QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#865119#9986. ShioriyhdddRE 41ms8012kbC++203.4kb2025-01-21 15:06:232025-01-21 15:06:24

Judging History

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

  • [2025-01-21 15:06:24]
  • 评测
  • 测评结果:RE
  • 用时:41ms
  • 内存:8012kb
  • [2025-01-21 15:06:23]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define mod 998244353ll
#define pii pair<int,int>
#define fi first
#define se second
#define mems(x,y) memset(x,y,sizeof(x))
#define pb push_back
#define db double
using namespace std;
const int maxn=200010;
const int inf=1e18;
inline int read(){
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=(x<<3)+(x<<1)+(ch-48);ch=getchar();}
	return x*f;
}
bool Mbe;

int n,q,a[maxn];
const int B=500;
int pl[1010],pr[1010],num,id[maxn];
bitset<maxn> vis[1010];
int tag[1010],cov[1010],sum[1010];
void del(int i){
	int l=pl[i],r=pr[i];
	for(int j=l;j<=r;j++)if(a[j]<=n)vis[i].reset(a[j]);
}
void add(int i){
	int l=pl[i],r=pr[i];
	for(int j=l;j<=r;j++)if(a[j]<=n)vis[i].set(a[j]);
	sum[i]=0;for(int j=l;j<=r;j++)sum[i]+=a[j];
}
void down(int i){
	if(cov[i]==-1&&!tag[i])return ;
	int l=pl[i],r=pr[i];
	del(i);
	if(~cov[i]){
		for(int j=l;j<=r;j++)a[j]=cov[i];
		cov[i]=-1;
	}
	if(tag[i]){
		for(int j=l;j<=r;j++)a[j]+=tag[i];
		tag[i]=0;
	}
	add(i);
}
int val(int i){
	if(~cov[id[i]])return cov[id[i]]+tag[id[i]];
	return a[i]+tag[id[i]];
}
bool find(int i,int v){
	if(~cov[i])return cov[i]+tag[i]==v;
	v-=tag[i];
	if(v<0||v>n)return 0;
	return vis[i].test(v);
}
bool find(int l,int r,int v){
	if(id[l]==id[r]){
		for(int i=l;i<=r;i++){
			if(val(i)==v)return 1;
		}
		return 0;
	}
	for(int i=l;i<=pr[id[l]];i++){
		if(val(i)==v)return 1;
	}
	for(int i=pl[id[r]];i<=r;i++){
		if(val(i)==v)return 1;
	}
	for(int i=id[l]=1;i<id[r];i++){
		if(find(i,v))return 1;
	}
	return 0;
}
void work(){
	n=read();q=read();
	for(int i=1;i<=n;i++)a[i]=read();
	for(int l=1,r;l<=n;l=r+1){
		r=min(l+B-1,n);pl[++num]=l,pr[num]=r;
		for(int j=l;j<=r;j++)id[j]=num;
		tag[num]=0,cov[num]=-1;
		add(num);
	}
	while(q--){
		int op=read();
		if(op==1){
			int l=read(),r=read(),v=read();
			if(id[l]==id[r]){
				down(id[l]);del(id[l]);
				for(int i=l;i<=r;i++)a[i]=v;
				add(id[l]);
			}
			else{
				down(id[l]);del(id[l]);
				for(int i=l;i<=pr[id[l]];i++)a[i]=v;
				add(id[l]);
				down(id[r]);del(id[r]);
				for(int i=pl[id[i]];i<=r;i++)a[i]=v;
				add(id[r]);
				for(int i=id[l]+1;i<id[r];i++)tag[i]=0,cov[i]=v,sum[i]=0;
			}
		}
		if(op==2){
			int l=read(),r=read();
			int mex=0;
			while(find(l,r,mex))mex++;
			if(id[l]==id[r]){
				down(id[l]);del(id[l]);
				for(int i=l;i<=r;i++)a[i]+=mex;
				add(id[l]);
			}
			else{
				down(id[l]);del(id[l]);
				for(int i=l;i<=pr[id[l]];i++)a[i]+=mex;
				add(id[l]);
				down(id[r]);del(id[r]);
				for(int i=pl[id[i]];i<=r;i++)a[i]+=mex;
				add(id[r]);
				for(int i=id[l]+1;i<id[r];i++)tag[i]+=mex;
			}
		}
		if(op==3){
			int l=read(),r=read(),ans=0;
			if(id[l]==id[r]){
				down(id[l]);
				for(int i=l;i<=r;i++)ans+=a[i];
			}
			else{
				down(id[l]);
				for(int i=l;i<=pr[id[l]];i++)ans+=a[i];
				down(id[r]);
				for(int i=pl[id[i]];i<=r;i++)ans+=a[i];
				for(int i=id[l]+1;i<id[r];i++){
					if(~cov[i])ans+=(cov[i]+tag[i])*(pr[id[i]]-pl[id[i]]+1);
					else ans+=sum[i]+tag[i]*(pr[id[i]]-pl[id[i]]+1);
				}
			}
			printf("%lld\n",ans);
		}
	}
}

// \
444

bool Med;
int T;
signed main(){
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	
//	ios::sync_with_stdio(0);
//	cin.tie(0);cout.tie(0);
	
//	cerr<<(&Mbe-&Med)/1048576.0<<" MB\n";
	
	T=1;
	while(T--)work();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5 8
0 7 2 1 0
1 2 4 0
2 1 3
2 3 4
3 1 3
1 2 3 4
3 1 4
2 1 5
3 2 5

output:

5
11
22

result:

ok 3 number(s): "5 11 22"

Test #2:

score: 0
Accepted
time: 0ms
memory: 5708kb

input:

1 1
0
1 1 1 0

output:


result:

ok 0 number(s): ""

Test #3:

score: 0
Accepted
time: 41ms
memory: 8012kb

input:

10 500000
0 0 0 0 0 0 0 0 0 0
3 2 9
2 4 10
2 2 7
2 7 9
3 1 1
3 5 8
1 5 10 0
3 1 9
3 5 9
2 2 4
1 2 4 0
2 5 6
3 8 8
1 4 6 0
1 6 6 0
2 4 10
3 1 9
3 5 7
1 4 10 0
3 6 9
3 2 6
2 1 8
1 5 9 0
3 7 8
3 4 8
2 4 8
2 5 8
2 1 9
2 3 8
1 5 10 0
2 4 8
3 1 6
2 1 4
2 3 7
3 4 10
1 4 6 0
1 1 6 0
2 3 7
1 1 1 0
2 1 10
1 5...

output:

0
0
10
7
0
0
6
3
0
0
0
1
25
12
10
0
0
0
0
17
23
1
20
2
11
27
26
2
18
2
2
0
0
0
2
4
1
0
0
0
7
2
0
4
32
15
7
11
0
4
5
2
8
5
1
6
0
7
0
7
6
3
2
5
0
0
0
7
14
2
5
0
2
0
0
6
12
6
0
2
3
0
0
1
16
12
1
1
12
0
3
4
4
10
3
16
0
17
2
4
0
0
16
8
2
8
18
23
2
24
4
12
7
4
14
5
0
2
8
4
16
10
6
4
21
15
1
3
3
0
2
5
0
2
...

result:

ok 166844 numbers

Test #4:

score: 0
Accepted
time: 41ms
memory: 8008kb

input:

10 500000
0 0 0 0 0 0 0 0 0 0
2 9 10
1 1 3 0
1 1 2 0
2 2 4
3 8 8
2 6 6
2 5 6
3 2 9
2 4 4
1 2 6 0
2 5 7
1 2 10 0
3 1 4
3 1 10
1 6 7 0
1 1 1 0
1 3 9 0
3 4 7
3 2 8
1 6 9 0
1 3 5 0
1 5 10 0
3 2 5
1 2 9 0
1 7 8 0
2 5 10
3 2 3
2 5 5
2 8 9
3 1 6
2 2 6
2 3 6
3 4 5
1 1 6 0
1 1 5 0
3 3 8
3 2 9
3 3 7
1 2 10 0
...

output:

0
9
0
0
0
0
0
0
2
5
2
3
1
0
5
7
1
0
1
3
20
1
23
13
7
14
6
19
0
2
1
2
1
1
0
1
2
2
3
1
0
0
12
28
20
0
0
0
0
0
1
0
1
1
0
2
21
6
9
2
5
10
0
0
0
1
2
1
0
0
0
1
1
0
3
0
2
0
2
0
2
2
2
0
8
3
2
1
0
2
12
4
2
0
0
6
0
9
3
15
0
0
6
0
14
11
6
0
5
4
4
26
11
8
7
7
10
0
4
6
2
4
4
6
4
7
0
3
6
4
20
3
17
14
18
14
9
13
8...

result:

ok 166636 numbers

Test #5:

score: -100
Runtime Error

input:

500000 500000
472024 143520 268267 155743 162119 212911 326774 283734 445407 353394 432929 138490 36366 247037 157063 203731 162782 54322 321700 39379 6459 358816 32001 245189 167252 460348 113630 85323 283872 285182 191285 487821 395892 328168 467455 469639 234067 325083 145477 450046 16029 142429 ...

output:


result: