QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#263557#186. Street LampsCamillus0 531ms420784kbC++206.2kb2023-11-24 22:49:572023-11-24 22:49:59

Judging History

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

  • [2023-11-24 22:49:59]
  • 评测
  • 测评结果:0
  • 用时:531ms
  • 内存:420784kb
  • [2023-11-24 22:49:57]
  • 提交

answer

#include "bits/stdc++.h"

using ll = long long;
using namespace std;

pair<int, ll> operator+(const pair<int, ll> &A, const pair<int, ll> &B) {
    return {A.first + B.first, A.second + B.second};
}

namespace implicit_st {
    struct node {
        int cnt = 0;
        ll sum = 0;

        int left = 0, right = 0;
    };

    vector<node> tree = { node() };

    int new_node() {
        tree.emplace_back();
        return (int)tree.size() - 1;
    }

    void add(int l, int r, int v, int x, int lx, int rx) {
        assert(x != 0);

        if (l <= lx && rx <= r) {
            tree[x].cnt += 1;
            tree[x].sum += v;
            return;
        }

        if (l >= rx || lx >= r) {
            return;
        }

        int mx = (lx + rx) / 2;

        {
            if (!tree[x].left) {
                tree[x].left = new_node();
            }
            add(l, r, v, tree[x].left, lx, mx);
        }

        {
            if (!tree[x].right) {
                tree[x].right = new_node();
            }
            add(l, r, v, tree[x].right, mx, rx);
        }
    }

    pair<int, ll> get(int i, int x, int lx, int rx) {
        if (x == 0) {
            return {0, 0ll};
        }

        pair<int, ll> cur(tree[x].cnt, tree[x].sum);

        if (rx - lx == 1) {
            return cur;
        }

        int mx = (lx + rx) / 2;

        if (i < mx) {
            return get(i, tree[x].left, lx, mx) + cur;
        } else {
            return get(i, tree[x].right, mx, rx) + cur;
        }
    }

    struct st {
        int root;
        int n;

        st(int n) : n(n) {
            root = new_node();
        }

        void add(int l, int r, int v) const {
            implicit_st::add(l, r, v, root, 0, n);
        }

        pair<int, ll> get(int i) const {
            return implicit_st::get(i, root, 0, n);
        }
    };
} // namespace implicit_st

struct main_st {
    vector<implicit_st::st> tree;
    int n;

    main_st(int n) : n(n) {
        tree.assign(4 * n, implicit_st::st(0));
        for (auto &item : tree) {
            item = implicit_st::st(n + 1);
        }
    }

    void add(pair<int, int> lefts, pair<int, int> rights, int time) {
        add(lefts.first, lefts.second + 1, rights.first, rights.second + 1, time, 0, 0, n);
    }

    pair<int, ll> get(int a, int b) {
        return get(a, b, 0, 0, n);
    }

private:
    void add(int lq, int rq, int l, int r, int v, int x, int lx, int rx) {
        if (lq <= lx && rx <= rq) {
            tree[x].add(l, r, v);
            return;
        }

        if (lq >= rx || lx >= rq) {
            return;
        }

        add(lq, rq, l, r, v, x * 2 + 1, lx, (lx + rx) / 2);
        add(lq, rq, l, r, v, x * 2 + 2, (lx + rx) / 2, rx);
    }

    pair<int, ll> get(int i, int v, int x, int lx, int rx) {
        if (rx - lx == 1) {
            return tree[x].get(v);
        }

        int mx = (lx + rx) / 2;

        if (i < mx) {
            return tree[x].get(v) + get(i, v, x * 2 + 1, lx, mx);
        } else {
            return tree[x].get(v) + get(i, v, x * 2 + 2, mx, rx);
        }
    }
};

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int n, q;
    cin >> n >> q;

    main_st B(n), E(n);
    set<pair<int, int>> S;

    string s;
    cin >> s;

    for (int i = 0; i < n; ) {
        if (s[i] == '1') {
            int l = i, r = i;

            while (s[i] == '1') {
                r = i + 1;
                i++;
            }

            for (int j = l; j < r; j++) {
                B.add(make_pair(j, j), make_pair(j + 1, r), 0);
            }

            S.emplace(l, r);
        } else {
            i++;
        }
    }

    for (int t = 1; t <= q; t++) {
        string type;
        cin >> type;

        if (type == "query") {
            int a, b;
            cin >> a >> b;

            a--, b--;

            auto x = B.get(a, b);
            auto y = E.get(a, b);

            ll ans = y.second - x.second;

            if (x.first != y.first) {
                ans += t;
            }

            cout << ans << '\n';
        } else {
            int i;
            cin >> i;

            i--;

            if (s[i] == '1') {
                s[i] = '0';

                auto it = prev(S.upper_bound(make_pair(i + 1, i + 1)));

                int l = it->first;
                int r = it->second;

                E.add(make_pair(l, i), make_pair(i + 1, r), t);

                S.erase(it);

                if (l < i) {
                    S.emplace(l, i);
                }

                if (i + 1 < r) {
                    S.emplace(i + 1, r);
                }
            } else {
                s[i] = '1';

                if ((i - 1 < 0 || s[i - 1] == '0') && (i + 1 >= n || s[i + 1] == '0')) {
                    S.emplace(i, i + 1);
                    B.add(make_pair(i, i), make_pair(i + 1, -1), t);
                } else if ((i - 1 < 0 || s[i - 1] == '0') && !(i + 1 >= n || s[i + 1] == '0')) {
                    auto it = S.upper_bound(make_pair(i + 1, i + 1));

                    int r = it->second;
                    S.erase(it);

                    S.emplace(i, r);

                    B.add(make_pair(i, i), make_pair(i + 1, r), t);
                } else if (!(i - 1 < 0 && s[i - 1] == '0') && (i + 1 >= n || s[i + 1] == '0')) {
                    auto it = prev(S.upper_bound(make_pair(i + 1, i + 1)));

                    int l = it->first;
                    S.erase(it);

                    S.emplace(l, i + 1);

                    B.add(make_pair(l, i), make_pair(i + 1, -1), t);
                } else {
                    auto it = S.upper_bound(make_pair(i + 1, i + 1));
                    int r = it->second;

                    it = prev(it);
                    S.erase(next(it));

                    int l = it->first;
                    S.erase(it);

                    S.emplace(l, r);

                    B.add(make_pair(l, i), make_pair(i + 1, r), t);
                }
            }
        }
    }
    return 0;
}

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 20
Accepted
time: 1ms
memory: 3460kb

input:

5 7
11011
query 1 2
query 1 2
query 1 6
query 3 4
toggle 3
query 3 4
query 1 6

output:

1
2
0
0
1
2

result:

ok 6 lines

Test #2:

score: -20
Wrong Answer
time: 0ms
memory: 3432kb

input:

5 50
01001
query 1 6
toggle 3
toggle 3
toggle 2
toggle 3
toggle 2
toggle 4
query 2 6
query 2 3
query 1 3
query 3 5
toggle 3
query 2 6
query 1 5
query 2 3
query 3 6
toggle 5
toggle 1
toggle 2
toggle 4
query 1 6
query 4 5
toggle 3
query 5 6
toggle 2
query 4 6
toggle 5
toggle 5
toggle 2
query 4 5
query...

output:

0
1
7
0
4
5
0
13
5
0
13
17
10
13
5
5
6
54
0
10
0
5
0
5
6

result:

wrong answer 18th lines differ - expected: '24', found: '54'

Subtask #2:

score: 0
Wrong Answer

Test #9:

score: 0
Wrong Answer
time: 119ms
memory: 3760kb

input:

100 300000
1100100000000101010010100111010001100010001100111101000010111110001101101110100100100110101010110010
query 13 14
query 42 43
toggle 64
query 78 79
toggle 85
query 35 36
toggle 35
query 4 5
toggle 5
query 4 5
query 42 43
query 35 36
query 13 14
query 14 15
toggle 15
toggle 31
query 20 21
q...

output:

0
0
0
6
0
0
0
7
0
14
0
18
0
0
21
0
26
0
0
36
38
15
41
44
0
47
20
50
52
0
55
52
56
0
35
0
70
73
0
0
0
0
0
83
84
90
7
0
95
97
0
70
0
103
26
0
46
207
109
122
210
109
108
0
0
217
0
135
139
112
35
142
9
146
0
151
0
153
0
0
73
0
164
0
285
0
309
173
135
109
178
180
75
0
189
35
0
197
23
0
200
0
0
206
208
29...

result:

wrong answer 36th lines differ - expected: '31', found: '0'

Subtask #3:

score: 0
Memory Limit Exceeded

Test #17:

score: 20
Accepted
time: 0ms
memory: 4196kb

input:

1000 1003
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

0
0
0

result:

ok 3 lines

Test #18:

score: 0
Accepted
time: 2ms
memory: 4124kb

input:

1000 1003
00100001101000000001000001001000100010000010010010001001001010001010101100010001000010101100000001001111000001110000010110100000100110001000000101001110000001110001000100000011001110000011010100101000000010100110100010000000110000111100100000011000100010010100000000100000000010001001110101...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 304 lines

Test #19:

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

input:

1000 1003
11001001111000111100001101101111110010111101110100101000111001111011110111110111111001110011111110111110101110011101111111111111010111010100011010011100101011111001111010111110111010111011101100100111010000110101110001000011100010111110011001010110101111011101100110001100111000000011000111...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
70
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0...

result:

ok 595 lines

Test #20:

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

input:

1000 1003
11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111...

output:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
...

result:

ok 1003 lines

Test #21:

score: 0
Accepted
time: 464ms
memory: 420784kb

input:

300000 300000
0000000000000000000000000000000000000000000000000100000000000100000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 2993 lines

Test #22:

score: 0
Accepted
time: 531ms
memory: 420272kb

input:

300000 300000
0011010101100001010010010000110110001001001010100100100000011000001000000011000001000000000000011000000000001001000100100110001001100000000100000010111000000100000000010001000010010000111100010000010100001010100010000100000000111011000000110100000000010010000011010000100100011100000000...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 90028 lines

Test #23:

score: -20
Memory Limit Exceeded

input:

300000 300000
0100110101111011111000101011001011100101011100111110111101110111001101110101111011011110110110110100011011110101100111101001010110011110111010100111100101011110011011011011110100100101011111101111101010111011111111001101100011110011011001010011111111101110101101010011110111011110101011...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:


Subtask #4:

score: 0
Wrong Answer

Test #30:

score: 20
Accepted
time: 0ms
memory: 4080kb

input:

1000 1003
10111011001010101101100010101100100010100110001000000001001100111110101100110100010001111101101100110111110100011000111101100100000110110010101011101001101110111100010100100000110001010001111101001010100101011111010000001110111110001011010111101100000001001110101110011111000101101100011010...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 991 lines

Test #31:

score: 0
Accepted
time: 2ms
memory: 4148kb

input:

1000 1003
01000000111001001110011100111111110011010010110000100010101101101011100011010100100100110101110101010111011100110100110000001010110001011011011010001001101000111011001000000001001100101100010101011101000000101110111011011101100001011110111011001010011101000110100011000101011101000110001011...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

ok 701 lines

Test #32:

score: -20
Wrong Answer
time: 2ms
memory: 4144kb

input:

1000 1003
00010001110110110000001111110000010011011011100111101001011010000111111110001111010101111011100100101000010111101111100011000111001111011011011101000101100000011101001001111110011000100011000001010001011000000010101001101111101111111101011101101000110010110111010111111001101000000100011100...

output:

0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
...

result:

wrong answer 271st lines differ - expected: '693', found: '111'

Subtask #5:

score: 0
Skipped

Dependency #1:

0%