QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#115632#6630. Triangle Collectionzhouhuanyi0 2ms5844kbC++111.8kb2023-06-26 14:02:582023-06-26 14:03:01

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-06-26 14:03:01]
  • 评测
  • 测评结果:0
  • 用时:2ms
  • 内存:5844kb
  • [2023-06-26 14:02:58]
  • 提交

answer

#include<iostream>
#include<cstdio>
#define N 200000
using namespace std;
int read()
{
    char c=0;
    int sum=0,f=1;
    while (c!='-'&&(c<'0'||c>'9')) c=getchar();
    if (c=='-') c=getchar(),f=-1;
    while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
    return sum*f;
}
struct seg
{
    struct node
    {
	int l,r;
	long long minn,lazy;
    };
    node tree[(N<<2)+1];
    void push_up(int k)
    {
	tree[k].minn=min(tree[k<<1].minn,tree[k<<1|1].minn);
	return;
    }
    void spread(int k)
    {
	if (tree[k].lazy)
	{
	    tree[k<<1].minn+=tree[k].lazy,tree[k<<1].lazy+=tree[k].lazy;
	    tree[k<<1|1].minn+=tree[k].lazy,tree[k<<1|1].lazy+=tree[k].lazy;
	    tree[k].lazy=0;
	}
	return;    
    }
    void build(int k,int l,int r)
    {
	tree[k].l=l,tree[k].r=r;
	if (l==r) return;
	int mid=(l+r)>>1;
	build(k<<1,l,mid),build(k<<1|1,mid+1,r);
	return;
    }
    void add(int k,int l,int r,int d)
    {
	if (tree[k].l==l&&tree[k].r==r)
	{
	    tree[k].minn+=d,tree[k].lazy+=d;
	    return;
	}
	spread(k);
	int mid=(tree[k].l+tree[k].r)>>1;
	if (r<=mid) add(k<<1,l,r,d);
	else if (l>=mid+1) add(k<<1|1,l,r,d);
	else add(k<<1,l,mid,d),add(k<<1|1,mid+1,r,d);
	push_up(k);
	return;
    }
};
seg T;
int n,q,c[N+1];
long long res,resA,resB;
int main()
{
    int x;
    long long d;
    n=read(),q=read(),T.build(1,0,n);
    for (int i=1;i<=n;++i)
    {
	c[i]=read();
	if (c[i]&1) resA++,T.add(1,(i+2)>>1,n,1);
	resB+=(c[i]>>1),T.add(1,i,n,-(c[i]>>1));
    }
    while (q--)
    {
	x=read(),d=read();
	if (c[x]&1) resA--,T.add(1,(x+2)>>1,n,-1);
	resB-=(c[x]>>1),T.add(1,x,n,c[x]>>1);
	c[x]+=d;
	if (c[x]&1) resA++,T.add(1,(x+2)>>1,n,1);
	resB+=(c[x]>>1),T.add(1,x,n,-(c[x]>>1));
	d=resA+resB+(T.tree[1].minn<<1);
	printf("%lld\n",d+((resB-d)<<1)/3);
    }
    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: 3772kb

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:

246
241
238
239
243
243
249
251
245
242
233
240
248
249
252
252
252
245
238
243
249
243
252

result:

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

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Wrong Answer

Test #28:

score: 0
Wrong Answer
time: 2ms
memory: 5844kb

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:

885
885
885
886
886
886
886
885
885
885
885
886
887
886
887
887
886
886
886
886
886
885
885
884
884
884
885
885
885
885
886
885
885
884
885
884
883
883
883
883
884
883
883
884
884
884
884
884
884
883
883
883
883
883
883
883
883
884
883
882
882
882
882
881
881
881
881
880
880
880
880
880
880
880
879
...

result:

wrong answer 1st numbers differ - expected: '660', found: '885'

Subtask #4:

score: 0
Wrong Answer

Test #35:

score: 0
Wrong Answer
time: 2ms
memory: 5684kb

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:

883
884
883
884
883
884
883
884
883
882
881
882
881
880
879
880
881
882
881
880
879
880
881
882
883
884
884
885
886
885
884
885
884
885
884
885
886
885
886
887
888
889
889
889
888
889
888
888
888
888
888
888
888
889
888
888
888
888
888
889
888
889
889
889
888
887
886
885
886
887
886
887
886
887
886
...

result:

wrong answer 1st numbers differ - expected: '666', found: '883'

Subtask #5:

score: 0
Skipped

Dependency #1:

0%