记录编号 444089 评测结果 AAAAAAAAAA
题目名称 凯伦和咖啡 最终得分 100
用户昵称 GravatarHeHe 是否通过 通过
代码语言 C++ 运行时间 0.132 s
提交时间 2017-09-02 06:40:06 内存使用 3.85 MiB
显示代码纯文本
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

inline char getc(void) { 
    static char buf[1 << 18], *fs, *ft;
    return (fs == ft && (ft = (fs = buf) + fread(buf, 1, 1 << 18, stdin)), fs == ft) ? EOF : *fs++;
}

inline int read(void) { 
    register int res = 0;
    register char tmp = getc();
    while(!isdigit(tmp)) tmp = getc();
    while(isdigit(tmp))
        res = ((res + (res << 2)) << 1) + (tmp ^ 0x30),
        tmp = getc();
    return res;
}

char ops[1 << 20], *opt = ops, *const opt_end = ops + (1 << 20);

inline void write_all(void) { 
    fwrite(ops, 1, opt - ops, stdout);
    opt = ops; return ;
}

inline void write(int x) { 
    static char *p = new char[20]();
    do{ 
        *(++p) = (x % 10) | 0x30;
        x /= 10;
    }while(x);
    while(*p) { 
        *(opt++) = *(p--);
        if(opt == opt_end) write_all();
    }
    *(opt++) = '\n';
    if(opt == opt_end) write_all();
    return ;
}

#define MAXN (200010)

int N, K, Q, mx;
int c[MAXN];
int ql[MAXN], qr[MAXN];

int main() { 
#ifndef LOCAL
    freopen("coffee.in", "r", stdin);
    freopen("coffee.out", "w", stdout);
#endif
    N = read(), K = read(), Q = read();
    for(int i = 1, l, r; i <= N; ++i) 
        l = read(), r = read(), 
        ++c[l], --c[r + 1];
    for(int i = 1; i <= Q; ++i) 
        ql[i] = read(),
        mx = max(mx, qr[i] = read());
    for(int i = 1; i <= mx; ++i) 
        c[i] += c[i - 1];
    for(int i = 1; i <= mx; ++i) 
        if(c[i] >= K) c[i] = c[i - 1] + 1;
        else c[i] = c[i - 1];
    for(int i = 1; i <= Q; ++i) 
        write(c[qr[i]] - c[ql[i] - 1]);
    write_all();
    return 0;
}