QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#56120#3042. Hilbert's HoteltricyzhkxWA 2ms3724kbC++141.6kb2022-10-17 11:23:172022-10-17 11:23:20

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-10-17 11:23:20]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:3724kb
  • [2022-10-17 11:23:17]
  • 提交

answer

# include <bits/stdc++.h>
using namespace std;
const int mod=998244353;
typedef long long ll;
int k[300010],b[300010],ans[300010];
set<pair<ll,int>> st;
struct Query{int op,x,y;}que[300010];
int add(int a,int b){return (a+=b)>=mod?a-mod:a;}
ll power(ll a,int b)
{
	ll ans=1;
	for(;b;b>>=1,a=a*a%mod)
		if(b&1) ans=ans*a%mod;
	return ans;
}
int main()
{
	int q,n=1,deltak=1,deltab=0;
	cin>>q;
	k[0]=1;
	for(int i=1;i<=q;i++)
	{
		scanf("%d",&que[i].op);
		if(que[i].op==1)
		{
			scanf("%d",&que[i].x);
			if(que[i].x)
			{
				deltab=add(deltab,que[i].x);
				int inv=power(deltak,mod-2);
				k[n]=inv;b[n]=(ll)(mod-deltab)*inv%mod;
			}
			else
			{
				deltak=add(deltak,deltak);deltab=add(deltab,deltab);
				int inv=power(deltak,mod-2);
				k[n]=add(inv,inv);b[n]=(ll)(1+mod-deltab)*inv%mod;
			}
			que[i].y=n++;
		}
		else if(que[i].op==2)
		{
			int id,x;
			scanf("%d%d",&id,&x);x--;
			ans[i]=(((ll)k[id]*x+b[id])%mod*deltak+deltab)%mod;
		}
		else scanf("%d",&que[i].x);
	}
	ll delta=0;
	for(int i=q;i>=1;i--)
		if(que[i].op==3) st.emplace(que[i].x+delta,i);
		else if(que[i].op==1)
		{
			if(que[i].x)
			{
				while(!st.empty() && st.begin()->first+delta<que[i].x)
					ans[st.begin()->second]=que[i].y,st.erase(st.begin());
				delta-=que[i].x;
			}
			else
			{
				set<pair<ll,int>> tst;
				for(auto p:st)
					if((p.first+delta)&1) ans[p.second]=que[i].y;
					else tst.emplace((p.first+delta)/2,p.second);
				swap(st,tst);delta=0;
			}
		}
	for(int i=1;i<=q;i++)
		if(que[i].op==2 || que[i].op==3)
			printf("%d\n",ans[i]);
	return 0;
}

详细

Test #1:

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

input:

10
3 0
1 3
2 1 2
1 0
3 10
2 2 5
1 5
1 0
3 5
2 3 3

output:

0
1
1
9
4
4

result:

wrong answer 3rd lines differ - expected: '0', found: '1'