QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#78533#5278. Mex and CardsYanagi_OrigamiWA 2ms3824kbC++143.3kb2023-02-19 12:11:272023-02-19 12:11:29

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:11:29]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3824kb
  • [2023-02-19 12:11:27]
  • 提交

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 n+1;
	pushdown(p);
	ll OLD=seg[p].sum;
	int mid=(l+r)>>1;
	int res=min(querypre(p<<1,l,mid,R),querypre(p<<1|1,mid+1,r,R));
	upd(p);
	if(seg[p].sum!=OLD) puts("FUCK YOUR MOTHER");
	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 ;
	}
	ll OLD=seg[p].sum;
	pushdown(p);
	upd(p);
	if(seg[p].sum!=OLD) puts("FUCK YOUR MOTHER");
	int mid=(l+r)>>1;
	if(R<=mid) modify(p<<1,l,mid,L,R,x); else
	if(L>mid) modify(p<<1|1,mid+1,r,L,R,x); else
	modify(p<<1,l,mid,L,mid,x),modify(p<<1|1,mid+1,r,mid+1,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: 0ms
memory: 3592kb

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

input:

1
0
0

output:

0

result:

ok 1 number(s): "0"

Test #3:

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

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

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

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
4505
### 50 101 10
4505
4505
### 3 6 101
FUCK
SHIHISHISHI
SHIHISHISHI
SHIHISHISHI
3669
### 42 101 10
3669
3669
### 9 14 82
3669
3251
### 98 101 10
3251
### 33 101 10
3251
3251
### 84 101 10
3251
### 27 101 10
3251
3251
3251
3251
3251
3251
### 56 101 10
3251
3251
3251
### 99 101 10
3251
325...

result:

wrong answer 3rd numbers differ - expected: '4923', found: '4505'