QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#865285#9774. Same SumxielirenWA 247ms63584kbC++143.3kb2025-01-21 16:29:152025-01-21 16:29:20

Judging History

你现在查看的是最新测评结果

  • [2025-01-21 16:29:20]
  • 评测
  • 测评结果:WA
  • 用时:247ms
  • 内存:63584kb
  • [2025-01-21 16:29:15]
  • 提交

answer

#include<bits/stdc++.h>
#define left rt * 2
#define right rt * 2 + 1
#define int long long
using namespace std;
int read(){
	int s = 0, f = 1;char ch = getchar();
	while(!isdigit(ch)){if(ch == '-')f = -1;ch = getchar();}
	while(isdigit(ch)){s = s * 10 + ch - '0';ch = getchar();}
	return s * f;
}
void write(int x){
    if(x < 0){putchar('-'); x = -x;}
    if(x > 9) write(x / 10);
    putchar(x % 10 + '0');
}
const int MAXN = 2e5 + 5, MR = 8e5 + 5, MOD = 911451407, E = 1907, INF = 1e18;
int n, q, a[MAXN], pw[MAXN], pw2[MAXN];
int fpow(int a, int b){
	int res = 1;
	while(b){if(b & 1ll)res = res * a % MOD;a = a * a % MOD;b >>= 1ll;}
	return res;
}
struct node{
	int a, b, c, d;
};
struct Segment_tree{
	int lf[MR], rf[MR], num[MR], num2[MR], lazy[MR], lazy2[MR], lazy3[MR], maxx[MR], minn[MR];
	void push_up(int rt){
		num[rt] = (num[left] + num[right]) % MOD;
		num2[rt] = (num2[left] + num2[right]) % MOD;
		minn[rt] = min(minn[left], minn[right]);
		maxx[rt] = max(maxx[left], maxx[right]);
	}
	void build(int rt, int l, int r){
		lf[rt] = l, rf[rt] = r, lazy2[rt] = lazy3[rt] = 1;
		if(l == r){
			minn[rt] = maxx[rt] = a[l];
			num[rt] = pw[a[l]];
			num2[rt] = pw2[a[l]];
			return ;
		}
		int mid = l + r >> 1ll;
		build(left, l, mid);
		build(right, mid + 1, r);
		push_up(rt);
	}
	void push_down(int rt){
		if(!lazy[rt])return ;
		int k = lazy[rt];
		minn[left] += k, minn[right] += k;
		maxx[left] += k, maxx[right] += k;
		num[left] = num[left] * lazy2[rt] % MOD;
		num[right] = num[right] * lazy2[rt] % MOD;
		num2[left] = num2[left] * lazy3[rt] % MOD;
		num2[right] = num2[right] * lazy3[rt] % MOD;
		lazy[left] += k, lazy[right] += k;
		lazy2[left] = lazy2[rt] * lazy2[left] % MOD;
		lazy2[right] = lazy2[rt] * lazy2[right] % MOD;
		lazy3[left] = lazy3[rt] * lazy3[left] % MOD;
		lazy3[right] = lazy3[rt] * lazy3[right] % MOD;
		lazy[rt] = 0, lazy2[rt] = lazy3[rt] = 1;
	}
	void add_list(int rt, int l, int r, int x){
		if(lf[rt] > r || rf[rt] < l)return ;
		if(l <= lf[rt] && rf[rt] <= r){
			num[rt] = num[rt] * pw[x] % MOD;
			num2[rt] = num2[rt] * pw2[x] % MOD;
			minn[rt] += x, maxx[rt] += x, lazy[rt] += x;
			lazy2[rt] = lazy2[rt] * pw[x] % MOD;
			lazy3[rt] = lazy3[rt] * pw2[x] % MOD;
			return ;
		}
		push_down(rt);
		add_list(left, l, r, x);
		add_list(right, l, r, x);
		push_up(rt);
	}
	node query(int rt, int l, int r){
		if(lf[rt] > r || rf[rt] < l)return {0, 0, INF, -INF};
		if(l <= lf[rt] && rf[rt] <= r)
			return {num[rt], num2[rt], minn[rt], maxx[rt]};
		push_down(rt);
		node lp = query(left, l, r), rp = query(right, l, r);
		node res = {0, 0, INF, -INF};
		res.a = (lp.a + rp.a) % MOD, res.b = (lp.b + rp.b) % MOD;
		res.c = min(lp.c, rp.c), res.d = max(lp.d, rp.d);
		return res;
	}
}tr;
signed main(){
	n = read(), q = read();
	pw[0] = pw2[0] = 1, pw[1] = E, pw2[1] = fpow(E, MOD - 2);
	for(int i = 2;i < MAXN;i ++)
		pw[i] = pw[i - 1] * pw[1] % MOD, pw2[i] = pw2[i - 1] * pw2[1] % MOD;
	for(int i = 1;i <= n;i ++)a[i] = read();
	tr.build(1, 1, n);
	while(q --){
		int opt = read(), l = read(), r = read();
		if(opt == 1){
			int x = read();
			tr.add_list(1, l, r, x);
		}
		else{
			node tmp = tr.query(1, l, r);
			int h = fpow(E, (tmp.c + tmp.d) % MOD) * tmp.b % MOD;
			if(h == tmp.a)puts("YES");
			else puts("NO");
		}
	}
	return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 22088kb

input:

8 4
1 2 3 4 5 6 7 8
2 1 8
1 1 4 4
2 1 6
2 1 8

output:

YES
NO
YES

result:

ok 3 token(s): yes count is 2, no count is 1

Test #2:

score: 0
Accepted
time: 218ms
memory: 63584kb

input:

200000 200000
0 0 0 1 1 0 2 1 1 2 0 1 0 0 0 2 1 0 1 2 2 1 2 1 2 0 0 2 1 2 1 0 0 2 0 2 1 1 1 2 0 0 0 0 2 0 1 0 0 2 2 1 1 0 0 2 1 0 2 0 2 1 2 1 0 1 2 1 0 1 2 1 2 1 0 1 2 0 1 0 1 1 0 2 1 2 0 2 2 1 1 2 1 2 2 0 0 1 2 0 0 2 2 0 1 2 2 0 0 1 2 1 2 0 2 0 0 2 0 2 1 0 1 1 1 1 2 1 2 0 1 2 1 0 2 1 0 1 1 2 2 0 1 ...

output:

NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
...

result:

ok 100047 token(s): yes count is 22, no count is 100025

Test #3:

score: 0
Accepted
time: 213ms
memory: 62148kb

input:

200000 200000
5 5 2 0 1 1 4 1 1 0 4 2 2 5 5 4 1 2 2 0 3 3 3 2 5 4 1 5 1 0 0 4 3 4 2 2 3 1 4 2 0 5 4 0 2 5 5 5 2 2 3 4 0 2 2 5 0 2 3 5 4 0 0 2 1 0 5 3 1 4 5 2 2 3 4 5 0 5 5 5 3 3 0 1 4 3 0 0 3 2 2 0 4 5 5 5 2 4 5 2 5 3 1 1 5 2 1 0 1 0 5 0 0 1 5 1 5 3 1 5 3 5 4 0 2 2 4 2 5 2 3 4 5 4 3 5 2 5 2 4 5 3 4 ...

output:

NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
...

result:

ok 99734 token(s): yes count is 10, no count is 99724

Test #4:

score: -100
Wrong Answer
time: 247ms
memory: 63480kb

input:

200000 200000
185447 70128 80288 38126 188018 126450 46081 189881 15377 21028 12588 100061 7218 74518 162803 34448 90998 44793 167718 16370 136024 153269 186316 137564 3082 169700 175712 19214 82647 72919 170919 142138 57755 168197 81575 126456 183138 106882 167154 184388 198667 190302 188371 183732...

output:

NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
...

result:

wrong answer expected YES, found NO [51577th token]