QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#263567#186. Street LampsCamillus0 2ms3836kbC++206.0kb2023-11-24 22:59:322023-11-24 22:59:33

Judging History

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

  • [2023-11-24 22:59:33]
  • 评测
  • 测评结果:0
  • 用时:2ms
  • 内存:3836kb
  • [2023-11-24 22:59:32]
  • 提交

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;

    map<pair<int, int>, int> cnt;
    map<pair<int, int>, ll> sum;

    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) {
        for (int l = lefts.first; l <= lefts.second; l++) {
            for (int r = rights.first; r <= rights.second; r++) {
                cnt[make_pair(l, r)] += 1;
                sum[make_pair(l, r)] += 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 make_pair(cnt[make_pair(a, b)], sum[make_pair(a, 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++;
        }
    }

    auto check = [&](int i) -> bool {
        if (0 <= i && i < n && s[i] == '1') {
            return true;
        }
        return false;
    };

    auto get_it = [&](int i) -> auto {
        auto it = S.upper_bound(make_pair(i + 1, 0));
        return prev(it);
    };

    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 (check(i)) {
                auto it = get_it(i);
                
                int l = it->first;
                int r = it->second;
                S.erase(it);

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

                if (i + 1 < r) {
                    S.emplace(i + 1, r);
                }

                E.add(make_pair(l, i), make_pair(i + 1, r), t);
            } else {
                
                int l = i;
                int r = i + 1;

                if (check(i - 1)) {
                    auto it = get_it(i - 1);
                    l = it->first;
                    S.erase(it);
                }

                if (check(i + 1)) {
                    auto it = get_it(i + 1);
                    r = it->second;
                    S.erase(it);
                }

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

                S.emplace(l, r);
            }
        }
    }
    return 0;
}

详细

Subtask #1:

score: 0
Runtime Error

Test #1:

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

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
Runtime Error

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:


result:


Subtask #2:

score: 0
Runtime Error

Test #9:

score: 0
Runtime Error

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:


result:


Subtask #3:

score: 0
Wrong Answer

Test #17:

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

input:

1000 1003
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

0
0
0

result:

ok 3 lines

Test #18:

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

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:

wrong answer 249th lines differ - expected: '26', found: '0'

Subtask #4:

score: 0
Wrong Answer

Test #30:

score: 20
Accepted
time: 2ms
memory: 3788kb

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: -20
Wrong Answer
time: 2ms
memory: 3832kb

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:

wrong answer 550th lines differ - expected: '92', found: '1107'

Subtask #5:

score: 0
Skipped

Dependency #1:

0%