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 Rust (1.15.1) (judge verdict: Accepted)

#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::Read;
#[allow(dead_code)]
fn getline() -> String {
    let mut ret = String::new();
    std::io::stdin().read_line(&mut ret).ok().unwrap();
    ret
}
fn get_word() -> String {
    let mut stdin = std::io::stdin();
    let mut u8b: [u8; 1] = [0];
    loop {
        let mut buf: Vec<u8> = Vec::with_capacity(16);
        loop {
            let res = stdin.read(&mut u8b);
            if res.unwrap_or(0) == 0 || u8b[0] <= b' ' {
                break;
            } else {
                buf.push(u8b[0]);
            }
        }
        if buf.len() >= 1 {
            let ret = String::from_utf8(buf).unwrap();
            return ret;
        }
    }
}

#[allow(dead_code)]
fn get<T: std::str::FromStr>() -> T { get_word().parse().ok().unwrap() }
/// References: http://noshi91.hatenablog.com/entry/2018/06/19/192741
///             https://github.com/noshi91/NoshiMochiLibrary/blob/master/WaveletMatrix/WaveletMatrix.noshi.cpp
/// Fine-tuned for machines whose machine word is 64-bit.
/// Not on Codeforces.
/// Verified: at_least, range_freq (by https://beta.atcoder.jp/contests/bitflyer2018-final/submissions/2972019)
type Word = u64;
struct BitVector {
    vec: Vec<Word>,
    dict: Vec<u32>,
}

impl BitVector {
    fn divide_digits(index: usize) -> (usize, usize) {
        (index >> 6, index & 0x3f)
    }
    pub fn build(a: &[bool]) -> Self {
        let n = a.len();
        let size = (n + 63) >> 6;
        let mut vec = vec![0; size];
        for i in 0 .. n {
            let (block, bit) = BitVector::divide_digits(i);
            if a[i] {
                vec[block] |= 1 << bit;
            }
        }
        let dict = BitVector::make_dict(&vec);
        BitVector {
            vec: vec,
            dict: dict,
        }
    }
    fn make_dict(a: &[Word]) -> Vec<u32> {
        let size = a.len();
        let mut dict = vec![0; size + 1];
        for i in 0 .. size {
            dict[i + 1] = dict[i] + a[i].count_ones();
        }
        dict
    }
    pub fn len(&self) -> u32 {
        self.vec.len() as u32 * 8
    }
    pub fn rank(&self, last: usize) -> u32 {
        let (block, bits) = BitVector::divide_digits(last);
        self.dict[block] + if bits == 0 { 0 } else { (self.vec[block] & ((1 << bits) - 1)).count_ones() }
    }
    pub fn access(&self, x: usize) -> bool {
        let (block, bit) = BitVector::divide_digits(x);
        (self.vec[block] >> bit & 1) != 0
    }
}

const BITS: usize = 64;
type ValueType = u64;
struct WaveletMatrix {
    len: usize,
    matrix: [BitVector; BITS],
    cnt: [u32; BITS],
}

impl WaveletMatrix {
    fn assert_valid_range(&self, first: usize, last: usize) {
        assert!(first <= self.len);
        assert!(last <= self.len);
        assert!(first <= last);
    }
    pub fn new(a: &[ValueType]) -> Self {
        let n = a.len();
        let mut matrix: [BitVector; BITS];
        let mut vec0 = a.to_vec();
        let mut bit_vec = vec![false; n];
        let mut tmp = 1 << (BITS - 1);
        let mut vec_l = vec![0; n].into_boxed_slice();
        let mut vec_r = vec![0; n].into_boxed_slice();
        let mut cnt = [0; BITS];
        unsafe {
            matrix = std::mem::uninitialized();
            for (i, elem) in matrix.iter_mut().enumerate() {
                let cur = tmp;
                tmp >>= 1;
                let mut l = 0;
                let mut r = 0;
                for j in 0 .. n {
                    if (vec0[j] & cur) != 0 {
                        vec_r[r] = vec0[j];
                        r += 1;
                        bit_vec[j] = true;
                    } else {
                        vec_l[l] = vec0[j];
                        l += 1;
                        bit_vec[j] = false;
                    }
                }
                let bv = BitVector::build(&bit_vec);
                std::ptr::write(elem, bv);
                vec0[..l].copy_from_slice(&vec_l[..l]);
                vec0[l..].copy_from_slice(&vec_r[..r]);
                cnt[i] = l as u32;
            }
        }
        WaveletMatrix { len: n, matrix: matrix, cnt: cnt }
    }
    #[allow(unused)]
    pub fn len(&self) -> usize { self.len }
    #[allow(unused)]
    pub fn access(&self, mut index: usize) -> ValueType {
        assert!(index < self.len);
        let mut ret = 0;
        let mut tmp = 1 << (BITS - 1);
        for (i, v) in self.matrix.iter().enumerate() {
            if v.access(index) {
                ret |= tmp;
                index = (v.rank(index) + self.cnt[i]) as usize;
            } else {
                index -= v.rank(index) as usize;
            }
            tmp >>= 1;
        }
        ret
    }
    #[allow(unused)]
    pub fn rank(&self, mut first: usize, mut last: usize, x: ValueType)
                -> usize {
        self.assert_valid_range(first, last);
        let mut tmp = 1 << (BITS - 1);
        for (i, v) in self.matrix.iter().enumerate() {
            let l = v.rank(first) as usize;
            let r = v.rank(last) as usize;
            if (x & tmp) != 0 {
                first = l + self.cnt[i] as usize;
                last = r + self.cnt[i] as usize;
            } else {
                first -= l;
                last -= r;
            }
            tmp >>= 1;
        }
        last - first
    }
    #[allow(unused)]
    pub fn quantile(&self, mut first: usize, mut last: usize, mut k: usize)
                    -> ValueType {
        assert!(first < self.len);
        assert!(last <= self.len);
        assert!(first < last);
        assert!(last - first > k);
        let mut ret = 0;
        let mut tmp = 1 << (BITS - 1);
        for (i, v) in self.matrix.iter().enumerate() {
            let l = v.rank(first) as usize;
            let r = v.rank(last) as usize;
            if r - l > k {
                first = l + self.cnt[i] as usize;
                last = r + self.cnt[i] as usize;
                ret |= tmp;
            } else {
                first -= l;
                last -= r;
                k -= r - l;
            }
            tmp >>= 1;
        }
        ret
    }
    pub fn at_least(&self, mut first: usize, mut last: usize, x: ValueType)
                    -> usize {
        self.assert_valid_range(first, last);
        let mut ret = 0;
        let mut tmp = 1 << (BITS - 1);
        for (i, v) in self.matrix.iter().enumerate() {
            let l = v.rank(first) as usize;
            let r = v.rank(last) as usize;
            if (x & tmp) != 0 {
                first = l + self.cnt[i] as usize;
                last = r + self.cnt[i] as usize;
            } else {
                ret += r - l;
                first -= l;
                last -= r;
            }
            tmp >>= 1;
        }
        ret + (last - first)
    }
    #[allow(unused)]
    pub fn range_freq(&self, first: usize, last: usize, x: ValueType, y: ValueType)
                      -> usize {
        self.at_least(first, last, x) - self.at_least(first, last, y)
    }
        
}

const MOCK: bool = false;

fn solve() {
    let n: usize = get();
    let m = get();
    let q = get();
    let mut lr = Vec::new();
    for i in 0 .. m {
        let l: u64;
        let r: u64;
        if MOCK {
            l = i as u64 + 1;
            r = 2 * i as u64 + 1;
        } else {
            l = get();
            r = get();
        }
        lr.push((2 * l, 2 * r));
    }
    lr.sort();
    let mut values = vec![0; m];
    let mut indices = vec![0; m];
    for i in 0 .. m { values[i] = lr[i].1; indices[i] = lr[i].0; }
    let wm = WaveletMatrix::new(&values);
    for i in 0 .. q {
        let p: u64;
        let q: u64;
        if MOCK {
            p = i as u64 + 1;
            q = 2 * i as u64 + 1;
        } else {
            p = get();
            q = get();
        }
        let p = 2 * p - 1;
        let q = 2 * q + 1;
        println!("{}", wm.range_freq(indices.binary_search(&p).err().unwrap(), m, p, q));
    }
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}