QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#261349#3042. Hilbert's HotellmeowdnWA 1ms9812kbC++142.7kb2023-11-22 20:29:312023-11-22 20:29:31

Judging History

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

  • [2023-11-22 20:29:31]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:9812kb
  • [2023-11-22 20:29:31]
  • 提交

answer

//vanitas vanitatum et omnia vanitas
#include<bits/stdc++.h>
#define fi first
#define se second
#define eb emplace_back
#define mp make_pair
using namespace std;
typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef __int128 i128;
template<typename T,typename U>
T ceil(T x, U y) {return (x>0?(x+y-1)/y:x/y);}
template<typename T,typename U>
T floor(T x, U y) {return (x>0?x/y:(x-y+1)/y);}
template<class T,class S>
bool chmax(T &a,const S b) {return (a<b?a=b,1:0);}
template<class T,class S>
bool chmin(T &a,const S b) {return (a>b?a=b,1:0);}
int popcnt(int x) {return __builtin_popcount(x);}
int popcnt(ll x)  {return __builtin_popcountll(x);}
int topbit(int x) {return (x==0?-1:31-__builtin_clz(x));}
int topbit(ll x)  {return (x==0?-1:63-__builtin_clzll(x));}
int lowbit(int x) {return (x==0?-1:__builtin_ctz(x));}
int lowbit(ll x)  {return (x==0?-1:__builtin_ctzll(x));}

#define int long long
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vp;
typedef tuple<int,int,int> tiii;
int read() {
  int x=0,w=1; char c=getchar(); 
  while(!isdigit(c)) {if(c=='-') w=-1; c=getchar();}
  while(isdigit(c)) {x=x*10+(c-'0'); c=getchar();}
  return x*w;
}

const int N=3e5+5,mod=1e9+7;
int n,s[N],lst[N],m,cur,mul,add,pd,p[N],a[N],tk[N],tq;

int ksm(int x,int y,int r=1) {
  for(;y;y>>=1,x=x*x%mod) if(y&1) r=r*x%mod;
  return r;
}

signed main() {
  n=read(); mul=1;
  rep(i,1,n) {
    int opt=read();
    if(opt==1) {
      m++; lst[m]=cur; int k=read(); s[m]=s[m-1]+(tk[m]=k);
      if(!k) {
        ++pd, cur=m, mul=mul*2%mod, add=add*2%mod;
        a[m]=(mod+1-add)*ksm(mul,mod-2)%mod;
        p[m]=1-pd;
      } else {
        add+=k;
        a[m]=(mod-add)*ksm(mul,mod-2)%mod;
        p[m]=-pd;
      }
    } else if(opt==2) {
      int g=read(), x=read(); ++tq; 
      int sa=(a[g]*mul+add)%mod, sp=p[g]+pd;
      printf("%lld\n",(sa+(x-1)*ksm(2,sp))%mod);
    } else {
      int ans=0, k=read(); ++tq;
      for(int x=m;x;) {
        if(!tk[x]) {
          if(k&1) {ans=x; break;}
          else k/=2;
          x--;
        } else {
          int ss=s[x]-s[lst[x]];
          if(k>ss) k-=ss;
          else {
            int l=lst[x]+1, r=x;
            while(l<=r) {
              int mid=l+r>>1;
              if(s[x]-s[mid-1]>=k) ans=mid, l=mid+1;
              else r=mid-1; 
            }
            if(tq==87) cout<<ans<<" "<<lst[ans]<<" "<<x<<" "<<k<<" "<<endl;
            break;
          }
          x=lst[x];
        }
      }
      printf("%lld\n",ans);
    }
  }
  return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 9768kb

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

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: 0
Accepted
time: 0ms
memory: 5660kb

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
1

result:

ok 8 lines

Test #4:

score: 0
Accepted
time: 0ms
memory: 9744kb

input:

20
1 0
3 1
2 0 4
2 0 7
1 0
3 8
1 0
2 3 7
3 4
2 3 4
3 1
3 8
1 0
2 4 5
1 9
3 2
3 3
3 2
1 7
1 0

output:

1
6
12
0
13
1
7
3
0
9
5
5
5

result:

ok 13 lines

Test #5:

score: 0
Accepted
time: 1ms
memory: 9696kb

input:

11
1 0
2 0 4
2 0 9
1 1
1 9
1 4
2 0 8
2 4 3
2 1 3
1 2
2 3 6

output:

6
16
28
2
19
11

result:

ok 6 lines

Test #6:

score: 0
Accepted
time: 0ms
memory: 5656kb

input:

20
2 0 9
2 0 9
1 0
3 6
1 9
2 0 10
2 1 10
3 7
3 5
1 0
2 1 1
2 1 5
1 7
2 3 3
2 2 2
1 8
1 4
1 0
1 0
2 5 2

output:

8
8
0
27
28
2
2
20
36
12
9
20

result:

ok 12 lines

Test #7:

score: 0
Accepted
time: 1ms
memory: 5628kb

input:

15
2 0 4
3 4
1 0
2 1 7
3 10
1 0
1 0
2 1 1
2 1 2
2 2 5
1 0
2 2 10
1 0
2 1 6
1 0

output:

3
0
13
0
4
12
18
76
176

result:

ok 9 lines

Test #8:

score: 0
Accepted
time: 1ms
memory: 9812kb

input:

13
1 2
1 2
3 3
2 0 6
3 8
2 0 3
2 2 2
3 8
2 1 2
1 4
1 0
1 4
1 0

output:

1
9
0
6
1
0
3

result:

ok 7 lines

Test #9:

score: 0
Accepted
time: 1ms
memory: 5624kb

input:

11
3 4
2 0 9
3 9
1 0
3 5
1 0
2 0 8
2 0 9
2 2 3
3 6
2 0 9

output:

0
8
0
1
28
32
5
1
32

result:

ok 9 lines

Test #10:

score: 0
Accepted
time: 1ms
memory: 9764kb

input:

13
3 6
1 0
1 7
3 4
3 1
2 0 8
1 9
1 9
1 5
3 10
3 10
2 4 6
2 3 9

output:

0
2
2
21
4
4
10
22

result:

ok 8 lines

Test #11:

score: 0
Accepted
time: 0ms
memory: 5608kb

input:

17
3 10
3 0
2 0 7
3 3
2 0 9
1 0
2 0 7
2 0 10
2 0 6
2 1 4
1 0
1 0
3 7
2 1 2
3 3
1 9
3 5

output:

0
0
6
0
8
12
18
10
7
3
12
3
4

result:

ok 13 lines

Test #12:

score: 0
Accepted
time: 1ms
memory: 9744kb

input:

18
1 0
3 3
1 4
2 2 3
2 2 4
2 2 2
2 0 10
3 3
3 1
3 9
1 0
1 1
1 9
3 4
1 9
2 4 1
3 0
3 6

output:

1
2
3
1
22
2
2
1
5
18
6
6

result:

ok 12 lines

Test #13:

score: -100
Wrong Answer
time: 1ms
memory: 5668kb

input:

990
3 613
3 983
3 529
2 0 4
2 0 8
3 352
3 136
2 0 1
2 0 6
3 144
3 936
1 7
3 102
2 0 3
2 0 4
1 0
2 0 10
3 381
3 200
2 2 4
1 6
3 251
1 9
2 4 5
1 3
2 3 6
2 1 4
3 65
2 2 6
2 2 4
3 934
2 3 6
2 3 3
2 2 10
2 1 2
2 5 3
3 618
3 996
3 335
3 268
2 3 6
1 5
1 5
2 4 7
1 6
1 5
3 347
3 646
1 3
1 6
2 8 1
3 845
1 7
3...

output:

0
0
0
3
7
0
0
0
5
0
0
0
9
10
32
2
0
7
2
4
17
24
2
29
25
0
17
14
37
20
2
0
0
2
0
17
19
0
2
14
2
2
2
17
3
109
4
195
30
28
54
24
24
24
8
0
3
368
24
17
24
1561
39
1369
24
28
875
103
28
219
20
74
234
28
26
28
28
379
742
28
56
26
1064
28
28
28
36 28 40 30 
36
1288
426
18
28
1642
2
117
1049
819
44
19
26
44...

result:

wrong answer 87th lines differ - expected: '35', found: '36 28 40 30 '