Codeforces Round #419 (Div. 2)Karen and Coffee

来源:互联网 发布:软横跨计算软件 编辑:程序博客网 时间:2024/06/04 23:32


#include <iostream>#include <stdio.h>#include <string.h>#include <algorithm>#include <queue>#include <vector>#include <stack>typedef long long LL;using namespace std;const int MAX = 200000+10;const int INF = 11234567;void Read(int &x) {    char c;    while(c=getchar(),c!=EOF)        if(c>='0'&&c<='9') {            x=c-'0';            while(c=getchar(),c>='0'&&c<='9')                x=x*10+c-'0';            ungetc(c,stdin);            return;        }}int n, k, q, l, r, p[MAX], pp[MAX];int main() {    scanf("%d%d%d", &n, &k, &q);    for(int i = 0; i<n; ++i){        scanf("%d%d", &l, &r);        p[l]++;        p[r+1]--;    }    pp[0] =0 ;    int kk = 0;    for(int i = 1; i<=200000; ++i){        kk+=p[i];        if(kk>=k)pp[i] = pp[i-1]+1;        else pp[i] = pp[i-1];    }    for(int i = 0; i<q; ++i){        scanf("%d%d", &l, &r);        printf("%d\n", pp[r]-pp[l-1]);    }    return 0;}


阅读全文
0 0