QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#186979#3857. Single-track railwaygugugu#WA 0ms3840kbC++14940b2023-09-24 13:39:332023-09-24 13:39:34

Judging History

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

  • [2023-09-24 13:39:34]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3840kb
  • [2023-09-24 13:39:33]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
const int maxn=200100;
int a[maxn],n,k;
long long c[maxn];
inline void add(int x,int v) {
	for(;x<maxn;x+=(x&(-x))) c[x]+=v;
}
long long sumall;
inline long long query(int x) {
	long long ans=0;
	for(;x;x&=x-1) ans+=c[x];
	return ans;
}
inline int getpos() {
	int p=0;
	long long s=0;
	for(int i=18;i>=0;i--) if(p+(1<<i)<maxn&&(s+c[p+(1<<i)])*2<=sumall) {
		p+=(1<<i);
		s+=c[p];
	}
	return p;
}
inline long long getans() {
	int p=getpos();
	long long sa=query(p),sb=sumall-query(p);
	long long ans=sb-sa;
	sa=query(p+1);sb=sumall-query(p+1);
	ans=min(ans,sa-sb);
	return ans;
}
int main() {
	scanf("%d",&n);
	for(int i=1;i<n;i++) scanf("%d",a+i),add(i,a[i]),sumall+=a[i];
	scanf("%d",&k);
	printf("%lld\n",getans());
	while(k--) {
		int pos,v;scanf("%d%d",&pos,&v);
		add(pos,v-a[pos]);
		sumall+=v-a[pos];
		printf("%lld\n",getans());
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3840kb

input:

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

output:

39
20
51
68
66
64
62
114

result:

wrong answer 3rd lines differ - expected: '70', found: '51'