QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#241197#5441. Quartz CollectionarahatoWA 2ms13992kbC++141.6kb2023-11-06 00:14:492023-11-06 00:14:51

Judging History

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

  • [2023-11-06 00:14:51]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:13992kb
  • [2023-11-06 00:14:49]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;

#define int long long

const int N=1e5+5;
int n,m,a[N],b[N],bas;

struct tr4{
	int tr[N<<2][4],n[N<<2];
	
	void pushup(int x){
		int l=x<<1,r=x<<1|1,N=n[l]%4;
		for(int i=0;i<4;i++) tr[x][i]=tr[l][i]+tr[r][(i-N+4)%4];
		n[x]=n[l]+n[r];
	}
	
	void up(int x,int l,int r,int p){
		if(l==r){
			n[x]++;
			int _0=tr[x][3]+p,_1=tr[x][0],_2=tr[x][1],_3=tr[x][2];
			tr[x][0]=_0,tr[x][1]=_1,tr[x][2]=_2,tr[x][3]=_3;
			return ;
		}
		int mid=l+r>>1;
		if(p<=mid) up(x<<1,l,mid,p);
		else up(x<<1|1,mid+1,r,p);
		pushup(x);
	}
	
	void del(int x,int l,int r,int p){
		if(l==r){
			n[x]--;
			tr[x][n[x]%4]-=p;
			return ;
		}
		int mid=l+r>>1;
		if(p<=mid) del(x<<1,l,mid,p);
		else del(x<<1|1,mid+1,r,p);
		pushup(x);
	}
	
	void up(int v){
		up(1,0,1e5,v);
	}
	
	void del(int v){
		del(1,0,1e5,v);
	}
	
	int que(int o){
		return tr[1][o];
	}
}A,B;

void doit(){
	int delta=0;
	delta+=A.que((1+A.n[1])%4)+A.que((2+A.n[1])%4);
	delta+=B.que(A.n[1]%2);
	cout<<bas+delta<<endl;
}

signed main(){
	ios::sync_with_stdio(0);
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>a[i]>>b[i];
		if(a[i]<=b[i]){
			bas+=a[i];
			A.up(b[i]-a[i]);
		}
		else{
			bas+=b[i];
			B.up(a[i]-b[i]);
		}
	}
	doit();
	while(m--){
		int i,x,y;
		cin>>i>>x>>y;
		if(a[i]<=b[i]){
			bas-=a[i];
			A.del(b[i]-a[i]);
		}
		else{
			bas-=b[i];
			B.del(a[i]-b[i]);
		}
		a[i]=x,b[i]=y;
		if(a[i]<=b[i]){
			bas+=a[i];
			A.up(b[i]-a[i]);
		}
		else{
			bas+=b[i];
			B.up(a[i]-b[i]);
		}
		doit();
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4 5
2 4
5 7
1 7
2 1
4 5 2
1 6 2
4 4 3
2 1 3
3 6 6

output:

13
14
15
14
10
13

result:

ok 6 numbers

Test #2:

score: 0
Accepted
time: 1ms
memory: 11836kb

input:

1 1
1 1
1 1 1

output:

1
1

result:

ok 2 number(s): "1 1"

Test #3:

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

input:

100 100
6 7
100 8
5 61
5 75
59 65
51 47
83 37
34 54
87 46
4 26
21 87
12 97
86 68
60 11
62 76
14 83
29 31
91 62
57 80
47 75
85 97
62 77
91 86
14 25
48 77
83 65
39 61
78 77
45 46
90 74
100 91
86 98
55 5
84 42
91 69
100 4
74 98
60 37
75 44
41 12
15 34
36 1
99 16
7 87
36 26
79 42
41 84
17 98
72 16
38 55...

output:

4723
4635
4626
4620
4588
4621
4578
4555
4502
4567
4520
4487
4457
4432
4520
4486
4469
4419
4420
4361
4362
4304
4249
4209
4138
4222
4246
4321
4311
4319
4348
4361
4305
4328
4287
4258
4255
4309
4377
4411
4335
4337
4320
4325
4289
4383
4311
4313
4262
4242
4204
4188
4117
4122
4220
4202
4149
4120
4104
4056
...

result:

wrong answer 1st numbers differ - expected: '5109', found: '4723'