QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#617189#7787. Maximum RatingD06WA 4ms10652kbC++143.9kb2024-10-06 14:21:132024-10-06 14:21:14

Judging History

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

  • [2024-10-06 14:21:14]
  • 评测
  • 测评结果:WA
  • 用时:4ms
  • 内存:10652kb
  • [2024-10-06 14:21:13]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
int n,h[200005],root;
struct t1
{
	int fa,s[2];
	int va,size;
	long long sum;
	t1()
	{
		fa=s[0]=s[1]=0;
		va=size=sum=0;
	}
}t[200005];
bool get(int x)
{
	return x==t[t[x].fa].s[1];
}
void maintain(int x)
{
	t[x].sum=t[t[x].s[0]].sum+t[t[x].s[1]].sum+t[x].va;
	t[x].size=t[t[x].s[0]].size+t[t[x].s[1]].size+1;
}
void rotate(int x)
{
	int y=t[x].fa,z=t[y].fa,opt=get(x);
	t[y].s[opt]=t[x].s[opt^1];
	if(t[x].s[opt^1])
	{
		t[t[x].s[opt^1]].fa=y;
	}
	t[x].s[opt^1]=y;
	t[y].fa=x;
	t[x].fa=z;
	if(z)
	{
		t[z].s[y==t[z].s[1]]=x;
	}
	maintain(y);
	maintain(x);
}
void update(int x)
{
//	cout<<"update"<<x<<endl;
	maintain(x);
	if(t[x].fa)
	{
		update(t[x].fa);
	}
}
void Splay(int x,int k)
{
	update(x);
	while(t[x].fa!=k)
	{
		int y=t[x].fa,z=t[y].fa;
		if(z!=k)
		{
			if(get(x)==get(y))
			{
				rotate(y);
			}
			else
			{
				rotate(x);
			}
		}
		rotate(x);
	}
	if(!k)
	{
		root=x;
	}
}
void output(int p)
{
	if(!p)
	{
		return;
	}
	output(t[p].s[0]);
	cout<<" "<<t[p].va;
	output(t[p].s[1]);
}
int rnk(int p,int va)
{
	if(t[t[p].s[0]].size==va-1)
	{
		return p;
	}
	else if(t[t[p].s[0]].size<va-1)
	{
		return rnk(t[p].s[1],va-t[t[p].s[0]].size-1);
	}
	else
	{
		return rnk(t[p].s[0],va);
	}
}
int ask(int p)
{
	Splay(rnk(root,1),0);
	Splay(rnk(root,p+2),rnk(root,1));
//	output(t[p+2].s[0]);
//	cout<<endl;
//	cout<<t[t[p+2].s[0]].sum<<"!!!"<<endl;
	return t[t[rnk(root,p+2)].s[0]].sum;
}
void insert(int x)
{
	int p=root;
	while(p)
	{
//		cout<<p<<endl;
		if(t[x].va>t[p].va)
		{
			if(!t[p].s[1])
			{
				t[p].s[1]=x;
				t[x].fa=p;
			//	cout<<"update"<<x<<endl;
		//		exit(0);
				Splay(x,0);
				return;
			}
			p=t[p].s[1];
		}
		else
		{
			if(!t[p].s[0])
			{
				t[p].s[0]=x;
				t[x].fa=p;
			//	cout<<"update"<<x<<endl;
			//	cout<<t[2].fa<<" "<<t[t[2].fa].fa<<" "<<t[t[t[2].fa].fa].fa<<endl;
			//	exit(0);
				Splay(x,0);
				return;
			}
			p=t[p].s[0];
		}
	}
}
int nxt(int p)
{
	while(t[p].s[1])
	{
		p=t[p].s[1];
	}
	return p;
}
void erase(int p)
{
	Splay(p,0);
	if(!t[p].s[0])
	{
		t[t[p].s[1]].fa=t[p].fa;
		if(t[p].fa)
		{
			t[t[p].fa].s[get(p)]=t[p].s[1]; 
		}
		Splay(t[p].s[1],0);
	}
	else if(!t[p].s[1])
	{
		t[t[p].s[0]].fa=t[p].fa;
		if(t[p].fa)
		{
			t[t[p].fa].s[get(p)]=t[p].s[0];
		}
		Splay(t[p].s[0],0);
	}
	else
	{
		int v=nxt(t[p].s[0]);
	//	cout<<v<<endl;
		Splay(v,p);
		t[v].s[1]=t[p].s[1]; 
		t[t[p].s[1]].fa=v;
		t[v].fa=t[p].fa;
		if(t[p].fa)
		{
			t[t[p].fa].s[get(p)]=v;
		}
		Splay(v,0);
	}
	t[p].fa=t[p].s[0]=t[p].s[1]=0;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int q,maxn=0;
	cin>>n>>q;
	t[1].va=INT_MIN;
	t[n+2].va=INT_MAX;
	t[1].s[1]=n+2;
	t[n+2].fa=1;
	maintain(n+2);
	maintain(1);
	root=1;
	h[1]=1;
	for(int i=2;i<=n+1;i++)
	{
		cin>>t[i].va;
		insert(i);
		h[i]=i;
		maxn+=(t[i].va>0);
	}
	auto check=[](int p)
	{
		return ask(p)<=0;	
	};
	for(int j=1;j<=n;j++)
	{
//		cout<<ask(j)<<endl;
	}
//	cout<<endl;
	for(int i=1;i<=q;i++)
	{
	//	output(root);
	//	cout<<"!"<<endl;
		int x,v;
		cin>>x>>v;
		maxn-=(t[x+1].va>0);
		maxn+=(v>0);
		t[x+1].va=v;
	//	cout<<"erase"<<x+1<<" "<<t[4].fa<<endl;
		erase(x+1);
	//	cout<<t[4].fa<<" "<<t[5].fa<<endl;
	//	cout<<"insert"<<x+1<<endl;
		insert(x+1);
		for(int j=1;j<=n;j++)
		{
//			cout<<ask(j)<<" ";
		}
//		cout<<endl;
		int p=partition_point(h+1,h+n+1,check)-h;
		int minn=n+1-p;
//		cout<<p<<"\n";
		cout<<maxn-minn+1<<"\n"; 
//		cout<<maxn<<" "<<minn<<"\n";
//		cout<<"---"<<endl;
	}
	return 0;
}
/*
4 7
3 -1 2 3
1 1
2 3
3 -10
4 -5
1 2
2 10
3 1
ans: 2 1 4 3 3 3 3

4 7
3 5 -10 10
3 -11
1 5
2 -3
1 -1
4 -5
1 1
2 3
ans: 3 3 2 2 1 2 3

3 2
-1 -2 -3
1 1
2 1
ans:2 3

4 3
1 5 -2 4
3 0
2 -5
1 0
ans:3 3 2

2 2
0 0 
1 0
2 0
ans:0 0
*/

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 10376kb

input:

3 5
1 2 3
3 4
2 -2
1 -3
3 1
2 1

output:

1
2
2
2
3

result:

ok 5 number(s): "1 2 2 2 3"

Test #2:

score: 0
Accepted
time: 1ms
memory: 10652kb

input:

3 5
1 2 3
3 4
2 -2
1 3
3 1
2 1

output:

1
2
1
2
1

result:

ok 5 number(s): "1 2 1 2 1"

Test #3:

score: 0
Accepted
time: 1ms
memory: 9848kb

input:

1 1
1000000000
1 1000000000

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: 0
Accepted
time: 2ms
memory: 9840kb

input:

1 1
-1000000000
1 -1000000000

output:

1

result:

ok 1 number(s): "1"

Test #5:

score: 0
Accepted
time: 2ms
memory: 10180kb

input:

1000 1000
1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 ...

output:

946
65
252
410
915
592
983
487
343
899
809
432
586
587
139
464
804
84
476
699
504
149
579
352
375
856
545
166
140
657
568
509
275
710
873
430
537
879
301
1
298
970
923
510
984
642
55
879
941
344
464
788
917
994
571
610
491
442
926
101
986
840
624
613
425
345
816
423
275
221
317
113
386
116
469
260
4...

result:

ok 1000 numbers

Test #6:

score: 0
Accepted
time: 2ms
memory: 9816kb

input:

1000 1000
1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000000 1 -1000000...

output:

500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
500
...

result:

ok 1000 numbers

Test #7:

score: -100
Wrong Answer
time: 4ms
memory: 10456kb

input:

1000 1000
-485078954 -474724347 -284958745 -99994191 -853392841 -796786314 -87134718 -861459498 -982809180 -184620712 -618476092 -244916830 -349486182 -751407510 -874417202 -419521829 -888338757 -735353446 -426330733 -715383449 -48093437 -359419189 -474876639 -887614191 -157085227 -51186523 -4851821...

output:

-485
-208
-207
-205
-204
-203
-150
-63
-57
-55
-719
-719
-718
-717
-716
-715
-714
-713
-701
-506
-513
22
-77
-118
-216
-215
-215
-453
-452
-244
-257
-256
-340
-110
-104
-103
-207
-548
-547
-697
-695
-694
-693
-692
-691
-642
-641
-640
-639
-592
-307
-206
-206
-204
-203
-425
-424
-432
-52
-41
-29
-182...

result:

wrong answer 1st numbers differ - expected: '2', found: '-485'