QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#244768 | #2831. Game Theory | Delay_for_five_minutes# | WA | 72ms | 11912kb | C++11 | 2.0kb | 2023-11-09 15:36:53 | 2023-11-09 15:37:40 |
Judging History
answer
#include<bits/stdc++.h>
#define maxn 200005
long long sum[2][maxn << 2];
long long sump[2][maxn << 2];
int rev[maxn << 2];
void Rev(int pos) {
rev[pos] ^= 1;
std::swap(sum[0][pos],sum[1][pos]);
std::swap(sump[0][pos],sump[1][pos]);
}
void pushdown(int pos) {
if (rev[pos]) {
rev[pos] = 0;
Rev(pos << 1), Rev(pos << 1 | 1);
}
}
void pushup(int pos) {
sum[0][pos] = sum[0][pos << 1] + sum[0][pos << 1 | 1];
sum[1][pos] = sum[1][pos << 1] + sum[1][pos << 1 | 1];
sump[0][pos] = sump[0][pos << 1] + sump[0][pos << 1 | 1];
sump[1][pos] = sump[1][pos << 1] + sump[1][pos << 1 | 1];
}
void update(int pos,int l,int r,int ql,int qr) {
if (r < ql || l > qr) return ;
if (ql <= l && r <= qr) {
Rev(pos);
return ;
}
pushdown(pos);
int mid = (l + r) >> 1;
update(pos << 1,l,mid,ql,qr);
update(pos << 1 | 1,mid + 1,r,ql,qr);
pushup(pos);
}
long long query(int pos,int l,int r,int ql,int qr,long long* tr) {
if (r < ql || l > qr) return 0;
if (ql <= l && r <= qr) {
return tr[pos];
}
pushdown(pos);
int mid = (l + r) >> 1;
return query(pos << 1, l, mid, ql, qr, tr);
return query(pos << 1 | 1, mid + 1, r, ql, qr, tr);
}
std::string str;
void build(int pos,int l,int r) {
rev[pos] = 0;
if (l == r) {
bool f = (str[r - 1] - '0');
sum[f][pos] = 1;
sum[f^1][pos] = 0;
sump[f][pos] = l;
sump[f^1][pos] = 0;
return ;
}
int mid = (l + r) >> 1;
build(pos << 1, l, mid);
build(pos << 1 | 1, mid + 1, r);
pushup(pos);
}
int n,q;
long long getans() {
int k = sum[1][1];
long long S = 1ll*(k-1)*k;
S -= (query(1,1,n,1,k,sum[1]) * k - query(1,1,n,1,k,sump[1])) * 2; // L1 * k - Lp * 2;
S += (query(1,1,n,k,n,sump[1]) - query(1,1,n,k,n,sum[1]) * k) * 2;
return S + k;
}
void solve() {
std::cin >> str;
build(1,1,n);
for(int i = 1; i <= q; i++) {
int l, r;
std::cin >> l >> r;
update(1,1,n,l,r);
std::cout << getans() % 998244353 << std::endl;
}
}
int main() {
// freopen("in.txt","r",stdin);
std::ios::sync_with_stdio(0);
while(std::cin >> n >> q) {
solve();
}
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 11900kb
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: 2ms
memory: 11804kb
input:
1 1 0 1 1
output:
1
result:
ok single line: '1'
Test #3:
score: 0
Accepted
time: 51ms
memory: 11812kb
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: 72ms
memory: 11912kb
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:
10 25 25 9 7 11 23 42 21 11 28 18 29 21 21 16 11 21 31 23 7 4 31 14 14 23 24 11 24 19 16 9 10 21 20 12 7 4 10 14 2 4 3 5 4 7 5 2 0 4 0 4 2 1 7 2 7 4 7 4 4 7 1 4 4 3 5 7 3 7 2 4 2 7 2 5 2 0 5 3 62 65 67 38 64 73 34 32 37 34 45 72 73 56 72 35 32 54 57 11 12 19 15 21 4 37 25 4 15 26 26 26 35 33 25 24 2...
result:
wrong answer 1st lines differ - expected: '16', found: '10'