记录编号 557848 评测结果 AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
题目名称 [洛谷U14472]数据结构 最终得分 100
用户昵称 Gravatar锝镆氪锂铽 是否通过 通过
代码语言 C++ 运行时间 3.138 s
提交时间 2020-11-28 22:34:43 内存使用 3.15 MiB
显示代码纯文本
#include <iostream>
#include <cstdio>
#define LL long long
using namespace std;
const int maxN = 8e4 + 10;

void calc(LL l, LL r);

LL b[maxN], anss[maxN];
LL n, opt, mmod, mmin, mmax, ans, now, F;
int main(void){
	freopen("shuju.in", "r", stdin);
	freopen("shuju.out", "w", stdout);
	scanf("%lld%lld%lld%lld%lld", &n, &opt, &mmod, &mmin, &mmax);
	for (int i = 1; i <= opt; i ++){ 
		char optt[2];
		scanf("%s", optt);
		if (optt[0] == 'A'){
			LL L, R, XX;
			scanf("%lld%lld%lld", &L, &R, &XX);
			b[L] += XX;
			b[R + 1] -= XX;
		} 
		else if (optt[0] == 'Q'){
			LL L, R;
			ans = 0;
			scanf("%lld%lld", &L, &R);
			calc(L, R);
		}
	}
	scanf("%lld", &F);
	now = 0;
	for (int i = 1; i <= n; i ++){ 
		now += b[i];
		anss[i] = ((now * i) % mmod <= mmax && (now * i) % mmod >= mmin) ? 1 : 0;//维护满足条件数的前缀和
		anss[i] += anss[i-1];
	}
	while (F --){ 
		LL l, r;
		scanf("%lld%lld", &l, &r);
		printf("%lld\n", anss[r] - anss[l - 1]);
	} 
	return 0;
}


void calc(LL l, LL r){
	now = ans = 0;
	for (LL i = 1; i <= r; i ++){
		now += b[i];
		if (i >= l && (now * i) % mmod >= mmin && (now * i) % mmod <= mmax)
			ans++;
	}
	printf("%lld\n", ans);
}