QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#186925#3857. Single-track railwaydoll_sister#WA 1ms5864kbC++14751b2023-09-24 13:21:592023-09-24 13:22:00

Judging History

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

  • [2023-09-24 13:22:00]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5864kb
  • [2023-09-24 13:21:59]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+5;
ll a[N],c[N],s=0;
int n;
void U(int x,int y){
	while(x<=n)c[x]+=y,x+=x&-x;
}
ll Q(int x){
	ll r=0;
	while(x)r+=c[x],x-=x&-x;
	return r;
}
ll Get(){
	int cur=0;
	ll sum=0;
	for(int i=18;i>=0;i--){
		if(cur+(1<<i)<=n&&c[cur+(1<<i)]+sum<=s/2){
			cur+=(1<<i);
			sum+=c[cur];
		}
	}
	ll ans=s-2*sum;
	if(cur<n){
		ans=min(ans,2*Q(cur+1)-sum);
	}
	return ans;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<n;i++){
		scanf("%lld",&a[i]);
		U(i,a[i]);
		s+=a[i];
	}
	cout<<Get()<<'\n';
	int q;
	scanf("%d",&q);
	for(int i=1;i<=q;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		U(x,y-a[x]),s+=y-a[x],a[x]=y;
		cout<<Get()<<'\n';
	}
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 5864kb

input:

2
39
7
1 20
1 70
1 56
1 37
1 37
1 37
1 91

output:

39
20
70
56
37
37
37
91

result:

ok 8 lines

Test #2:

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

input:

3
8 41
0

output:

33

result:

ok single line: '33'

Test #3:

score: -100
Wrong Answer
time: 0ms
memory: 5804kb

input:

30
86 100 80 30 23 17 90 98 20 3 43 31 49 14 14 47 13 44 7 30 50 29 67 68 56 69 28 61 81
10
21 23
7 99
16 70
3 50
4 17
26 42
7 37
10 43
26 83
13 96

output:

8
79
70
93
25
10
11
17
5
18
27

result:

wrong answer 2nd lines differ - expected: '19', found: '79'