QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#298280#4429. Gebyte's GrindPhantomThreshold#WA 5279ms203116kbC++202.6kb2024-01-05 22:20:382024-01-05 22:20:39

Judging History

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

  • [2024-01-05 22:20:39]
  • 评测
  • 测评结果:WA
  • 用时:5279ms
  • 内存:203116kb
  • [2024-01-05 22:20:38]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const ll lim=4.1e18;
// h  <= lo -> 0
// lo <  h  <=hi -> c
// hi <  h  -> h+d
struct info
{
	ll lo,hi,c,d;
	info(){lo=hi=c=d=0ll;}
	info(char ch,ll x)
	{
		if(ch=='B')
		{
			lo=hi=x;
			c=0;
			d=-x;
		}
		else if(ch=='K')
		{
			lo=x-1;
			hi=lim;
			c=0;
			d=x;
		}
		else
		{
			lo=0;
			hi=x;
			c=x;
			d=0;
		}
	}
	ll eval(ll x)const
	{
		if(x<=lo)return -1;
		if(x<=hi)return c;
		return x+d;
	}
	info operator+(const info &t)const
	{
		info ret;
		ret.lo=lo;
		if(c<=t.lo)ret.lo=hi;
		ll bound=t.lo-d;
		if(bound>hi)ret.lo=bound;
		
		ret.c=t.eval(c);
		if(t.c)ret.c=t.c;
		bound=t.hi-d;
		if(bound>hi)ret.hi=bound;
		else ret.hi=hi;
		
		ret.d=d+t.d;
		
		return ret;
	}
};
const int maxn=4555555;
info w[maxn];
int lson[maxn],rson[maxn];
int ind,root;
char ty[maxn];
ll x[maxn];
void upd(int cur)
{
	cur[w]=cur[lson][w]+cur[rson][w];
}
int build(int l,int r)
{
	int ret=++ind;
	if(l!=r)
	{
		int mid=(l+r)/2;
		ret[lson]=build(l,mid);
		ret[rson]=build(mid+1,r);
		upd(ret);
	}
	else
	{
		ret[w]=info(ty[l],x[l]);
	}
	return ret;
}
void change(int cur,int l,int r,int pos)
{
	if(l==r)
	{
		cur[w]=info(ty[pos],x[pos]);
		return;
	}
	int mid=(l+r)/2;
	if(pos<=mid)change(cur[lson],l,mid,pos);
	else change(cur[rson],mid+1,r,pos);
	upd(cur);
}
pair<int,ll> query(int cur,int l,int r,int pos,ll h)
{
	if(pos>r)return make_pair(pos,h);
	if(pos==l and cur[w].eval(h)!=-1)return make_pair(r+1,cur[w].eval(h));
	if(l==r)return make_pair(l,-1);
	int mid=(l+r)/2;
	if(pos<=mid)
	{
		auto res=query(cur[lson],l,mid,pos,h);
		if(res.second==-1)return res;
		else return query(cur[rson],mid+1,r,mid+1,res.second);
	}
	return query(cur[rson],mid+1,r,pos,h);
}
void printall(int cur,int l,int r)
{
	cerr<<cur<<' '<<l<<' '<<r<<' '<<cur[w].lo<<' '<<cur[w].hi<<' '<<cur[w].c<<' '<<cur[w].d<<endl;
	if(l!=r)
	{
		int mid=(l+r)/2;
		printall(cur[lson],l,mid);
		printall(cur[rson],mid+1,r);
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	int T;
	cin>>T;
	while(T--)
	{
		int n,q;
		ll H;
		cin>>n>>q>>H;
		for(int i=1;i<=n;i++)
		{
			cin>>ty[i]>>x[i];
		}
		ty[n+1]='B';
		x[n+1]=lim;
		ind=0;
		root=build(1,n+1);
		while(q--)
		{
//			printall(root,1,n+1);
			char op;
			cin>>op;
			if(op=='D')
			{
				int pos;
				cin>>pos;
				int res=query(root,1,n+1,pos,H).first;
				if(res==pos)cout<<-1<<"\n";
				else cout<<res-1<<"\n";
			}
			else
			{
				int pos;
				cin>>pos;
				cin>>ty[pos]>>x[pos];
				change(root,1,n+1,pos);
			}
		}
	}
	return 0;
}

詳細信息

Test #1:

score: 0
Wrong Answer
time: 5279ms
memory: 203116kb

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:

830886
237551
1006759
1911618
1482435
995020
911266
594968
1956406
163024
1222474
213379
1606414
541216
578056
1277464
1641650
645516
900256
1009146
1720986
1905355
765240
1766529
991879
134357
140608
422999
378431
188153
555268
1019521
12846
1007200
623101
1143461
887096
856018
173817
1185152
16893...

result:

wrong answer 1st lines differ - expected: '833302', found: '830886'