QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#824462#9774. Same Sumucup-team3161#TL 462ms92116kbC++173.5kb2024-12-21 14:17:012024-12-21 14:17:02

Judging History

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

  • [2025-01-11 11:59:18]
  • hack成功,自动添加数据
  • (/hack/1443)
  • [2024-12-23 17:02:06]
  • hack成功,自动添加数据
  • (/hack/1310)
  • [2024-12-23 16:48:26]
  • hack成功,自动添加数据
  • (/hack/1309)
  • [2024-12-23 16:33:45]
  • hack成功,自动添加数据
  • (/hack/1308)
  • [2024-12-23 16:23:53]
  • hack成功,自动添加数据
  • (/hack/1307)
  • [2024-12-23 16:13:08]
  • hack成功,自动添加数据
  • (/hack/1306)
  • [2024-12-23 15:54:42]
  • hack成功,自动添加数据
  • (/hack/1305)
  • [2024-12-23 14:58:39]
  • hack成功,自动添加数据
  • (/hack/1304)
  • [2024-12-23 09:58:11]
  • hack成功,自动添加数据
  • (/hack/1302)
  • [2024-12-23 09:47:22]
  • hack成功,自动添加数据
  • (/hack/1301)
  • [2024-12-23 09:41:23]
  • hack成功,自动添加数据
  • (/hack/1300)
  • [2024-12-23 09:26:32]
  • hack成功,自动添加数据
  • (/hack/1299)
  • [2024-12-23 09:19:58]
  • hack成功,自动添加数据
  • (/hack/1298)
  • [2024-12-23 09:13:29]
  • hack成功,自动添加数据
  • (/hack/1297)
  • [2024-12-22 18:52:18]
  • hack成功,自动添加数据
  • (/hack/1296)
  • [2024-12-22 18:13:14]
  • hack成功,自动添加数据
  • (/hack/1294)
  • [2024-12-21 14:17:02]
  • 评测
  • 测评结果:TL
  • 用时:462ms
  • 内存:92116kb
  • [2024-12-21 14:17:01]
  • 提交

answer

#include<bits/stdc++.h>
#define For(i,x,y) for (int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (int i=(x);i<(y);i++)
#define Dow(i,x,y) for (int i=(x);i>=(y);i--)
#define mp make_pair
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PA;

inline ll read(){
    ll x;
    scanf("%lld",&x);
    return x;
}

const int N = 2e5+10;
int n,q,a[N];

const int base = 2333;
inline int Mod(int x,int mod){
	return x>=mod?x-mod:x;
}
inline int power(int a,ll b,int mod){
	b%=mod-1;
	int ret=1;
	for (;b;b>>=1,a=1ll*a*a%mod) if (b&1) ret=1ll*ret*a%mod;
	return ret;
}

struct SGT{
    int mod,invb;
	ll mx[N<<2],mn[N<<2],tag[N<<2],tag1[N<<2],tag2[N<<2],s1[N<<2],s2[N<<2];
	inline void init(int _mod){
		mod=_mod;
		invb=power(base,mod-2,mod);
	}
	inline void push_up(int u){
		mx[u]=max(mx[u<<1],mx[u<<1^1]);
		mn[u]=min(mn[u<<1],mn[u<<1^1]);
		s1[u]=Mod(s1[u<<1]+s1[u<<1^1],mod);
		s2[u]=Mod(s2[u<<1]+s2[u<<1^1],mod);
	}
    inline void Build(int u,int l,int r){
		tag1[u]=1;
		tag2[u]=1;
		tag[u]=0;
        if (l==r){
			mx[u]=mn[u]=a[l];
			s1[u]=power(base,a[l],mod);
			s2[u]=power(invb,a[l],mod);
            return;
        }
        int mid=l+r>>1;
        Build(u<<1,l,mid);
        Build(u<<1^1,mid+1,r);
        push_up(u);
    }
	inline void upd(int u,int x,int y,int z){
		tag[u]+=x;
		tag1[u]=1ll*tag1[u]*y%mod;
		tag2[u]=1ll*tag2[u]*z%mod;
		mn[u]+=x;
		mx[u]+=x;
		s1[u]=1ll*s1[u]*y%mod;
		s2[u]=1ll*s2[u]*z%mod;
	}
	inline void push_down(int u){
		if (!tag[u]) return;
		upd(u<<1,tag[u],tag1[u],tag2[u]);
		upd(u<<1^1,tag[u],tag1[u],tag2[u]);
		tag[u]=0;
		tag1[u]=1;
		tag2[u]=1;
	}
	inline void update(int u,int l,int r,int ql,int qr,int x,int pw1,int pw2){
		if (l>=ql&&r<=qr){
			upd(u,x,pw1,pw2);
			return;
		}
		int mid=l+r>>1;
		push_down(u);
		if (ql<=mid) update(u<<1,l,mid,ql,qr,x,pw1,pw2);
		if (qr>mid) update(u<<1^1,mid+1,r,ql,qr,x,pw1,pw2);
		push_up(u);
	}
	inline void update(int l,int r,int x){
		update(1,1,n,l,r,x,power(base,x,mod),power(invb,x,mod));
	}
	inline PA Query1(int u,int l,int r,int ql,int qr){
		if (l>=ql&&r<=qr) return mp(mn[u],mx[u]);
		int mid=l+r>>1;
		push_down(u);
		if (qr<=mid) return Query1(u<<1,l,mid,ql,qr);
		if (ql>mid) return Query1(u<<1^1,mid+1,r,ql,qr);
		auto L=Query1(u<<1,l,mid,ql,qr),R=Query1(u<<1^1,mid+1,r,ql,qr);
		return mp(min(L.fi,R.fi),max(L.se,R.se));
	}
	inline PA Query2(int u,int l,int r,int ql,int qr){
		if (l>=ql&&r<=qr) return mp(s1[u],s2[u]);
		int mid=l+r>>1;
		push_down(u);
		if (qr<=mid) return Query2(u<<1,l,mid,ql,qr);
		if (ql>mid) return Query2(u<<1^1,mid+1,r,ql,qr);
		auto L=Query2(u<<1,l,mid,ql,qr),R=Query2(u<<1^1,mid+1,r,ql,qr);
		return mp(Mod(L.fi+R.fi,mod),Mod(L.se+R.se,mod));
	}
	inline bool check(int s1,int s2,int mn,int mx){
		s1=1ll*s1*power(invb,mn,mod)%mod;
		s2=1ll*s2*power(base,mx,mod)%mod;
		return s1==s2;
	}
}T1,T2;

int main(){
    n=read(),q=read();
    For(i,1,n) a[i]=read();
	T1.init(1e9+7);
	T2.init(1e9+9);
	T1.Build(1,1,n);
	T2.Build(1,1,n);
	while (q--){
		int op=read(),l=read(),r=read();
		if (op==1){
			int x=read();
			T1.update(l,r,x);
			T2.update(l,r,x);
		} else {
			auto [mn,mx]=T1.Query1(1,1,n,l,r);
			PA t=T1.Query2(1,1,n,l,r);
			if (!T1.check(t.fi,t.se,mn,mx)){
				puts("NO");
				continue;
			}
			
			t=T2.Query2(1,1,n,l,r);
			if (!T2.check(t.fi,t.se,mn,mx)){
				puts("NO");
				continue;
			}

			puts("YES");
		}
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 32296kb

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: 462ms
memory: 92116kb

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: 436ms
memory: 91980kb

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