QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#115495#6630. Triangle CollectionHe_Ren#0 9ms5976kbC++172.0kb2023-06-26 10:31:312024-05-31 14:14:22

Judging History

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

  • [2024-05-31 14:14:22]
  • 评测
  • 测评结果:0
  • 用时:9ms
  • 内存:5976kb
  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-26 10:31:31]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int MAXN = 2e5 + 5;

struct Data
{
	ll sum, ans, rem;
	void init(int x)
	{
		sum = x;
		ans = x / 3;
		rem = x / 2 - ans;
	}
};
Data operator + (Data A,Data B)
{
	Data res;
	res.sum = A.sum + B.sum;
	res.ans = 0;
	res.rem = 0;
	
	ll use = min(B.rem, A.sum);
	res.ans += B.ans;
	res.ans += use;
	res.rem += B.rem - use;
	
	ll lim = (A.sum - use) / 3;
	lim = min(lim, A.ans);
	res.ans += lim;
	res.rem += A.ans + A.rem - lim;
	
	return res;
}

struct Segment_Tree
{
	Data tree[MAXN<<2];
	#define ls(u) ((u)<<1)
	#define rs(u) ((u)<<1|1)
	#define lson(u) ls(u),l,mid
	#define rson(u) rs(u),mid+1,r
	inline void push_up(int u)
	{
		tree[u] = tree[ls(u)] + tree[rs(u)];
	}
	void build(int u,int l,int r,int *a)
	{
		if(l == r){ tree[u].init(a[l]); return;}
		int mid = (l+r)>>1;
		build(lson(u),a); build(rson(u),a);
		push_up(u);
	}
	void set(int u,int l,int r,int q,int k)
	{
		if(l == r){ tree[u].init(k); return;}
		int mid = (l+r)>>1;
		if(q<=mid) set(lson(u),q,k);
		else set(rson(u),q,k);
		push_up(u);
	}
	void dfs(int u,int l,int r)
	{
		printf("tree[%d]:\n",u);
		printf("seg = [%d, %d]\n",l,r);
		printf("sum = %lld, ans = %lld, rem = %lld\n",tree[u].sum,tree[u].ans,tree[u].rem);
		if(l == r) return;
		int mid = (l+r)>>1;
		dfs(lson(u)); dfs(rson(u));
	}
}tree;

int a[MAXN];

int main(void)
{
	int n,Q;
	scanf("%d%d",&n,&Q);
	for(int i=1; i<=n; ++i)
		scanf("%d",&a[i]);
	
	auto query = [&] (void)
	{
		static ll b[MAXN];
		fill(b+1, b+n+1, 0);
		for(int i=1; i<=n; ++i)
			b[i / 2 + 1] += a[i];
		
		ll cur = 0;
		for(int i=1; i<=n; ++i)
		{
			b[i] += b[i-1];
			cur = min(cur + a[i] / 2, b[i] / 3);
		}
		return cur;
	};
	
//	tree.build(1,1,n,a);
	
	printf("%lld\n",query());
	while(Q--)
	{
		int x,k;
		scanf("%d%d",&x,&k);
		a[x] += k;
		printf("%lld\n",query());
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 5976kb

input:

1 23
1485
1 -12
1 -30
1 -20
1 6
1 24
1 5
1 31
1 14
1 -34
1 -22
1 -45
1 37
1 46
1 9
1 22
1 -9
1 9
1 -46
1 -47
1 39
1 36
1 -36
1 50

output:

495
491
481
474
476
484
486
496
501
489
482
467
479
495
498
505
502
505
490
474
487
499
487
504

result:

wrong answer 1st numbers differ - expected: '491', found: '495'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Wrong Answer

Test #28:

score: 0
Wrong Answer
time: 9ms
memory: 3888kb

input:

1999 2000
1 1 1 1 0 2 0 2 1 0 2 1 2 2 2 1 2 0 0 1 2 2 0 1 0 1 0 2 0 0 2 1 1 1 1 0 1 2 1 2 1 1 1 1 1 0 2 2 0 2 1 1 2 0 0 2 0 0 2 1 2 0 0 1 1 2 0 2 2 2 1 2 0 2 1 2 0 1 2 2 2 1 1 2 1 1 1 1 0 0 1 1 0 1 2 1 0 0 2 0 2 2 2 0 1 1 2 0 0 1 0 0 2 1 2 1 2 0 1 1 2 2 0 0 1 2 2 1 2 1 2 2 2 0 0 1 1 2 1 1 2 2 2 2 2 ...

output:

660
660
660
660
661
661
661
661
660
660
660
660
661
662
662
663
663
662
661
662
662
661
660
661
660
660
660
661
661
661
661
662
661
661
660
661
660
659
658
658
659
659
658
659
660
660
660
660
660
660
659
659
659
659
659
659
659
659
660
659
658
658
658
658
657
657
657
658
657
656
657
657
657
656
656
...

result:

wrong answer 4th numbers differ - expected: '661', found: '660'

Subtask #4:

score: 0
Wrong Answer

Test #35:

score: 0
Wrong Answer
time: 6ms
memory: 5976kb

input:

2000 1999
0 1 0 3 0 1 0 0 0 0 0 0 0 2 0 0 0 0 3 1 1 0 2 0 0 3 0 0 0 0 0 4 0 0 1 0 1 0 0 0 0 1 2 1 0 0 0 0 7 0 1 3 1 0 1 1 0 3 2 1 0 1 1 3 3 1 0 2 0 0 0 0 0 0 0 0 1 0 0 0 2 0 0 0 0 0 1 2 3 0 1 0 3 3 0 0 0 0 1 0 1 2 0 0 2 2 0 1 2 1 2 0 0 0 1 1 0 1 2 0 0 0 0 2 0 5 0 0 0 0 0 1 0 0 2 0 1 2 0 1 0 0 0 2 0 ...

output:

666
666
666
666
666
666
666
666
666
666
666
666
666
666
666
666
666
666
666
666
666
666
666
666
666
666
666
666
666
666
666
666
666
666
666
666
666
666
666
666
666
666
666
666
666
665
665
665
665
665
665
665
665
665
665
665
665
665
665
665
665
665
666
666
666
666
666
666
666
666
666
666
666
666
666
...

result:

wrong answer 45th numbers differ - expected: '665', found: '666'

Subtask #5:

score: 0
Skipped

Dependency #1:

0%