QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#875214#9791. Intrusive Donkeysuzukaze_Aobayama (Takehiro Suda, Taishi Amagai, Yoshinori Furuto)#WA 8ms8752kbC++204.4kb2025-01-29 13:08:582025-01-29 13:08:59

Judging History

This is the latest submission verdict.

  • [2025-01-29 13:08:59]
  • Judged
  • Verdict: WA
  • Time: 8ms
  • Memory: 8752kb
  • [2025-01-29 13:08:58]
  • Submitted

answer

#include<bits/stdc++.h>
using namespace std;

using ll = long long;
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define rep2(i, l, r) for(ll i = (l); i < (r); ++i)

using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;

#define all(A) A.begin(), A.end()
#define elif else if
using pii = pair<ll, ll>;

bool chmin(auto &a, auto b) {return a > b ? a = b, 1 : 0;}
bool chmax(auto &a, auto b) {return a < b ? a = b, 1 : 0;}

struct IOS {
  IOS() {
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
} iosetup;

template<class T>
void print(vector<T> a) {
  for(auto x : a) cout << x << ' ';
  cout << endl;
}

void print(auto x) {cout << x << endl;}

template<class Head, class... Tail>
void print(Head &&head, Tail &&...tail) {
  cout << head << ' ';
  print(forward<Tail>(tail)...);
}

template<class S, S(*op)(S, S), S(*e)(), class F, S(*mp)(F, S), F(*cmp)(F, F), F(*id)()>
struct lazysegtree {
  int N, sz, log;
  vector<S> d;
  vector<F> lz;

  lazysegtree() = default;
  lazysegtree(int n) : lazysegtree(vector<S>(n, e())) {};
  lazysegtree(vector<S> v) {
    N = v.size();
    sz = 1, log = 0;
    while(sz < N) sz *= 2, log++;
    d.assign(2*sz, e());
    lz.assign(2*sz, id());
    rep(i, N) d[i+sz] = v[i];
    for(int i = sz-1; i > 0; --i) d[i] = op(d[2*i], d[2*i+1]);
  }

  void update(int k) {d[k] = op(d[2*k], d[2*k+1]);}
  void all_apply(int k, F f) {
    d[k] = mp(f, d[k]);
    if(k < sz) lz[k] = cmp(f, lz[k]);
  }
  void push(int k) {
    all_apply(2*k, lz[k]);
    all_apply(2*k+1, lz[k]);
    lz[k] = id();
  }
  void PUSH(int k) {
    for(int i = log; i > 0; --i) push(k >> i);
  }

  bool shift(int x, int i) {return ((x>>i)<<i)!= x;}

  S prod(int l, int r) {
    if(l == r) return e();
    l += sz, r += sz;
    for(int i = log; i > 0; i--) {
      if(shift(l, i)) push(l>>i);
      if(shift(r, i)) push((r-1)>>i);
    }
    S sml = e(), smr = e();
    while(l < r) {
      if(l&1) sml = op(sml, d[l++]);
      if(r&1) smr = op(d[--r], smr);
      l >>= 1, r >>= 1;
    }
    return op(sml, smr);
  }

  void apply(int l, int r, F f) {
    if(l==r) return;
    l += sz, r += sz;
    for(int i = log; i > 0; --i) {
      if(shift(l, i)) push(l>>i);
      if(shift(r, i)) push((r-1)>>i);
    }
    int ml = l, mr = r;
    while(l < r) {
      if(l&1) all_apply(l++, f);
      if(r&1) all_apply(--r, f);
      l >>= 1, r >>= 1;
    }
    l = ml, r = mr;
    rep2(i, 1, log+1) {
      if(shift(l, i)) update(l >> i);
      if(shift(r, i)) update((r-1)>>i);
    }
  }

  void set(int p, S x) {
    p += sz;
    PUSH(p);
    d[p] = x;
    rep2(i, 1, log+1) update(p >> i);
  }

  template<class C>
  int max_right(int l, C check) {
    assert(check(e()));
    if(l == N) return N;
    l += sz;
    PUSH(l);
    S sm = e();
    do {
      while(~l & 1) l >>= 1;
      if(!check(op(sm, d[l]))) {
        while(l < sz) {
          push(l);
          l <<= 1;
          if(check(op(sm, d[l]))) {
            sm = op(sm, d[l]);
            l++;
          }
        }
        return l - sz;
      }
      sm = op(sm, d[l]);
      l++;
    } while((l & -l) != l);
    return N;
  }

};


ll op(ll a,ll b){return a+b;}
ll e(){return 0;}
ll mapping(ll f,ll x){return f*x;}
ll cmp(ll f,ll g){return f*g;}
ll id(){return 1;}

ll target;
bool f(ll x){return x<=target;}

int main(){
  int n,q;
  cin>>n>>q;
  string s;
  cin>>s;
  vll init(n,1);
  lazysegtree<ll,op,e,ll,mapping,cmp,id>seg(init);

  auto get=[&](ll x)->int{
    target=x;
    return seg.max_right(0,f);
  };

  rep(i,q){
    int t;
    cin>>t;
    if(t==1){
      ll l,r;
      cin>>l>>r;
      l--;
      // r--;
      int idxl=get(l);
      int idxr=get(r);
      if(idxl==idxr){
        ll len=seg.prod(idxl,idxl+1);
        seg.set(idxl,len+(r-l));
      }
      else{
        int left1=seg.prod(0,idxl);
        ll len1=seg.prod(idxl,idxl+1);

        int left2=seg.prod(0,idxr);
        ll len2=-1;
        if(idxr!=n)len2=seg.prod(idxr,idxr+1);
        
        {
          seg.set(idxl,2*len1-(l-left1));
        }

        {
          seg.apply(idxl+1,idxr,2);
        }
        {
          if(len2!=-1)seg.set(idxr,len2+(r-left2));
        }
      }
      // rep(i,n)cout<<seg.prod(i,i+1)<<" ";
      // cout<<endl;
    }
    else{
      ll idx;
      cin>>idx;
      idx--;
      cout<<s[get(idx)]<<"\n";
    }
  }
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

4 7
abac
2 2
2 3
1 2 3
2 3
2 4
2 5
2 6

output:

b
a
b
a
a
c

result:

ok 6 lines

Test #2:

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

input:

5 4
shrek
1 1 2
2 7
1 1 7
2 7

output:

k
h

result:

ok 2 lines

Test #3:

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

input:

4 7
abac
2 2
2 3
1 2 3
2 3
2 4
2 5
2 6

output:

b
a
b
a
a
c

result:

ok 6 lines

Test #4:

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

input:

5 4
shrek
1 1 2
2 7
1 1 7
2 7

output:

k
h

result:

ok 2 lines

Test #5:

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

input:

3 55
vfe
1 2 3
1 2 2
1 3 5
2 4
1 1 2
2 9
2 7
2 5
1 10 10
1 1 1
2 9
1 8 12
2 8
1 7 10
2 1
1 5 6
1 1 4
1 20 24
1 14 32
1 19 38
2 48
1 56 64
2 58
2 19
1 64 72
1 36 86
2 11
1 117 124
2 38
2 108
2 85
1 112 118
2 153
2 40
2 114
2 80
1 11 18
2 27
2 73
1 159 162
2 84
1 130 164
2 163
2 65
1 150 156
1 101 109...

output:

f
e
f
f
f
f
v
f
e
f
f
f
e
e
e
f
e
e
f
e
e
e
f
e
f
e
v

result:

ok 27 lines

Test #6:

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

input:

60 51
ranhfkbjhkxckkcbhgsspsjcbjgpwcfvmqqlvlfualndmqqsihsfdyqviowu
2 53
2 37
2 33
2 60
1 1 32
2 44
1 87 92
1 7 77
1 56 86
2 17
1 128 184
1 26 159
2 323
2 55
1 24 316
1 435 652
2 316
2 444
1 819 868
2 27
2 912
2 313
1 555 576
1 510 942
1 1118 1269
2 365
2 84
1 595 650
2 1468
2 258
1 1557 1607
2 938
1...

output:

d
v
m
u
s
k
q
c
p
j
j
n
p
j
c
u
s
c
b
p
u
p
c
n
p
g

result:

ok 26 lines

Test #7:

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

input:

32 58
shdnavermvazdgaqioiqictppwhtoplw
1 28 32
2 17
2 12
1 23 28
2 10
1 16 43
1 25 42
2 85
1 21 46
1 42 73
1 114 144
2 42
2 127
2 111
2 42
2 113
2 38
1 164 174
1 104 180
2 134
2 247
1 122 234
2 34
1 324 354
2 265
1 365 383
2 208
2 405
2 409
2 344
2 376
1 344 401
1 258 453
1 73 267
2 791
2 45
2 133
2...

output:

i
z
v
l
c
w
p
c
p
i
p
l
i
t
h
l
l
p
l
l
c
p
l
t
p
l
h
t
o
t
t
p

result:

ok 32 lines

Test #8:

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

input:

78 38
gychxprltqtnidbvtrhunqhtrvknfjtnsodvsqrfczassyiofcdmuospwrcmfloplsojdqjexfszhl
2 62
2 48
2 60
1 31 77
2 46
2 46
1 64 110
1 54 99
2 109
2 41
1 86 196
2 225
2 193
1 63 302
1 490 554
2 264
2 288
1 326 406
1 485 502
1 104 310
2 141
2 645
1 699 800
2 627
1 153 974
2 1811
1 1341 1579
1 321 483
1 206...

output:

l
o
m
q
q
d
v
r
s
u
o
f
r
r
j
c
o
l
o

result:

ok 19 lines

Test #9:

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

input:

100 100
ogaxzfpqrpanbhrhzbpfdkudvzgswxqsqjxiwbzuhzbzlnmsiudvoimiuiguuaipovaiimzqpckpzdjcgazssksjiwypmwtcvhcq
2 32
1 75 80
1 27 91
1 12 98
1 192 200
2 234
2 45
1 243 252
1 208 212
2 76
2 211
2 5
1 35 36
2 154
1 257 268
2 103
1 157 212
1 61 73
2 123
1 355 359
2 225
2 97
2 16
1 105 266
1 412 505
1 50 3...

output:

s
d
g
x
m
z
i
h
b
a
w
h
s
g
i
p
b
m
i
s
l
z
i
b
m
z
i
i
m
o
i
i
v
i
i
m
i
i
i
i
i
u
i
i
i
i
i
i
i
i

result:

ok 50 lines

Test #10:

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

input:

100 100
qmooxvmzsmwfjcyctyjicrarwqcbkzgswopuxwmxyfpfxpalqwhbmeskoopekwcgjekswfdipkmdzkpscfaagihgrpbqgnsfkuhs
1 35 65
2 31
2 65
2 11
2 124
1 119 123
1 16 27
2 7
2 34
2 71
2 28
1 76 78
2 106
1 132 138
2 97
1 74 131
2 22
1 214 214
2 200
1 24 189
1 328 334
2 334
1 256 388
2 14
1 266 302
1 213 431
1 212 ...

output:

g
w
w
g
m
w
a
r
c
o
j
r
p
c
j
j
h
i
g
c
e
c
e
g
w
g
w
j
g
w
w
j
j
j
k
g
j
j
w
j
w
g
j
w
e
c
g
w
c
g
c
c
c
j
j
g
g
j
c
g

result:

ok 60 lines

Test #11:

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

input:

100 100
uwnwvbymyokfijvijqnbzuhaallrgzyxsdpfaybnemreyfzqfmkhbxhoagexizrhbgnpymliarhaqgwfkxeblildhkqturevkcei
1 16 19
1 52 84
2 98
2 111
1 130 133
1 26 96
2 45
1 13 96
1 15 43
1 46 95
1 365 373
1 65 251
2 214
2 284
1 551 559
1 61 67
2 319
2 341
1 18 409
1 352 643
1 909 1244
1 887 1195
1 1757 1849
1 1...

output:

l
q
y
r
f
b
m
p
j
b
k
g
y
m
e
p
m
l
k
f
e
n
z
u
m
m
m
h
z
e
k
n
q
m
k
k
h
g
b
k
h
a
h
k
b
h
h

result:

ok 47 lines

Test #12:

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

input:

100 100
esqkyrydeoctndqmecklzayohrvnfxxqkiksvojrdmdscoosjgjaygenwliocibxhgswwiyvzukxcgltuduvauqdzkizhiydtxcj
1 8 42
1 27 133
1 95 126
1 89 151
2 216
1 34 242
2 260
2 59
1 545 545
1 155 540
2 458
1 752 825
1 540 610
1 878 1006
1 833 1168
1 139 1465
2 537
2 277
1 421 1725
2 1659
2 534
1 2307 3992
1 47...

output:

d
v
a
o
s
i
r
s
w
a
r
v
s
x
j
x
h
v
i
c
s
x
o
c
w
o
i
g
b
b
b
w
i
b
x
b
b
c
c
x
b
x
b
b
b
b

result:

ok 46 lines

Test #13:

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

input:

7 50
padvejq
2 5
2 3
1 7 7
2 1
1 6 7
1 10 10
1 10 11
1 12 13
1 10 11
1 6 15
1 6 22
2 6
1 30 35
1 3 5
1 26 52
1 79 80
1 25 49
2 56
2 18
2 44
2 66
1 40 66
1 76 87
2 145
1 39 74
1 180 180
2 81
1 106 147
1 129 134
1 133 161
1 178 178
1 17 90
1 138 180
2 195
1 195 362
1 383 436
2 229
1 91 265
2 681
1 644...

output:

e
d
p
j
q
q
q
q
q
q
q
q
q
q
q
q
q
q

result:

ok 18 lines

Test #14:

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

input:

55 3
ztlgpnoiedxyxqsaxzxoqffyozbkqprfjuutsdhpcbvrqjvcylaxmmk
2 37
1 47 50
2 17

output:

s
x

result:

ok 2 lines

Test #15:

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

input:

98 33
zhzoaivphsefnoimiurtiyaxzcbbhngpjmkbnqadfzeygwltpvrpnhndqlpohkdjvlvjfgrzascluodrqaokrrmozbxflwqplp
2 73
1 88 88
2 62
2 44
2 73
2 27
2 47
1 73 84
2 88
2 103
2 29
1 43 98
2 4
2 2
2 4
2 26
2 153
2 40
2 38
1 79 157
2 55
1 147 198
2 204
2 44
2 67
2 252
1 34 263
1 334 352
1 325 342
2 351
1 24 550
1 ...

output:

a
k
y
a
b
l
r
b
h
o
h
o
c
r
d
q
p
d
e
n
a
u
a

result:

ok 23 lines

Test #16:

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

input:

54 21
rjyiuclnplxpbqudhvycgxugpgwcxfelztyhtpnzjbcxjlqbjxmeav
2 51
2 16
1 39 50
2 60
1 4 39
1 51 94
1 53 109
1 42 123
2 193
1 152 243
1 247 282
1 269 412
1 302 346
2 28
2 460
1 526 559
2 129
2 611
2 253
1 531 630
1 422 671

output:

m
d
j
h
d
n
l
q
h

result:

ok 9 lines

Test #17:

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

input:

97 75
tzpklhpavuheakijolxdhfgajoozpbrwfzrnbfnlzxjnphqwkakyemnqfiucvhncxixiaowjfksvfnjgageqyblunzuhpriee
1 23 72
2 29
1 114 117
1 117 118
2 51
1 71 110
2 48
2 38
1 76 118
2 23
1 157 218
1 257 283
2 97
2 116
2 37
1 125 158
1 54 343
2 45
2 69
2 126
2 509
1 461 620
2 458
2 7
2 202
2 530
2 107
1 683 735
...

output:

o
b
r
b
g
a
e
b
z
x
a
a
x
p
m
i
w
w
a
c
n
a
i
i
a
i
h
i
i
x
i
o
u
v
n
i

result:

ok 36 lines

Test #18:

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

input:

16 65
bgmceovwgjsxvolb
1 13 14
2 5
2 16
2 9
1 7 17
1 16 20
2 12
2 12
1 34 34
1 21 35
1 4 30
1 6 13
2 40
2 15
2 77
2 38
1 31 46
2 79
2 75
2 71
2 39
1 82 90
2 32
1 61 80
2 36
2 93
2 26
1 81 128
2 78
2 158
2 136
1 150 154
1 147 165
1 135 135
2 150
2 99
2 78
2 152
2 178
1 102 157
2 4
1 199 230
1 274 276...

output:

e
o
g
g
g
x
v
o
s
v
v
v
s
j
j
v
g
v
o
v
o
v
v
o
o
c
v
v
o
o
v
v
l
v
v
v

result:

ok 36 lines

Test #19:

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

input:

63 21
rwhschtzyizzjldgrkifsjesoxchfvuekdyromzfdzxkxjyrpugmzkbdfspixeo
2 54
1 39 61
1 24 42
2 88
2 12
1 48 62
1 33 89
1 49 104
1 194 207
2 239
1 40 80
2 185
2 21
1 217 237
2 194
1 109 163
1 100 253
1 300 320
2 205
2 208
2 531

output:

k
k
z
s
z
s
z
r
r
s

result:

ok 10 lines

Test #20:

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

input:

22 16
hpkhufjykgzhwigldlutfg
1 14 15
2 13
1 12 17
1 11 25
2 38
1 2 29
1 26 34
1 4 5
1 31 57
2 3
2 87
1 85 87
2 24
1 84 103
2 15
1 134 134

output:

w
l
p
i
z
j

result:

ok 6 lines

Test #21:

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

input:

68 37
cqctxalmejoztbwmgfmjxuoptmqzoavhpyiwumhvjzsuclolxwleeoequbukxrjjnjgc
2 38
1 45 67
1 3 88
2 110
1 12 148
2 71
1 62 314
2 405
2 528
1 400 458
1 171 538
1 481 813
1 790 891
1 1426 1429
1 1025 1373
1 146 238
2 942
1 1749 1839
1 1300 1502
2 388
2 1124
1 2017 2132
1 2221 2258
1 1842 1860
1 487 2104
...

output:

m
w
u
e
r
e
j
o
o
q
e

result:

ok 11 lines

Test #22:

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

input:

20 80
ajgneaujzddnggsbcwom
2 20
1 5 20
2 9
2 13
2 24
2 18
1 11 27
2 13
2 13
2 17
1 19 50
2 8
2 8
1 81 83
2 12
1 67 76
2 70
2 44
1 41 71
1 66 106
2 66
1 140 147
2 95
2 41
1 156 173
2 76
1 151 174
1 19 109
1 135 178
2 125
1 233 355
2 295
1 153 177
2 296
1 112 156
1 72 548
2 815
2 921
2 622
1 461 486
1...

output:

m
u
z
g
d
j
j
z
a
a
j
b
g
g
s
n
g
g
b
s
b
c
b
b
c
d
b
g
g
b
s
g
g
c
s
b
s
s
s
s
c
s
s
g

result:

ok 44 lines

Test #23:

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

input:

11 28
gjecjaxeosx
2 3
1 4 6
1 13 14
2 1
2 10
2 10
2 12
1 1 8
2 8
1 7 7
2 10
2 23
2 12
2 10
2 19
2 7
1 19 19
1 17 21
2 12
1 5 18
2 16
2 26
1 4 11
1 52 52
1 18 35
1 28 45
2 79
2 56

output:

e
g
x
x
o
c
c
s
j
c
x
c
j
c
j
x
j

result:

ok 17 lines

Test #24:

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

input:

71 95
ioujmdnmwigsjkhmywaqupgclgtiihkmrrnwxhwnorqeveqnnlwbqjsuzywadknkuxkdatr
1 41 45
2 7
1 12 68
1 111 125
2 53
1 140 148
1 53 59
2 161
1 8 49
1 93 183
1 38 234
1 234 260
1 128 514
2 500
2 272
1 35 66
2 903
1 569 926
1 1093 1289
1 987 1397
1 465 1449
2 2520
2 2453
2 2803
1 2461 2807
2 2962
1 2554 2...

output:

n
m
t
q
n
k
a
a
n
k
a
v
y
a
l
n
e
b
l
z
u
b
w
l
u
u
l
u
u
j
s
j
j
j
j
s
u
s
j
s
z
s
u
s
j

result:

ok 45 lines

Test #25:

score: -100
Wrong Answer
time: 8ms
memory: 8752kb

input:

66343 13562
iacwskbysgfuinrclsxrluublrwdxttfwsoebgorohvbsnaivopnivgyzbxepjlghteqivamviwjjrsblkrbvkkhxoptwawnxwvtmecankhkmckptpoxhrmxfemfkdafwktwdfkbizrefgdssqhqzxbcppsotwrwjlrliwgtjagsjcapyvwvevllphvrnmnmbsesfhbvuhpwdpzhwsuufqwlpzskyzstvtafbtvermbbwsizqmnclqyoxnuyzbllrjaiwrifvwjmevzhpnoxmlqalktkftao...

output:

j
v
x
j
z
v
j
z
v
j
o
s
p
m
t
n
y
g
z
g
d
d
t
a
w
c
g
j
m
d
e
y
q
d
h
g
s
w
u
m
a
i
d
y
z
v
g
f
f
r
r
l
x
z
c
q
k
n
y
b
p
e
p
v
k
e
h
g
d
c
d
d
d
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
a
...

result:

wrong answer 68th lines differ - expected: 'r', found: 'g'