816B. Karen and Coffee by 李博浩 20000的数组而已

这道题我一点进来就觉得需要截图啊

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
using namespace std;

const int maxn = 2e5 + 5;
int cnt[maxn];
int sum[maxn];

int main()
{
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
    #endif // ONLINE_JUDGE
    int n, k, q;

    while (cin >> n >> k >> q) {
        int l, r;
        memset(cnt, 0, sizeof(cnt));
        for (int i = 0; i < n; i++) {
            scanf("%d%d", &l, &r);
            cnt[l]++;
            cnt[r+1]--;
        }
        memset(sum, 0, sizeof(sum));
        for (int i = 1; i <= 200000; i++) {
            cnt[i] += cnt[i-1];
            sum[i] = (cnt[i]>=k ? sum[i-1]+1: sum[i-1]);
        }
        int a, b;
        while (q--) {
            scanf("%d%d", &a, &b);
            printf("%d\n", sum[b]-sum[a-1]);
        }
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_43870649/article/details/88725365