QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#65896 | #3042. Hilbert's Hotel | gyh20 | WA | 5ms | 7760kb | C++14 | 2.2kb | 2022-12-04 10:59:49 | 2022-12-04 10:59:51 |
Judging History
answer
#include<bits/stdc++.h>
#define re register
using namespace std;
inline int read(){
re int t=0;re char v=getchar();
while(v<'0')v=getchar();
while(v>='0')t=(t<<3)+(t<<1)+v-48,v=getchar();
return t;
}
const int M=1e9+7;
inline void add(re int &x,re int y){(x+=y)>=M?x-=M:x;}
inline int Mod(re int x){return x>=M?x-M:x;}
inline int ksm(re int x,re int y){
re int s=1;
while(y){
if(y&1)s=1ll*s*x%M;
x=1ll*x*x%M,y>>=1;
}
return s;
}
int n,tg1[1200002],tg2[1200002],lst[1200002],G,X,ID[300002];
long long sum[1200002];
inline void build(re int p,re int l,re int r){
tg1[p]=1,tg2[p]=0;
if(l==r)return;
re int mid=l+r>>1;
build(p<<1,l,mid),build(p<<1|1,mid+1,r);
}
inline void Mul(re int p,re int x,re int y){
tg1[p]=1ll*tg1[p]*x%M,tg2[p]=1ll*tg2[p]*x%M;
add(tg2[p],y);
}
inline void pd(re int p){
if(tg1[p]!=1||tg2[p])Mul(p<<1,tg1[p],tg2[p]),Mul(p<<1|1,tg1[p],tg2[p]),tg1[p]=1,tg2[p]=0;
}
inline void mul(re int p,re int l,re int r,re int x,re int y,re int z1,re int z2){
if(l>=x&&r<=y){
if(z1)add(tg1[p],tg1[p]),add(tg2[p],tg2[p]);
add(tg2[p],z2);return;
}re int mid=l+r>>1;pd(p);
if(x<=mid)mul(p<<1,l,mid,x,y,z1,z2);
if(y>mid)mul(p<<1|1,mid+1,r,x,y,z1,z2);
}
inline void ask(re int p,re int l,re int r,re int x){
if(l==r){
X=1ll*X*tg1[p]%M,add(X,tg2[p]);
return;
}re int mid=l+r>>1;pd(p);
if(x<=mid)ask(p<<1,l,mid,x);
else ask(p<<1|1,mid+1,r,x);
}
int main(){
n=read(),build(1,0,n);
for(re int i=1;i<=n;++i){
re int o=read();sum[i]=sum[i-1],lst[i]=lst[i-1];
if(o==1){
int x=read();++G,ID[i]=G;
if(x==0)lst[i]=i,mul(1,0,n,0,G,1,0),mul(1,0,n,G,G,0,1);
else sum[i]=sum[i-1]+x,mul(1,0,n,0,G-1,0,x);
}
else if(o==2){
re int x=read();X=read()-1;
ask(1,0,n,x),printf("%d\n",X);
}
else{
re int v=read(),pos=i;
while(1){
if(!pos){
puts("0");
break;
}
re int x=lst[pos];
if(sum[pos]-sum[x]>=v){
re int l=x,r=pos-1,oo=x;
while(l<=r){
re int mid=l+r>>1;
if(sum[pos]-sum[mid]>=v)oo=mid,l=mid+1;
else r=mid-1;
}
printf("%d\n",ID[oo+1]);
break;
}
else{
v-=(sum[pos]-sum[x]);
if(v&1){
printf("%d\n",ID[x]);break;
}v>>=1;
pos=x-1;
}
}
}
}
}
详细
Test #1:
score: 100
Accepted
time: 3ms
memory: 7580kb
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: 0
Accepted
time: 3ms
memory: 7500kb
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 0 7 0 0 2 0 0 3 2
result:
ok 12 lines
Test #3:
score: -100
Wrong Answer
time: 5ms
memory: 7760kb
input:
11 2 0 8 3 9 1 5 2 0 10 2 0 5 1 0 3 9 2 2 7 2 2 3 3 0 1 0
output:
7 0 14 9 2 13 5 0
result:
wrong answer 8th lines differ - expected: '1', found: '0'