QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#251176#3042. Hilbert's HotelS00021WA 1ms3580kbC++141.9kb2023-11-14 12:30:342023-11-14 12:30:34

Judging History

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

  • [2023-11-14 12:30:34]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3580kb
  • [2023-11-14 12:30:34]
  • 提交

answer

#include<bits/stdc++.h>
#define N 200005
#define int long long
#define pb push_back
#define fi first
#define se second
#define pii pair<int,int>
#define MP make_pair
#define M 1000000007
#define ls (rt<<1)
#define rs (rt<<1|1)
using namespace std;
int Q; multiset<int>st;
struct SGT{
	int tag1[N<<3],tag2[N<<3];
	void build(int rt,int l,int r){
		tag1[rt]=1,tag2[rt]=0; if(l==r) return;
		int md=(l+r)>>1; build(ls,l,md),build(rs,md+1,r);	
	}void upd(int rt,int d0,int d1){
		(tag1[rt]*=d0)%=M,(tag2[rt]*=d0)%=M,(tag2[rt]+=d1)%=M;
	}void pd(int rt){
		upd(ls,tag1[rt],tag2[rt]);
		upd(rs,tag1[rt],tag2[rt]); tag1[rt]=1,tag2[rt]=0;	
	}void modf(int rt,int l,int r,int L,int R,int d0,int d1){ if(L>R) return;
		if(L<=l&&r<=R){upd(rt,d0,d1); return;} int md=(l+r)>>1; pd(rt);
		if(L<=md) modf(ls,l,md,L,R,d0,d1); if(R>md) modf(rs,md+1,r,L,R,d0,d1);
	}int ask(int rt,int l,int r,int x,int t){
		if(l==r) return (t*tag1[rt]%M+tag2[rt])%M; int md=(l+r)>>1; pd(rt);
		if(x<=md) return ask(ls,l,md,x,t); else return ask(rs,md+1,r,x,t);}
}T; int n,l0[N],l1[N],sum[N],cn,id[N];
signed main(){
	scanf("%lld",&n),T.build(1,1,n);
	for(int i=1;i<=n;i++){
		int op,x,k; scanf("%lld",&op);
		l0[i]=l0[i-1],l1[i]=l1[i-1],sum[i]=sum[i-1]; 	
		if(op==1){ id[i]=(++cn);
			scanf("%lld",&k); if(k){
				T.modf(1,1,n,1,cn-1,1,k);
				T.modf(1,1,n,cn,cn,1,0),l1[i]=i;
			}else{
				T.modf(1,1,n,1,cn-1,2,0);
				T.modf(1,1,n,cn,cn,2,1),l0[i]=i; } sum[i]+=k;
		}if(op==2) scanf("%lld%lld",&x,&k),printf("%lld\n",T.ask(1,1,n,x,k-1));
		if(op==3){ scanf("%lld",&x);
			int po=i; while(1){
				if(po<=0){puts("0"); break;}
				if(x==0){printf("%lld\n",id[l1[po]]); break;}
				if(sum[po]-sum[l0[po]]>x){
					int t=lower_bound(sum+l0[po]+1,sum+po+1,sum[po]-x)-sum-1;
					printf("%lld\n",id[t]); break;
				}else{ x-=(sum[po]-sum[l0[po]]);
					if(x&1){printf("%lld\n",id[l0[po]]); break;} x>>=1,po=l0[po]-1;
				}}
		}
	}return 0;
}

详细

Test #1:

score: 100
Accepted
time: 1ms
memory: 3532kb

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: 1ms
memory: 3580kb

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
3
0
0
0
2

result:

wrong answer 8th lines differ - expected: '2', found: '3'