QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#65897 | #3042. Hilbert's Hotel | gyh20 | TL | 0ms | 0kb | C++14 | 2.2kb | 2022-12-04 11:01:24 | 2022-12-04 11:01:26 |
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: 0
Time Limit Exceeded
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