QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#859754#9774. Same SumZZ_zuozheTL 384ms30968kbC++172.4kb2025-01-17 22:47:522025-01-17 22:47:52

Judging History

This is the latest submission verdict.

  • [2025-01-17 22:47:52]
  • Judged
  • Verdict: TL
  • Time: 384ms
  • Memory: 30968kb
  • [2025-01-17 22:47:52]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;
#define ll long long

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=ksm(bs);
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);
}
using arr=array<int,3>;
arr operator+(const arr &a,const arr &b){
	return {a[0]+b[0],(a[1]+b[1])%mod,(a[2]+b[2])%mod};
}
arr qry(int x,int l,int r,int nl,int nr){
	if(nl<=l&&r<=nr)return {sum0[x],sum1[x],sum2[x]};
	down(x,l,r);
	if(mi<nl)return qry(rson,nl,nr);
	if(mi>=nr)return qry(lson,nl,nr);
	return qry(lson,nl,nr)+qry(rson,nl,nr);
}

int main(){
	pw[0]=ipw[0]=1;
	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;
	cin>>n>>q;
	for(int i=1;i<=n;i++)cin>>a[i];
	build(1,1,n);
	for(int i=1;i<=q;i++){
		cin>>o;
		if(o==1){
			cin>>t1>>t2>>t3;
			upd(1,1,n,t1,t2,t3);
		}
		else{
			cin>>t1>>t2;
			auto [t,pos,neg]=qry(1,1,n,t1,t2);
			if(t%(t2-t1+1>>1)){
				puts("NO");
				continue;
			}
			t/=t2-t1+1>>1;
			if(1ll*neg*ksm(bs,t)%mod==pos)puts("YES");
			else puts("NO");
		}
	}
	return 0;
}

詳細信息

Test #1:

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

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: 381ms
memory: 30968kb

input:

200000 200000
0 0 0 1 1 0 2 1 1 2 0 1 0 0 0 2 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NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
NO
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
Time Limit Exceeded

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: