QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#592224 | #2831. Game Theory | lonelywolf# | WA | 171ms | 50292kb | C++20 | 4.9kb | 2024-09-26 21:17:13 | 2024-09-26 21:17:17 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define int long long
template<class Info, class Tag>
struct LazySegmentTree {
int n;
vector<Info> info;
vector<Tag> tag;
LazySegmentTree() : n(0) {}
LazySegmentTree(int n_, Info v_ = Info()) {
init(n_, v_);
}
template<class T>
LazySegmentTree(vector<T> init_) {
init(init_);
}
void init(int n_, Info v_ = Info()) {
init(vector(n_ + 1, v_));
}
template<class T>
void init(vector<T> init_) {
n = init_.size() - 1;
info.assign(4 << __lg(n) + 1, Info());
tag.assign(4 << __lg(n) + 1, Tag());
function<void(int, int, int)> build = [&](int p, int l, int r) {
if (l == r) {
info[p] = init_[l];
return;
}
int m = (l + r) / 2;
build(2 * p, l, m);
build(2 * p + 1, m + 1, r);
pull(p);
};
build(1, 1, n);
}
void pull(int p) {
info[p] = info[2 * p] + info[2 * p + 1];
}
void apply(int p, const Tag &v) {
info[p].apply(v);
tag[p].apply(v);
}
void push(int p) {
apply(2 * p, tag[p]);
apply(2 * p + 1, tag[p]);
tag[p] = Tag();
}
void modify(int p, int l, int r, int x, const Info &v) {
if (l == r) {
info[p] = v;
return;
}
int m = (l + r) / 2;
push(p);
if (x <= m) {
modify(2 * p, l, m, x, v);
} else {
modify(2 * p + 1, m + 1, r, x, v);
}
pull(p);
}
void modify(int p, const Info &v) {
modify(1, 1, n, p, v);
}
Info rangeQuery(int p, int l, int r, int x, int y) {
if (l > y || r < x) {
return Info();
}
if (l >= x && r <= y) {
return info[p];
}
int m = (l + r) / 2;
push(p);
return rangeQuery(2 * p, l, m, x, y) + rangeQuery(2 * p + 1, m + 1, r, x, y);
}
Info rangeQuery(int l, int r) {
return rangeQuery(1, 1, n, l, r);
}
void rangeApply(int p, int l, int r, int x, int y, const Tag &v) {
if (l > y || r < x) {
return;
}
if (l >= x && r <= y) {
apply(p, v);
return;
}
int m = (l + r) / 2;
push(p);
rangeApply(2 * p, l, m, x, y, v);
rangeApply(2 * p + 1, m + 1, r, x, y, v);
pull(p);
}
void rangeApply(int l, int r, const Tag &v) {
return rangeApply(1, 1, n, l, r, v);
}
template<class F>
int findFirst(int p, int l, int r, int x, int y, F pred) {
if (l > y || r < x || !pred(info[p])) {
return -1;
}
if (l == r) {
return l;
}
int m = (l + r) / 2;
push(p);
int res = findFirst(2 * p, l, m, x, y, pred);
if (res == -1) {
res = findFirst(2 * p + 1, m + 1, r, x, y, pred);
}
return res;
}
template<class F>
int findFirst(int l, int r, F pred) {
return findFirst(1, 1, n, l, r, pred);
}
template<class F>
int findLast(int p, int l, int r, int x, int y, F pred) {
if (l > y || r < x || !pred(info[p])) {
return -1;
}
if (l == r) {
return l;
}
int m = (l + r) / 2;
push(p);
int res = findLast(2 * p + 1, m + 1, r, x, y, pred);
if (res == -1) {
res = findLast(2 * p, l, m, x, y, pred);
}
return res;
}
template<class F>
int findLast(int l, int r, F pred) {
return findLast(1, 1, n, l, r, pred);
}
};
struct Tag {
int rev = 0;
void apply(Tag t) {
rev ^= t.rev;
}
};
struct Info {
array<int, 2> cnt{0, 0};
array<int, 2> sum{0, 0};
void apply(Tag t) {
if (t.rev) {
swap(cnt[0], cnt[1]);
swap(sum[0], sum[1]);
}
}
};
Info operator+(Info a, Info b) {
Info c;
for (int i = 0; i < 2; i++) {
c.cnt[i] = a.cnt[i] + b.cnt[i];
c.sum[i] = a.sum[i] + b.sum[i];
}
return c;
}
constexpr bool LOCAL = false;
signed main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n, q;
while (cin >> n >> q) {
LazySegmentTree<Info, Tag> tr(n);
for (int i = 1; i <= n; i++) {
char c;
cin >> c;
if (c == '1') {
tr.modify(i, {{0, 1}, {0, i}});
} else {
tr.modify(i, {{1, 0}, {i, 0}});
}
}
while (q--) {
int l, r;
cin >> l >> r;
tr.rangeApply(l, r, {1});
auto v = tr.rangeQuery(1, n);
int a = v.sum[1], b = v.cnt[1];
// cerr << a << " " << b << "\n";
cout << (a - b * (b + 1) / 2) * 2 + b << "\n";
}
if (LOCAL) {
return 0;
}
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 3568kb
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: 0ms
memory: 3868kb
input:
1 1 0 1 1
output:
1
result:
ok single line: '1'
Test #3:
score: 0
Accepted
time: 38ms
memory: 3868kb
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: 0
Accepted
time: 34ms
memory: 3892kb
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 34 40 43 45 35 28 25 33 45 37 19 20 35 38 36 41 36 29 36 29 22 31 20 23 28 20 21 10 14 30 2 10 5 7 10 9 7 2 0 10 0 10 2 1 9 6 7 4 7 8 4 9 1 6 8 3 5 7 3 7 6 8 6 9 6 7 2 0 5 3 66 105 83 68 92 137 92 76 85 92 127 120 119 104 124 65 70 88 61 53 40 43 25 21 32 59 67 32 29 50...
result:
ok 200000 lines
Test #5:
score: 0
Accepted
time: 52ms
memory: 3700kb
input:
11 200 11100010010 2 3 3 7 1 7 3 10 1 3 7 11 2 8 4 8 9 10 9 11 2 7 1 4 9 11 6 7 4 4 8 10 2 6 2 3 1 2 5 7 2 7 1 3 3 4 2 10 9 10 6 11 3 11 3 9 9 10 2 6 5 10 1 8 4 9 6 7 8 11 3 9 7 10 1 9 4 5 5 8 5 7 2 7 6 8 10 10 5 10 7 11 1 11 6 10 2 11 1 4 4 8 6 11 7 10 8 10 4 5 7 10 7 8 4 4 1 6 7 11 3 5 4 9 3 9 8 1...
output:
27 22 29 25 30 39 34 17 15 12 18 22 33 35 40 45 54 36 34 37 39 52 54 37 39 33 40 51 37 46 52 24 26 24 16 7 35 30 32 40 39 37 28 15 41 28 39 4 26 54 49 31 39 26 28 44 46 41 35 26 17 31 24 28 30 22 38 13 18 60 38 36 49 41 41 43 27 28 54 41 14 16 7 8 20 22 45 26 27 20 21 12 27 31 28 21 39 37 39 30 31 2...
result:
ok 200000 lines
Test #6:
score: 0
Accepted
time: 79ms
memory: 4064kb
input:
228 2000 111000100100000001001101001100110001011110001110001000101110101100010011011111000001011011000110111010111101011000010010000111111111100011111011011100111010011100111001010011110110011000100100110011111000110001111001010011001010 23 112 24 165 103 162 86 203 99 204 114 217 55 132 168 184 110...
output:
13974 13044 13700 13434 14000 13220 13546 13913 13184 13533 13051 13689 13533 14119 14470 13742 13980 13022 13167 13648 13592 13159 13028 13041 12964 12996 12792 12539 12039 11974 12336 12742 12841 12831 12730 12004 12065 12352 13037 11923 12332 14242 13475 13935 13121 12996 12755 13353 13720 13043 ...
result:
ok 200000 lines
Test #7:
score: 0
Accepted
time: 126ms
memory: 9384kb
input:
20000 20000 110010001110111001001001011110011011011011101011010000011100100100110000011111000010010101001001110101010000011010101110001100111010000101000010110100011111001100001110011011001011010000100110010001000101111101001011100110101111110110100001100100110100000100100001011100111011000101111010...
output:
99977542 98746996 98989557 99015753 98938270 98605428 99504163 99699325 101118187 100862580 99993292 99728608 101006398 100940632 100522798 99799311 99585772 100035886 99976445 99131130 99309148 99370536 100535551 99600860 99595679 99735286 99976663 100435885 100334687 100103891 100055339 100160376 ...
result:
ok 200000 lines
Test #8:
score: -100
Wrong Answer
time: 171ms
memory: 50292kb
input:
200000 200000 1101110010111101001110011011011100110000111011010010001110010111010000111100010101100111111010010100111110001001011000010110000100111111011110101101011011011101000010000110010011001011101000000100010110001100001010110010011101010100000011101111001110001110110000101101111011111101000101...
output:
10008345471 9978724639 9985258030 9985907293 9991673860 10011084416 10009425011 9997441308 9996266981 9988543457 10007145550 10003805687 9994416764 9995955504 10004097166 10015563170 10022793858 10028553181 10011635882 10026210037 10013171967 10011313687 10027633147 9986661473 9996002182 10017854287...
result:
wrong answer 1st lines differ - expected: '25901941', found: '10008345471'