QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#56119 | #3042. Hilbert's Hotel | tricyzhkx | WA | 2ms | 3844kb | C++14 | 1.6kb | 2022-10-17 11:19:39 | 2022-10-17 11:19:41 |
Judging History
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()->first]=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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 3844kb
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 0 9 4 4
result:
ok 6 lines
Test #2:
score: -100
Wrong Answer
time: 2ms
memory: 3740kb
input:
16 2 0 8 2 0 4 3 7 3 5 2 0 8 3 6 1 0 3 8 2 0 2 1 2 2 2 1 2 2 1 1 6 1 1 3 4 2 3 2
output:
7 3 0 3 7 0 0 2 0 0 0 2
result:
wrong answer 4th lines differ - expected: '0', found: '3'