QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#224694#5441. Quartz CollectionZSH_ZSH#WA 1ms5936kbC++143.6kb2023-10-23 09:34:542023-10-23 09:34:55

Judging History

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

  • [2023-10-23 09:34:55]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5936kb
  • [2023-10-23 09:34:54]
  • 提交

answer

#include<bits/stdc++.h>
#define rep(i,a,b) for (register int i=(a);i<=(b);i++)
#define drep(i,a,b) for (register int i=(a);i>=(b);i--)
typedef long long ll;
using namespace std;

const int N=300010;

int n,a[N],b[N],m;

struct info
{
	int ls,rs,rnd,tag,val,X,size;
	ll sum;
}t[N];
inline void push_up(int x)
{
	t[x].sum=t[x].val;
	if (t[x].ls) t[x].sum+=t[t[x].ls].sum;
	if (t[x].rs) t[x].sum+=t[t[x].rs].sum;
	t[x].size=1;
	if (t[x].ls) t[x].size+=t[t[x].ls].size;
	if (t[x].rs) t[x].size+=t[t[x].rs].size;
}
void setcov(int node)
{
	t[node].tag^=1;
	t[node].val=-t[node].val;
	t[node].sum=-t[node].sum;
}
inline void push_down(int x)
{
	if (t[x].tag)
	{
		if (t[x].ls) setcov(t[x].ls);
		if (t[x].rs) setcov(t[x].rs);
		t[x].tag=0;
	}
}
array<int,2> split(int x,int X)
{
	if (!x) return {0,0};
	push_down(x);
	if (t[x].X<=X)
	{
		auto rs=split(t[x].rs,X);
		t[x].rs=rs[0];
		push_up(x);
		return {x,rs[1]};
	}
	else
	{
		auto ls=split(t[x].ls,X);
		t[x].ls=ls[1];
		push_up(x);
		return {ls[0],x};
	}
}
array<int,2> splitsz(int x,int sz)
{
	if (!x) return {0,0};
	push_down(x);
	if (t[t[x].ls].size+1<=sz)
	{
		auto rs=split(t[x].rs,sz-t[t[x].ls].size-1);
		t[x].rs=rs[0];
		push_up(x);
		return {x,rs[1]};
	}
	else
	{
		auto ls=split(t[x].ls,sz);
		t[x].ls=ls[1];
		push_up(x);
		return {ls[0],x};
	}
}

int merge(int x,int y)
{
	if (!x||!y) return x+y;
	push_down(x);
	push_down(y);
	if (t[x].rnd<t[y].rnd)
	{
		t[x].rs=merge(t[x].rs,y);
		push_up(x);
		return x;
	}
	else
	{
		t[y].ls=merge(x,t[y].ls);
		push_up(y);
		return y;
	}
}
mt19937 rng(time(0));
int rt[5],cnt;

map<int,int> mp;
void ins(int x)
{
	mp[x]++;
	if (x<=0)
	{
		array<int,2> s[4];
		rep(i,0,3) s[i]=split(rt[i],x);
		t[++cnt].rnd=rng();
		t[cnt].X=x;
		t[cnt].val=x;
		t[cnt].sum=x;
		t[cnt].size=1;
		int id=0;
		rep(i,0,3) id+=t[s[i][0]].size;
		id++; id%=4;
		s[id][0]=merge(s[id][0],cnt);
		rep(i,0,3) rt[i]=merge(s[i][0],s[(i+3)%4][1]);
	}
	else
	{
		auto s=split(rt[4],x);
		t[++cnt].rnd=rng();
		t[cnt].X=x;
		t[cnt].val=t[cnt].sum=((t[s[0]].size%2==1)?x:-x);
		t[cnt].size=1;
		if (s[1]) setcov(s[1]);
		rt[4]=merge(merge(s[0],cnt),s[1]);
	}
}
void del(int x)
{
	assert(mp[x]);
	mp[x]--;
	if (x<=0)
	{
		array<int,2> s[4];
		rep(i,0,3) s[i]=split(rt[i],x);
		int id=0;
		rep(i,0,3) id+=t[s[i][0]].size;
		id%=4;
		{
			auto ss=splitsz(s[id][0],t[s[id][0]].size-1);
			s[id][0]=ss[0];
		}
		rep(i,0,3) rt[i]=merge(s[i][0],s[(i+1)%4][1]);
	}
	else
	{
		assert(t[rt[4]].size); 
		assert(t[rt[4]].size); 
		{
			auto sss=splitsz(rt[4],t[rt[4]].size-1);
//			assert(t[sss[1]].size==1);
//			assert(t[sss[1]].X>=x);
			rt[4]=merge(sss[0],sss[1]); 
			assert(t[rt[4]].size); 
		}
		auto s=split(rt[4],x);
		auto ss=splitsz(s[0],t[s[0]].size-1);
		if (s[1]) setcov(s[1]);
		rt[4]=merge(ss[0],s[1]);
	}
}

ll xns;
void solve()
{
	ll ans=xns;
	ans+=t[rt[0]].sum+t[rt[1]].sum; 
	ans-=t[rt[2]].sum+t[rt[3]].sum; 
	int sz=0;
	rep(i,0,3) sz+=t[rt[i]].size;
	sz%=2;
	if (sz==0)
	{
		ans-=t[rt[4]].sum;
	}
	else ans+=t[rt[4]].sum;
	printf("%lld\n",ans/2);
}

int main()
{
	ios::sync_with_stdio(false); cin.tie(0);
	
	cin>>n>>m;
	rep(i,1,n) cin>>a[i]>>b[i],a[i]*=2,b[i]*=2;
	
	rep(i,1,n)
	{
		xns+=(a[i]+b[i])/2;
		ins((a[i]-b[i])/2);
	}
	solve();
	
	rep(i,1,m)
	{
		int t,A,B; cin>>t>>A>>B;
		A*=2; B*=2;
		
		xns-=((a[t]+b[t])/2);
		del((a[t]-b[t])/2);
		
		a[t]=A,b[t]=B;
		xns+=((a[t]+b[t])/2);
		ins((a[t]-b[t])/2);
		solve();
	}
	
	return 0;
}
/*
4 5
2 4
5 7
1 7
2 1
4 5 2
1 6 2
4 4 3
2 1 3
3 6 6

*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4 5
2 4
5 7
1 7
2 1
4 5 2
1 6 2
4 4 3
2 1 3
3 6 6

output:

13
14
15
14
10
13

result:

ok 6 numbers

Test #2:

score: 0
Accepted
time: 0ms
memory: 5888kb

input:

1 1
1 1
1 1 1

output:

1
1

result:

ok 2 number(s): "1 1"

Test #3:

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

input:

100 100
6 7
100 8
5 61
5 75
59 65
51 47
83 37
34 54
87 46
4 26
21 87
12 97
86 68
60 11
62 76
14 83
29 31
91 62
57 80
47 75
85 97
62 77
91 86
14 25
48 77
83 65
39 61
78 77
45 46
90 74
100 91
86 98
55 5
84 42
91 69
100 4
74 98
60 37
75 44
41 12
15 34
36 1
99 16
7 87
36 26
79 42
41 84
17 98
72 16
38 55...

output:

5109
5085
5080
5024
4992
5024
4981
4955
4964
4964
5016
4957
4830
4786
4829
4865
4899
4846
4804
4756
4884
4773
4709
4619
4583
4655
4774
4674
4678
4726
4692
4767
4789
4733
4700
4730
4729
4782
4846
4716
4669
4671
4679
4762
4752
4788
4728
4778
4732
4702
4739
4631
4598
4666
4694
4653
4687
4584
4550
4578
...

result:

wrong answer 2nd numbers differ - expected: '5065', found: '5085'