比赛 树立信心的模拟赛 评测结果 AAAAAAAAAA
题目名称 凯伦和咖啡 最终得分 100
用户昵称 AAAAAAAAAA 运行时间 0.074 s
代码语言 C++ 内存使用 2.61 MiB
提交时间 2017-09-01 20:14:36
显示代码纯文本
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<ctime>
#define MAXN 200010
namespace IO {
	char buf[1 << 15], *fs, *ft;
	inline char gc() { return (fs == ft && (ft = (fs = buf) + fread(buf, 1, 1 << 15, stdin), fs == ft)) ? 0 : *fs++; }
	inline int qr() {
		int x = 0, ch = gc();
		while (ch<'0' || ch>'9') { ch = gc(); }
		while (ch >= '0'&&ch <= '9') { x = (x << 1) + (x << 3) + ch - '0'; ch = gc(); }
		return x;
	}
}using namespace IO;
using namespace std;
/***********************************************************************************************/
int N, K, Q, c[MAXN], l, r, a[MAXN], b[MAXN];
int main() {
	freopen("coffee.in", "r", stdin);
	freopen("coffee.out", "w", stdout);
	//srand(time(NULL));
	N = qr(); K = qr(); Q = qr();
	//N = rand() % MAXN;K = 2;Q = rand()%MAXN;
	//printf("%d %d %d\n", N, K, Q);
	int max1 = 0;
	for (int i = 1; i <= N; i++) {
		l = qr(); r = qr();
		//l = rand() % MAXN;r =l+rand() % (MAXN - l);
		//printf("%d %d\n", l, r);
		c[l]++; c[r + 1]--;
	}
	for (int i = 1; i <= Q; i++) {
		a[i] = qr(); b[i] = qr();
		//a[i] = rand() % MAXN;b[i] = a[i] + rand() % (MAXN - a[i]);
		//printf("%d %d\n", a[i], b[i]);
		max1 = max(max1, b[i]);
	}
	for (int i = 1; i <= max1; i++) {
		c[i] = c[i] + c[i - 1];
	}
	for (int i = 1; i <= max1; i++) {
		if (c[i] >= K)c[i] = 1;
		else c[i] = 0;
		c[i] = c[i] + c[i - 1];
	}
	//freopen("coffee10.out", "w", stdout);
	for (int i = 1; i <= Q; i++) {
		printf("%d\n", c[b[i]] - c[a[i] - 1]);
	}
	return 0;
}