QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#78539#5278. Mex and CardsYanagi_OrigamiWA 2ms3828kbC++143.1kb2023-02-19 12:19:552023-02-19 12:20:04

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-02-19 12:20:04]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3828kb
  • [2023-02-19 12:19:55]
  • 提交

answer

#include <iostream>
#include <cstdio>
#include <cmath>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
const int N=4e5+5;
typedef long long ll;
int n,a[N],b[N];
struct node{
	int Min,l,r,tag;
	ll sum;
}seg[N<<2];
ll calc(int l,int r,int w){
	return 1ll*(r-l+1)*w;
}
void pushdown(int p){
	if(seg[p].tag==-1) return ;
	int ls=(p<<1),rs=(p<<1|1),tg=seg[p].tag;
	seg[ls].tag=tg;
	seg[rs].tag=tg;
	seg[ls].sum=calc(seg[ls].l,seg[ls].r,tg);
	seg[rs].sum=calc(seg[rs].l,seg[rs].r,tg);
	if(seg[ls].sum+seg[rs].sum!=seg[p].sum) puts("WHATS WRONG?");
	seg[p].tag=-1;
}
void upd(int p){
	seg[p].Min=min(seg[p<<1].Min,seg[p<<1|1].Min);
	seg[p].sum=seg[p<<1].sum+seg[p<<1|1].sum;
}
int queryless(int p,int l,int r,int x){
	if(l==r){
		return seg[p].Min<=x?l:(n+1);
	}
	pushdown(p);
	//ll OLD=seg[p].sum;
	int mid=(l+r)>>1,res;
	if(seg[p<<1].Min<=x) res=queryless(p<<1,l,mid,x);
	else res=queryless(p<<1|1,mid+1,r,x);
	//if(seg[p].sum!=OLD) puts("FUCK YOUR MOTHER");
	return res;
}
int querypre(int p,int l,int r,int R){
	if(r<=R){
		return seg[p].Min;
	}
	if(l>R) return 1e9;
	pushdown(p);
	int mid=(l+r)>>1;
	int res=min(querypre(p<<1,l,mid,R),querypre(p<<1|1,mid+1,r,R));
	upd(p);
	return res;
}
void build(int p,int l,int r){
	if(l==r){
		seg[p].tag=-1;
		seg[p].Min=a[l];
		seg[p].sum=b[l];
		seg[p].l=l; seg[p].r=r;
		return ;
	}
	seg[p].l=l; seg[p].r=r;
	seg[p].tag=-1;
	int mid=(l+r)>>1;
	build(p<<1,l,mid),build(p<<1|1,mid+1,r);
	upd(p);
}
void modify(int p,int l,int r,int L,int R,int x){
	if(L<=l&&r<=R){
		seg[p].tag=x;
		seg[p].sum=calc(l,r,x);
		//printf("$$$ %d %d %d %lld %d\n",p,l,r,seg[p].sum,seg[p].tag);
		return ;
	}
	if(r<L||l>R) return ;
	pushdown(p);
	int mid=(l+r)>>1;
	modify(p<<1,l,mid,L,R,x);
	modify(p<<1|1,mid+1,r,L,R,x);
	upd(p);
	
	//printf("$$$ %d %d %d %lld %d\n",p,l,r,seg[p].sum,seg[p].tag);
}
void Modify(int p,int l,int r,int x){
	if(l==r){
		seg[p].Min=a[x];
		return ;
	}
	pushdown(p);
	int mid=(l+r)>>1;
	if(x<=mid) Modify(p<<1,l,mid,x);
	else Modify(p<<1|1,mid+1,r,x);
	upd(p);
}
int main(){
	scanf("%d",&n);
	rep(i,1,n) scanf("%d",a+i);
	b[1]=a[1];
	rep(i,2,n) b[i]=min(b[i-1],a[i]);
	build(1,1,n);
	printf("%lld\n",seg[1].sum);
	int Q; scanf("%d",&Q);
	while(Q--){
		int opt,p;
		scanf("%d%d",&opt,&p);
		p++;
		//if(n>=100) printf("#%d %d\n",opt,p); 
		if(opt==1){
			a[p]++;
			Modify(1,1,n,p);
			int Min=querypre(1,1,n,p);
			int ps=queryless(1,1,n,Min-1);
			modify(1,1,n,p,ps-1,Min);
		}else{
			a[p]--;
			Modify(1,1,n,p);
			int Min=querypre(1,1,n,p);
			int ps=queryless(1,1,n,Min-1);
			modify(1,1,n,p,ps-1,Min);
			if(n>=100) printf("### %d %d %d\n",p,ps,Min);
			if(n>=100){
				b[1]=a[1];
				rep(i,2,n) b[i]=min(b[i-1],a[i]);
				b[n+1]=-1;
				if(b[ps]>b[p]||b[p]!=Min||b[ps-1]<Min) puts("FUCK");
				rep(i,p,ps-1) if(b[p]!=Min) puts("SHIHISHISHI");
			}
		}
		printf("%lld\n",seg[1].sum);
	}
	return 0;
}
/*
10
3 8 1 4 10 3 10 9 7 10
8
2 5
1 4
1 2
1 4
1 3
1 3
1 0
2 8



10
4 8 2 6 12 3 10 9 6 10
2
2 5
2 8
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 2ms
memory: 3672kb

input:

1
0
0

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: 0
Accepted
time: 2ms
memory: 3588kb

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
22
22
22
22
24
24
24
24
26
26
26
26
26
26
26
26
26
26

result:

ok 21 numbers

Test #4:

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

input:

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

output:

45
44
45
44
45
45
44
44
45
46
46
45
45
43
43
42
43
44
44
44
45

result:

ok 21 numbers

Test #5:

score: -100
Wrong Answer
time: 2ms
memory: 3588kb

input:

100
969 519 608 546 957 82 670 100 92 581 974 529 970 54 639 216 238 620 966 162 430 10 446 884 895 292 450 180 619 389 943 855 204 605 514 997 325 98 643 915 744 249 333 431 160 434 714 976 168 573 682 69 873 285 668 561 159 858 864 683 266 564 350 214 461 421 213 568 279 624 749 433 735 437 978 95...

output:

4923
4923
4923
### 50 101 10
4923
4923
### 3 6 519
4923
### 42 101 10
4923
4923
### 9 14 82
4923
4927
### 98 101 10
4927
### 33 101 10
4927
4927
### 84 101 10
4927
### 27 101 10
4927
4927
4927
4927
4927
4927
### 56 101 10
4927
4927
4927
### 99 101 10
4927
4927
4927
### 36 101 10
4927
4927
4927
### 2...

result:

wrong output format Expected integer, but "###" found