QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#202400#4429. Gebyte's GrindForever_Young#TL 0ms0kbC++232.5kb2023-10-06 00:31:232023-10-06 00:31:24

Judging History

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

  • [2023-10-06 00:31:24]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2023-10-06 00:31:23]
  • 提交

answer

#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 mp make_pair
#define pb push_back
#define N 2100000
const long long inf=2147483647ll*1000000000ll;
int n,q; long long h;
struct node
{
	//if (0<=h<=x),f(h)=0
	//if (x<h<=y), f(h)=p
	//if (y<h), f(h)=h+q
	long long x,y,p,q;
	void print()
	{
		printf("x=%lld y=%lld p=%lld q=%lld\n",x,y,p,q);
	}
	void read()
	{
		char s[2]; long long w; 
		scanf("%s%lld",s,&w);
		//puts(s); cout<<w<<endl;
		if (s[0]=='B')
		{
			x=w; y=w; p=w; q=-w;
		}
		if (s[0]=='K')
		{
			x=w-1; y=inf; p=w; q=inf;
		}
		if (s[0]=='C')
		{
			x=0; y=w; p=w; q=0;
		}
	}
	long long eval(long long h)
	{
		if (h<=x)return 0;
		if (h<=y)return p;
		return h+q;
	}
	friend node operator +(node x,node y)
	{
		//y.eval(x.eval())
		//if (0<=h<=x),f(h)=0
		//if (x<h<=y), f(h)=p
		//if (y<h), f(h)=h+q	
		node ret;
		ret.x=x.x;
		if (y.eval(x.p)==0)ret.x=x.y;
		//h+x.q>y.x
		else ret.x=max(ret.x,y.x-x.q);
		
		if (y.eval(x.p)==y.p)ret.y=x.y;
		//h+x.q<=y.y
		else ret.y=max(ret.y,y.y-x.q);
		ret.p=y.p;

		ret.q=x.q+y.q;
		return ret;
	}
}st[4*N];
void build(int t,int l,int r)
{
	if (l==r)
	{
		st[t].read();
		//cout<<t<<" "; st[t].print();
		return;
	}
	int mid=(l+r)/2;
	build(2*t,l,mid);
	build(2*t+1,mid+1,r);
	st[t]=st[2*t]+st[2*t+1];
}
void modify(int t,int l,int r,int k)
{
	if (l==r)
	{
		st[t].read();
		return;
	}
	int mid=(l+r)/2;
	if (k<=mid)modify(2*t,l,mid,k);
	else modify(2*t+1,mid+1,r,k);
	st[t]=st[2*t]+st[2*t+1];
}
node get(int t,int l,int r,int a,int b)
{
	if (a<=l && r<=b)return st[t];
	int mid=(l+r)/2;
	if (b<=mid)return get(2*t,l,mid,a,b);
	if (a>mid)return get(2*t+1,mid+1,r,a,b);
	auto ret1=get(2*t,l,mid,a,b);
	auto ret2=get(2*t+1,mid+1,r,a,b);
	return ret1+ret2;
}
int main()
{
	//freopen("1.in","r",stdin);
	int T;
	cin>>T;
	while (T--)
	{
		scanf("%d%d%lld",&n,&q,&h);
		build(1,1,n);

		auto ret1=get(1,1,n,1,1);
		auto ret2=get(1,1,n,2,2);
		auto ret3=ret1+ret2;
		
		//get(1,1,n,1,2).print();
		//get(1,1,n,1,3).print();
		while (q--)
		{
			char s[2]; int x;
			scanf("%s%d",s,&x);
			if (s[0]=='Z') modify(1,1,n,x);
			else 
			{
				int l=x,r=n;
				auto t=get(1,1,n,x,l);
				if (t.eval(h)==0){ puts("-1"); continue; }
				while (l<r)
				{
					int mid=(l+r)/2 + 1;
					auto t=get(1,1,n,x,mid);
					if (t.eval(h)==0)r=mid-1;
					else l=mid;
				}
				printf("%d\n",l);
			}
		}
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Time Limit Exceeded

input:

1
2000000 4000000 1000000000000
B 2982992025
B 1226542907
B 2299259203
B 1223702056
B 1407121251
B 340783317
B 1259091208
B 2101980047
B 2611543443
B 2010658889
B 4233714406
B 3112120167
B 2311876255
B 2789960428
B 3008572010
B 1
B 2464951378
B 1364240867
B 2829584762
B 2511437438
B 692948679
B 1113...

output:

1377016
238284
1011719
2000000
1481219
995118
937500
594852
2000000
179690
2000000
1187991
1604871
619770
577662
1457982
1642581
1375004
899995
2000000
1720728
1904470
763971
1766440
992188
437500
140194
1187991
378028
1130864
1390625
1018556
11385
1499549
622926
2000000
1187991
855627
629930
200000...

result: