QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#860566#9774. Same SumZZ_zuozheWA 234ms30944kbC++202.5kb2025-01-18 14:01:062025-01-18 14:02:47

Judging History

This is the latest submission verdict.

  • [2025-01-18 14:02:47]
  • Judged
  • Verdict: WA
  • Time: 234ms
  • Memory: 30944kb
  • [2025-01-18 14:01:06]
  • Submitted

answer

#include<bits/stdc++.h>
#define ll long long
int read(){
	int f=0,s=0; char c=getchar();
	while(c>'9'||c<'0')f=(c=='-'),c=getchar();
	while(c>='0'&&c<='9')s=(s<<3)+(s<<1)+(c^'0'),c=getchar();
	return f?-s:s;
}

const int N=200005;
int n,q;
int a[N];
int o,t1,t2,t3;

const int mod=998244353;
int ksm(int a,int b=mod-2){
	int res=1;
	for(;b;b>>=1,a=1ll*a*a%mod)if(b&1)res=1ll*res*a%mod;
	return res;
}
const int bs=20050913;
const int ibs=665516581;
inline void ad(int &a,int b){ a=a+b>=mod?a+b-mod:a+b; }
int pw[N],ipw[N];

#define ls x<<1
#define rs x<<1|1
#define mi ((l+r)>>1)
#define lson ls,l,mi
#define rson rs,mi+1,r
ll sum0[N<<2];
int sum1[N<<2],sum2[N<<2];
ll lz0[N<<2];
int lz1[N<<2],lz2[N<<2];
void up(int x){
	sum0[x]=sum0[ls]+sum0[rs];
	sum1[x]=(sum1[ls]+sum1[rs])%mod;
	sum2[x]=(sum2[ls]+sum2[rs])%mod;
}
void tag0(int x,int l,int r,int k){
	sum0[x]+=1ll*(r-l+1)*k;
	lz0[x]+=k;
}
void tag1(int x,int k1,int k2){
	sum1[x]=1ll*sum1[x]*k1%mod;
	sum2[x]=1ll*sum2[x]*k2%mod;
	lz1[x]=1ll*lz1[x]*k1%mod;
	lz2[x]=1ll*lz2[x]*k2%mod;
}
void down(int x,int l,int r){
	if(lz0[x]){
		tag0(ls,l,mi,lz0[x]);
		tag0(rs,mi+1,r,lz0[x]);
		lz0[x]=0;
	}
	if(lz1[x]!=1){
		tag1(ls,lz1[x],lz2[x]);
		tag1(rs,lz1[x],lz2[x]);
		lz1[x]=lz2[x]=1;
	}
}
void build(int x,int l,int r){
	lz0[x]=0; lz1[x]=lz2[x]=1;
	if(l==r){
		sum0[x]=a[l];
		sum1[x]=pw[a[l]];
		sum2[x]=ipw[a[l]];
		return;
	}
	build(lson); build(rson);
	up(x);
}
void upd(int x,int l,int r,int nl,int nr,int k){
	if(nl<=l&&r<=nr){
		tag0(x,l,r,k);
		tag1(x,pw[k],ipw[k]);
		return;
	}
	down(x,l,r);
	if(mi>=nl)upd(lson,nl,nr,k);
	if(mi<nr)upd(rson,nl,nr,k);
	up(x);
}
ll t;
int pos,neg;
void qry(int x,int l,int r,int nl,int nr){
	if(nl<=l&&r<=nr){
		t+=sum0[x];
		pos=(pos+sum1[x])%mod;
		neg=(neg+sum2[x])%mod;
		return;
	}
	down(x,l,r);
	if(mi>=nl)qry(lson,nl,nr);
	if(mi<nr)qry(rson,nl,nr);
}

int main(){
	pw[0]=ipw[0]=1;
	// cout<<ibs<<endl;
	for(int i=1;i<N;i++)pw[i]=1ll*pw[i-1]*bs%mod;
	for(int i=1;i<N;i++)ipw[i]=1ll*ipw[i-1]*ibs%mod;
	n=read(); q=read();
	for(int i=1;i<=n;i++)a[i]=read();
	build(1,1,n);
	for(int i=1;i<=q;i++){
		o=read();
		if(o==1){
			t1=read(); t2=read(); t3=read();
			upd(1,1,n,t1,t2,t3);
		}
		else{
			t1=read(); t2=read();
			t=pos=neg=0;
			qry(1,1,n,t1,t2);
			if(t%((t2-t1+1)/2)){
				puts("NO");
				continue;
			}
			t/=((t2-t1+1)/2);
			if(1ll*neg*ksm(bs,t%(mod-1))%mod==pos)puts("YES");
			else puts("NO");
		}
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 16204kb

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: 210ms
memory: 30944kb

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: 28952kb

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: 234ms
memory: 28776kb

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 [77964th token]