QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#601732#5278. Mex and Cardshuaxiamengjin#WA 1ms11892kbC++141.3kb2024-09-30 11:41:302024-09-30 11:41:35

Judging History

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

  • [2024-09-30 11:41:35]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:11892kb
  • [2024-09-30 11:41:30]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define int long long 
int n,a[200100];
int mn[1001001],s[1001001],ls[1001001];
int ss[1001001],sss[1001001];
void build(int p,int l,int r,int pre){
	if(l==r)return mn[p]=min(pre,a[l]),ls[p]=mn[p],s[p]=0,void();
	int mid=l+r>>1;
	build(p<<1,l,mid,pre);build(p<<1|1,mid+1,r,min(mn[p<<1],pre));
	mn[p]=min(mn[p<<1],mn[p<<1|1]);
	ls[p]=ls[p<<1];
	s[p]=s[p<<1]+s[p<<1|1]+(mid+1)*(min(pre,mn[p<<1])-ls[p<<1|1]);
}
void push(int p,int l,int r,int x,int pre){
	if(l==r)return mn[p]=min(pre,a[l]),ls[p]=mn[p],s[p]=0,void();
	int mid=l+r>>1;
//	if(x==1)cout<<l<<" "<<r<<" "<<x<<" "<<pre<<"\n";
	if(x>=l){
		if(x<=mid)push(p<<1,l,mid,x,pre);
		push(p<<1|1,mid+1,r,x,min(pre,mn[p<<1]));
	}else{
		if(pre<=mn[p<<1])mn[p<<1]=pre,ls[p<<1]=pre,push(p<<1|1,mid+1,r,x,pre);
		else push(p<<1,l,mid,x,pre);
	}
	mn[p]=min(mn[p<<1],mn[p<<1|1]);
	ls[p]=ls[p<<1];
	s[p]=s[p<<1]+s[p<<1|1]+(mid+1)*(min(pre,mn[p<<1])-ls[p<<1|1]);
}
signed main(){
	cin>>n;
	for (int i=0;i<n;i++)
	cin>>a[i];
	int q;
	cin>>q;
	build(1,0,n-1,1e9);
	cout<<s[1]+mn[1]*n<<"\n";
	int op,x;
	while(q--){
		cin>>op;
		if(op==1){
			cin>>x;
			a[x]++;
			push(1,0,n-1,x,1e9);
			cout<<s[1]+mn[1]*n<<"\n";
		}else {
			cin>>x;
			a[x]--;
			push(1,0,n-1,x,1e9);
			cout<<s[1]+mn[1]*n<<"\n";
		}
	}
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

5
2 1 3 0 2
6
1 0
1 1
2 4
1 3
2 1
2 1

output:

4
5
7
7
9
7
3

result:

ok 7 numbers

Test #2:

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

input:

1
0
0

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: -100
Wrong Answer
time: 1ms
memory: 11720kb

input:

10
3 8 1 4 10 3 10 9 7 10
20
2 5
1 4
1 2
1 4
1 3
1 3
1 0
2 8
1 5
1 4
1 0
1 3
1 8
1 6
1 4
1 1
1 5
1 9
1 6
2 7

output:

14
14
14
16
18
19
20
23
24
24
24
26
26
26
26
26
26
26
26
26
26

result:

wrong answer 4th numbers differ - expected: '22', found: '16'