QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#83382#2831. Game Theoryuniecho1#WA 54ms7592kbC++173.2kb2023-03-01 17:16:392023-03-01 17:16:41

Judging History

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

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-01 17:16:41]
  • 评测
  • 测评结果:WA
  • 用时:54ms
  • 内存:7592kb
  • [2023-03-01 17:16:39]
  • 提交

answer

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#include <bits/stdc++.h>
#define int long long
#define pii pair<int, int>
#define mkp make_pair
#define endl '\n'
using namespace std;

const int MAXN = 2e5 + 5;
const int mod = 998244353;

struct segtree {
    int sum[MAXN << 2], num[MAXN << 2];
    bool rev[MAXN << 2];

    void update(int id) {
        sum[id] = (0ll + sum[id << 1] + sum[id << 1 | 1]) % mod;
        num[id] = num[id << 1] + num[id << 1 | 1];
    }
    void pushdown(int l, int r, int id) {
        if (rev[id]) {
            rev[id] ^= 1;
            rev[id << 1] ^= 1;
            rev[id << 1 | 1] ^= 1;
            int m = l + r >> 1;
            sum[id << 1] =
                (1ll * (l + m) * (m - l + 1) / 2 - sum[id << 1]) % mod;
            num[id << 1] = (m - l + 1) - num[id << 1];
            sum[id << 1 | 1] =
                (1ll * (m + 1 + r) * (r - m) / 2 - sum[id << 1 | 1]) % mod;
            num[id << 1 | 1] = (r - m) - num[id << 1 | 1];
        }
    }
    void build(int l, int r, int id) {
        rev[id] = 0;
        sum[id] = num[id] = 0;
        if (l == r) {
            char c;
            cin >> c;
            if (c == '1') num[id] = 1, sum[id] = l;
            return;
        }
        int m = l + r >> 1;
        build(l, m, id << 1);
        build(m + 1, r, id << 1 | 1);
        update(id);
    }
    void revolve(int x, int y, int l, int r, int id) {
        // cout << l << " " << r << endl;
        if (x > y) return;
        if (x <= l && r <= y) {
            sum[id] = (1ll * (l + r) * (r - l + 1) / 2 - sum[id]) % mod;
            num[id] = r - l + 1 - num[id];
            rev[id] = true;
            return;
        }
        pushdown(l, r, id);
        int m = l + r >> 1;
        if (x <= m) revolve(x, y, l, m, id << 1);
        if (y > m) revolve(x, y, m + 1, r, id << 1 | 1);
        update(id);
    }
    pii query(int x, int y, int l, int r, int id) {
        // cout << x << " " << y << " " << l << " " << r << endl;
        if (x > y) return mkp(0, 0);
        if (x <= l && r <= y) return mkp(sum[id], num[id]);
        int m = l + r >> 1;
        pushdown(l, r, id);
        if (x <= m && y > m) {
            auto a = query(x, y, l, m, id << 1);
            auto b = query(x, y, m + 1, r, id << 1 | 1);
            return mkp((0ll + a.first + b.first) % mod, a.second + b.second);
        } else if (x <= m)
            return query(x, y, l, m, id << 1);
        else
            return query(x, y, m + 1, r, id << 1 | 1);
    }
} T;

int N, Q;

signed main() {
    // freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    while (cin >> N >> Q) {
        T.build(1, N, 1);
        for (int i = 1, l, r; i <= Q; i++) {
            cin >> l >> r;
            T.revolve(l, r, 1, N, 1);
            int k = T.query(1, N, 1, N, 1).second;
            int part2 = T.query(k + 1, N, 1, N, 1).first;
            int part1 = T.query(1, k, 1, N, 1).first;
            part1 = (1ll * (1 + k) * k / 2 - part1) % mod;
            int ans = (k - 2 * part1 % mod + 2 * part2 % mod + mod) % mod;
            cout << ans << endl;
        }
    }
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3 2
010
1 2
2 3
5 1
00000
1 5

output:

1
3
5

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 3ms
memory: 7592kb

input:

1 1
0
1 1

output:

1

result:

ok single line: '1'

Test #3:

score: 0
Accepted
time: 48ms
memory: 7404kb

input:

2 2
01
2 2
2 2
2 2
01
1 2
1 2
1 2
1
1 1
1 1
1 2
1
1 1
1 1
2 2
00
1 2
1 2
2 2
11
1 2
1 2
2 2
01
2 2
1 1
2 2
10
2 2
1 2
2 2
01
1 2
1 2
1 2
0
1 1
1 1
2 2
01
1 2
2 2
1 2
0
1 1
1 1
1 2
1
1 1
1 1
2 2
10
1 2
1 1
1 2
0
1 1
1 1
2 2
01
1 2
1 2
2 2
10
1 2
1 1
1 2
0
1 1
1 1
1 2
0
1 1
1 1
1 2
1
1 1
1 1
2 2
10
1 ...

output:

0
3
1
3
0
1
0
1
2
0
0
2
0
1
2
0
1
3
1
0
1
2
1
0
0
1
3
2
1
0
1
3
3
2
1
0
1
0
0
1
0
1
0
2
2
1
0
1
2
1
1
0
2
0
2
3
1
0
0
1
2
0
0
1
0
1
0
1
1
0
1
2
2
0
0
2
0
1
0
1
1
0
1
0
1
0
0
1
0
1
0
1
2
0
3
0
1
0
0
1
1
0
1
0
1
2
0
2
1
0
0
3
1
2
0
1
3
2
1
0
0
1
2
0
2
0
0
1
0
1
1
0
1
0
1
0
1
0
1
2
1
0
3
1
0
3
0
1
0
1
...

result:

ok 200000 lines

Test #4:

score: -100
Wrong Answer
time: 54ms
memory: 5444kb

input:

11 20
00010111000
1 6
1 11
5 6
8 11
1 4
3 8
4 11
1 7
5 9
1 4
6 10
5 6
1 7
5 10
1 10
9 11
6 8
1 4
8 11
1 4
10 20
0101000010
3 4
2 2
4 8
4 6
6 7
3 7
3 3
1 5
1 5
6 8
2 2
2 4
2 6
5 7
1 3
2 5
6 8
7 9
5 8
3 10
4 20
1011
2 4
1 4
1 3
2 3
1 1
2 2
1 2
2 4
1 2
3 4
3 4
3 4
1 4
2 2
1 4
1 3
1 1
1 3
1 3
2 2
4 20
1...

output:

16
55
53
25
13
15
43
52
41
33
998244337
38
34
32
26
30
27
35
37
29
19
20
35
56
54
41
34
29
34
29
23
18
29
22
21
17
44
11
31
39
2
10
5
9
4
7
9
0
2
4
2
4
0
3
998244346
6
5
2
11
4
4
9
1
6
8
3
5
7
3
7
6
8
6
9
6
7
0
2
3
1
66
105
83
68
10
137
113
109
104
113
106
103
104
87
79
90
165
53
67
71
40
43
25
21
3...

result:

wrong answer 11th lines differ - expected: '34', found: '998244337'