QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#197809#3857. Single-track railwayForever_Young#WA 1ms5896kbC++231.3kb2023-10-02 20:08:322023-10-02 20:08:33

Judging History

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

  • [2023-10-02 20:08:33]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5896kb
  • [2023-10-02 20:08:32]
  • 提交

answer

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,tune=native")
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=1;i<=n;++i)
#define per(i,n) for(int i=n;i>=1;--i)
#define pb push_back
#define mp make_pair
#define N 210000
#define inf 1000000000
int n;
int a[N];
long long st[N];
int lowbit(int x)
{
	return x & (-x);
}
void add(int x,long long p)
{
	while (x<=n-1)
	{
		st[x]+=p;
		x+=lowbit(x);
	}
}
long long get(int x)
{
	long long ret=0;
	while (x>0)
	{
		ret+=st[x];
		x-=lowbit(x);
	}
	return ret;
}
long long getsum(int l,int r)
{
	if (l>r)return 0;
	return get(r)-get(l-1);
}
long long getans()
{
	int l=1,r=n;
	while (l<r)
	{
		int mid=(l+r)/2;
		if (getsum(1,mid-1)*2>=st[1])r=mid;
		else l=mid+1;
	}
	long long ans=2147483647ll*100000ll,ansp;
	for(int i=max(1,l-2);i<=min(n,l+2);i++)
	{
		long long wait=abs(getsum(1,i-1)-getsum(i,n-1));
		if (wait<ans)ans=wait,ansp=i;
	}
	return ans;
}
int main()
{
	cin>>n;
	rep(i,n-1)scanf("%d",&a[i]);
	rep(i,n-1)add(i,a[i]);
	printf("%lld\n",getans());
	int q; cin>>q;
	while (q--)
	{
		int x,y; scanf("%d%d",&x,&y);
		add(x,y-a[x]);
		a[x]=y;
		printf("%lld\n",getans());
	}
}

详细

Test #1:

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

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: 0ms
memory: 3580kb

input:

3
8 41
0

output:

33

result:

ok single line: '33'

Test #3:

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

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:

816
789
798
821
851
838
811
749
789
830
877

result:

wrong answer 1st lines differ - expected: '8', found: '816'