QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#724673#7787. Maximum Ratingjuan_123#WA 2ms7920kbC++141.8kb2024-11-08 14:24:022024-11-08 14:24:02

Judging History

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

  • [2024-11-08 14:24:02]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:7920kb
  • [2024-11-08 14:24:02]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
#define double long double
#define lowbit(x) (x&(-x))
int ls[14000005],rs[14000005],sum[14000005];
#define int long long
int val[14000005];
int nw =1;
void update(int k,int pos,int add1,int add2,int l,int r){
	if(l+1 == r){
		sum[k]+=add1;
		val[k]+=add2;
		return;
	}
	int mid = l+r>>1;
	if(pos<mid){
		if(!ls[k])ls[k] = ++nw;
		update(ls[k],pos,add1,add2,l,mid);
	}else{
		if(!rs[k])rs[k] = ++nw;
		update(rs[k],pos,add1,add2,mid,r);
	}
	sum[k]=sum[ls[k]]+sum[rs[k]];
	val[k]=val[ls[k]]+val[rs[k]];
//	cout << " " <<  k << " " << l << " " << r << " " << sum[k] << " " << val[k] << endl;
}
int find(int k,int l,int r,int x){
//	cout << k << " " << l << " " << r << " " << x << endl;
	if(!k)return 0;
	if(l+1 == r){return min(x/l,val[k]);}
	if(sum[ls[k]]>=x)return find(ls[k],l,l+r>>1,x);
	return find(rs[k],l+r>>1,r,x-sum[ls[k]])+val[ls[k]];
}
int query(int k,int l,int r,int ll,int rr){
	if(!k or l>=rr or ll>=r)return 0;
	if(l<=ll and rr<=r)return val[k];
	return query(ls[k],l,r,ll,ll+rr>>1)+query(rs[k],l,r,ll+rr>>1,rr);
}

const int M = 1000000001;
int ssum = 0,tot = 0;
int a[500005];
int n,q;
signed main(){
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin >> n >> q;
	for(int i = 1;i<=n;i++)cin >> a[i];
	for(int i = 1;i<=n;i++){
		if(a[i]<0){
			ssum+=-a[i];
		}else{
			++tot;
			update(1,a[i],a[i],1,1,M+1);
		}
	}
	for(int i = 1;i<=q;i++){
		int pos,v;cin >> pos >> v;
		if(a[pos]<0){
			ssum-=-a[pos];
		}
		if(a[pos]>0){
			--tot;
			update(1,a[pos],-a[pos],-1,1,M+1);
		}
		if(v<0){
			ssum+=-v;
		}
		if(v>0){
			++tot;
			update(1,v,v,1,1,M+1);
		}
		a[pos] = v;
		int x = find(1,1,M+1,ssum)+1;
		cout << x << '\n';
	} 
	return 0;
}/*
3 5
1 2 3
3 4
2 -2
1 -3
3 1
2 1
*/

詳細信息

Test #1:

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

input:

3 5
1 2 3
3 4
2 -2
1 -3
3 1
2 1

output:

1
2
2
2
3

result:

ok 5 number(s): "1 2 2 2 3"

Test #2:

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

input:

3 5
1 2 3
3 4
2 -2
1 3
3 1
2 1

output:

1
2
1
2
1

result:

ok 5 number(s): "1 2 1 2 1"

Test #3:

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

input:

1 1
1000000000
1 1000000000

output:

1

result:

ok 1 number(s): "1"

Test #4:

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

input:

1 1
-1000000000
1 -1000000000

output:

1

result:

ok 1 number(s): "1"

Test #5:

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

input:

1000 1000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

output:

946
65
252
410
915
592
983
487
343
899
809
432
586
587
139
464
804
84
476
699
504
149
579
352
375
856
545
166
140
657
568
509
275
710
873
430
537
879
301
1
298
970
923
510
984
642
55
879
941
344
464
788
917
994
571
610
491
442
926
101
986
840
624
613
425
345
816
423
275
221
317
113
386
116
469
260
4...

result:

ok 1000 numbers

Test #6:

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

input:

1000 1000
1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000...

output:

500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
...

result:

ok 1000 numbers

Test #7:

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

input:

1000 1000
-485078954 -474724347 -284958745 -99994191 -853392841 -796786314 -87134718 -861459498 -982809180 -184620712 -618476092 -244916830 -349486182 -751407510 -874417202 -419521829 -888338757 -735353446 -426330733 -715383449 -48093437 -359419189 -474876639 -887614191 -157085227 -51186523 -4851821...

output:

2
3
4
5
6
7
8
9
10
11
12
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
51
52
53
54
55
56
57
58
59
60
60
61
62
63
64
65
65
66
67
68
69
70
71
72
73
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
88
89
90
91
92
92
93
94
95
96...

result:

wrong answer 746th numbers differ - expected: '505', found: '506'