QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#826231#9791. Intrusive DonkeyZawos#WA 0ms3832kbC++203.7kb2024-12-22 04:09:412024-12-22 04:09:42

Judging History

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

  • [2024-12-22 04:09:42]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3832kb
  • [2024-12-22 04:09:41]
  • 提交

answer

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

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using ii = pair<int, int>;
using vii = vector<ii>;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(x) x.begin(), x.end()
#define pb(x) push_back(x)

const int MX = 3e5;

struct Segtree {
    vll st, lazy;
    int n;

    void build(vll &nums, int v, int tl, int tr) {
        if (tl == tr) {
            st[v] = nums[tl];
            return;
        }

        int mid = (tl + tr) / 2;
        build(nums, 2 * v, tl, mid);
        build(nums, 2 * v + 1, mid + 1, tr);
        st[v] = st[2 * v] + st[2 * v + 1];
    }

    void build(vll &nums) {
        n = nums.size();
        st.resize(4 * n);
        lazy.resize(4 * n);
        build(nums, 1, 0, n - 1);
    }

    void rangeUpdate(int v, int tl, int tr, int l, int r) {
        if (tl >= l && tr <= r) {
            st[v] *= 2ll;
            lazy[v]++;
            return;
        }

        if (tl > r || tr < l) return;
        push(v);
        int mid = (tl + tr) / 2;
        rangeUpdate(2 * v, tl, mid, l, r);
        rangeUpdate(2 * v + 1, mid + 1, tr, l, r);
        st[v] = st[2 * v] + st[2 * v + 1];
    }

    void rangeUpdate(ll l, ll r) {
        int tl = kth(l), tr = kth(r);
        rangeUpdate(1, 0, n - 1, tl + 1, tr - 1);
        if (tl == tr) {
            pointUpdate(tl, r - l + 1ll);
        }else {
            pointUpdate(tr, r - sum(0, tr - 1));
            pointUpdate(tl, sum(0, tl) - l + 1ll);
            
        }
    }

    void pointUpdate(int v, int tl, int tr, int pos, ll x) {
        if (tl == tr) {
            st[v] += x;
            return;
        }
        push(v);
        int mid = (tl + tr) / 2;
        if (pos <= mid)
            pointUpdate(2 * v, tl, mid, pos, x);
        else 
            pointUpdate(2 * v + 1, mid + 1, tr, pos, x);
        st[v] = st[2 * v] + st[2 * v + 1];
    }

    void pointUpdate(int pos, ll x) {
        pointUpdate(1, 0, n - 1, pos, x);
    }   

    ll sum(int v, int tl, int tr, int l, int r) {
        if (tl >= l && tr <= r) return st[v];
        if (tl > l || tr < l) return 0;
        push(v);
        int mid = (tl + tr) / 2;
        return sum(2 * v, tl, mid, l, r) + sum(2 * v + 1, mid + 1, tr, l, r);
    }

    ll sum(int l, int r) {
        return sum(1, 0, n - 1, l, r);
    }

    int kth(int v, int tl, int tr, ll x) {
        if (tl == tr) return tl;
        push(v);
        int mid = (tl + tr) / 2;
        if (st[2 * v] >= x)
            return kth(2 * v, tl, mid, x);
        return kth(2 * v + 1, mid + 1, tr, x - st[2 * v]);
    }

    int kth(ll x) {
        return kth(1, 0, n - 1, x);
    }

    void push(int v) {
        if (lazy[v]) {
            lazy[2 * v] += lazy[v];
            lazy[2 * v + 1] += lazy[v];
            st[2 * v] *= 1ll << lazy[v];
            st[2 * v + 1] *= 1ll << lazy[v];
            lazy[v] = 0;
        }
    }
};

void solve() {
    int n, q; cin >> n >> q;
    string s; cin >> s;
    vll blocks;
    string chars;
    ll cur = 1;
    rep(i, 1, n) {
        if (s[i] != s[i - 1]) {
            blocks.pb(cur);
            chars.pb(s[i - 1]);
            cur = 0;
        }

        cur++;
    }

    blocks.pb(cur);
    chars.pb(s[n - 1]);

    Segtree st; st.build(blocks);

    while (q--) {
        int op; cin >> op;
        if (op == 1) {
            ll l, r; cin >> l >> r;
            st.rangeUpdate(l, r);
        }else {
            ll x; cin >> x;
            cout << chars[st.kth(x)] << "\n";
        }
    }   
}

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int t = 1; //cin >> t;
    while (t--)
        solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 3560kb

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: 0ms
memory: 3832kb

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: 3628kb

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: 3792kb

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: -100
Wrong Answer
time: 0ms
memory: 3556kb

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
u
c
p
u
h
u
p
w
k
u
j
u
b
u
u
u
u
u
u
u

result:

wrong answer 7th lines differ - expected: 'q', found: 'u'