Problem:
Score: 400 points

Problem Statement

In Takahashi Kingdom, there is a east-west railroad and N cities along it, numbered 1, 2, 3, ..., N from west to east.
A company called AtCoder Express possesses M trains, and the train i runs from City L_i to City R_i (it is possible that L_i = R_i).
Takahashi the king is interested in the following Q matters:

The number of the trains that runs strictly within the section from City p_i to City q_i, that is, the number of trains j such that p_i \leq L_j and R_j \leq q_i.

Although he is genius, this is too much data to process by himself. Find the answer for each of these Q queries to help him.

Constraints

N is an integer between 1 and 500 (inclusive).

M is an integer between 1 and 200 \ 000 (inclusive).

Q is an integer between 1 and 100 \ 000 (inclusive).

1 \leq L_i \leq R_i \leq N (1 \leq i \leq M)

1 \leq p_i \leq q_i \leq N (1 \leq i \leq Q)

Input

Input is given from Standard Input in the following format:

N M Q
L_1 R_1
L_2 R_2
:
L_M R_M
p_1 q_1
p_2 q_2
:
p_Q q_Q

Output

Print Q lines. The i-th line should contain the number of the trains that runs strictly within the section from City p_i to City q_i.

Sample Input 1

2 3 1
1 1
1 2
2 2
1 2

Sample Output 1

3

As all the trains runs within the section from City 1 to City 2, the answer to the only query is 3.

Sample Input 2

10 3 2
1 5
2 8
7 10
1 7
3 10

Sample Output 2

1
1

The first query is on the section from City 1 to 7. There is only one train that runs strictly within that section: Train 1.
The second query is on the section from City 3 to 10. There is only one train that runs strictly within that section: Train 3.

Sample Input 3

10 10 10
1 6
2 9
4 5
4 7
4 7
5 8
6 6
6 7
7 9
10 10
1 8
1 9
1 10
2 8
2 9
2 10
3 8
3 9
3 10
1 10

Sample Output 3

7
9
10
6
8
9
6
7
8
10

Solution in C# (Mono 4.6.2.0) (judge verdict: Accepted)

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using static System.Math;
using System.Text;
using System.Threading;
using System.Globalization;
using System.Runtime.CompilerServices;
using Library;

namespace Program
{
    public static class ABC106D
    {
        static public int numberOfRandomCases = 0;
        static public void MakeTestCase(List<string> _input, List<string> _output, ref Func<string[], bool> _outputChecker)
        {
        }
        static public void Solve()
        {
            var N = NN;
            var M = NN;
            var Q = NN;
            var LRList = Repeat(0, M).Select(_ => new { L = NN - 1, R = NN - 1 }).ToArray();
            var pqList = Repeat(0, Q).Select(_ => new { p = NN - 1, q = NN - 1 }).ToArray();
            var seg2d = new LIB_SegTree2D<long>(N, N, 0, (x, y) => x + y);
            foreach (var item in LRList)
            {
                seg2d[item.L, item.R] += 1;
            }
            foreach (var item in pqList)
            {
                Console.WriteLine(seg2d.Query(item.p, item.q + 1, item.p, item.q + 1));
            }
        }
        static class Console_
        {
            static Queue<string> param = new Queue<string>();
            public static string NextString() { if (param.Count == 0) foreach (var item in Console.ReadLine().Split(' ')) param.Enqueue(item); return param.Dequeue(); }
        }
        class Printer : StreamWriter
        {
            public override IFormatProvider FormatProvider { get { return CultureInfo.InvariantCulture; } }
            public Printer(Stream stream) : base(stream, new UTF8Encoding(false, true)) { base.AutoFlush = false; }
            public Printer(Stream stream, Encoding encoding) : base(stream, encoding) { base.AutoFlush = false; }
        }
        static public void Main(string[] args) { if (args.Length == 0) { Console.SetOut(new Printer(Console.OpenStandardOutput())); } var t = new Thread(Solve, 134217728); t.Start(); t.Join(); Console.Out.Flush(); }
        static long NN => long.Parse(Console_.NextString());
        static double ND => double.Parse(Console_.NextString());
        static string NS => Console_.NextString();
        static long[] NNList(long N) => Repeat(0, N).Select(_ => NN).ToArray();
        static double[] NDList(long N) => Repeat(0, N).Select(_ => ND).ToArray();
        static string[] NSList(long N) => Repeat(0, N).Select(_ => NS).ToArray();
        static IEnumerable<T> OrderByRand<T>(this IEnumerable<T> x) => x.OrderBy(_ => xorshift);
        static long Count<T>(this IEnumerable<T> x, Func<T, bool> pred) => Enumerable.Count(x, pred);
        static IEnumerable<T> Repeat<T>(T v, long n) => Enumerable.Repeat<T>(v, (int)n);
        static IEnumerable<int> Range(long s, long c) => Enumerable.Range((int)s, (int)c);
        static IEnumerable<string> OrderBy(this IEnumerable<string> x) => x.OrderBy(e => e, StringComparer.OrdinalIgnoreCase);
        static IEnumerable<T> OrderBy<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderBy(selector, StringComparer.OrdinalIgnoreCase);
        static IEnumerable<string> OrderByDescending(this IEnumerable<string> x) => x.OrderByDescending(e => e, StringComparer.OrdinalIgnoreCase);
        static IEnumerable<T> OrderByDescending<T>(this IEnumerable<T> x, Func<T, string> selector) => x.OrderByDescending(selector, StringComparer.OrdinalIgnoreCase);
        static uint xorshift { get { _xsi.MoveNext(); return _xsi.Current; } }
        static IEnumerator<uint> _xsi = _xsc();
        static IEnumerator<uint> _xsc() { uint x = 123456789, y = 362436069, z = 521288629, w = (uint)(DateTime.Now.Ticks & 0xffffffff); while (true) { var t = x ^ (x << 11); x = y; y = z; z = w; w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)); yield return w; } }
    }
}
namespace Library {
    class LIB_SegTree2D<T>
    {
        int xsz;
        int ysz;
        T ti;
        Func<T, T, T> f;
        T[,] dat;
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public LIB_SegTree2D(long _xsz, long _ysz, T _ti, Func<T, T, T> _f)
        {
            xsz = 1; ysz = 1;
            while (xsz < _xsz) xsz <<= 1;
            while (ysz < _ysz) ysz <<= 1;
            ti = _ti;
            f = _f;
            dat = new T[xsz << 1, ysz << 1];
            for (var i = 0; i < xsz; ++i) for (var j = 0; j < ysz; ++j) dat[i, j] = ti;
            for (var j = 0; j < xsz; ++j) for (var i = ysz - 1; i > 0; i--) dat[j, i] = f(dat[j, (i << 1) | 0], dat[j, (i << 1) | 1]);
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public void Update(long x, long y, T v)
        {
            dat[x += xsz, y += ysz] = v;
            Action<long, long> up = (xp, yp) => { while ((yp >>= 1) > 0) dat[xp, yp] = f(dat[xp, (yp << 1) | 0], dat[xp, (yp << 1) | 1]); };
            up(x, y);
            while ((x >>= 1) > 0)
            {
                dat[x, y] = f(dat[(x << 1) | 0, y], dat[(x << 1) | 1, y]);
                up(x, y);
            }
        }
        [MethodImpl(MethodImplOptions.AggressiveInlining)]
        public T Query(long xl, long xr, long yl, long yr)
        {
            if (xl == xr || yl == yr) return ti;
            if (xr < xl || yr < yl) throw new Exception();
            var xvl = ti;
            var xvr = ti;
            for (long xli = xsz + xl, xri = xsz + xr; xli < xri; xli >>= 1, xri >>= 1)
            {
                if ((xli & 1) == 1)
                {
                    var yvl = ti;
                    var yvr = ti;
                    for (long yli = ysz + yl, yri = ysz + yr; yli < yri; yli >>= 1, yri >>= 1)
                    {
                        if ((yli & 1) == 1) yvl = f(yvl, dat[xli, yli++]);
                        if ((yri & 1) == 1) yvr = f(dat[xli, --yri], yvr);
                    }
                    xvl = f(xvl, f(yvl, yvr));
                    ++xli;
                }
                if ((xri & 1) == 1)
                {
                    --xri;
                    var yvl = ti;
                    var yvr = ti;
                    for (long yli = ysz + yl, yri = ysz + yr; yli < yri; yli >>= 1, yri >>= 1)
                    {
                        if ((yli & 1) == 1) yvl = f(yvl, dat[xri, yli++]);
                        if ((yri & 1) == 1) yvr = f(dat[xri, --yri], yvr);
                    }
                    xvr = f(f(yvl, yvr), xvr);
                }
            }
            return f(xvl, xvr);
        }
        public T this[long x, long y]
        {
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            get { return dat[x + xsz, y + ysz]; }
            [MethodImpl(MethodImplOptions.AggressiveInlining)]
            set { Update(x, y, value); }
        }
    }
}