QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#369745 | #2827. Autobiography | PetroTarnavskyi# | WA | 1ms | 3552kb | C++20 | 2.1kb | 2024-03-28 17:21:42 | 2024-03-28 17:21:43 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (a) - 1; i >= (b); i--)
#define SZ(a) int(a.size())
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
#define F first
#define S second
typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;
typedef double db;
struct SegTree
{
VI lazy, cnt;
vector<LL> sum, all;
void init(int _n)
{
int n = 1;
while(n <= _n) n *= 2;
n *= 2;
lazy.resize(n);
cnt.resize(n);
sum.resize(n);
all.resize(n);
}
void combine(int v)
{
cnt[v] = cnt[2 * v + 1] + cnt[2 * v + 2];
sum[v] = sum[2 * v + 1] + sum[2 * v + 2];
all[v] = all[2 * v + 1] + all[2 * v + 2];
}
void build(int v, int tl, int tr, const string& s)
{
if(tl + 1 == tr)
{
cnt[v] = 0;
all[v] = tl + 1;
if(s[tl] == '1')
{
cnt[v] = 1;
sum[v] = all[v];
}
return;
}
int tm = (tl + tr) / 2;
build(2 * v + 1, tl, tm, s);
build(2 * v + 2, tm, tr, s);
combine(v);
}
void push(int v, int tl, int tr)
{
if(!lazy[v])
return;
lazy[v] = 0;
sum[v] = all[v] - sum[v];
cnt[v] = (tr - tl) - cnt[v];
if(tl + 1 == tr)
return;
lazy[2 * v + 1] ^= 1;
lazy[2 * v + 2] ^= 1;
}
void upd(int v, int tl, int tr, int l, int r)
{
push(v, tl, tr);
if(tr <= l || r <= tl)
return;
if(l <= tl && tr <= r)
{
lazy[v] = 1;
push(v, tl, tr);
return;
}
int tm = (tl + tr) / 2;
upd(2 * v + 1, tl, tm, l, r);
upd(2 * v + 2, tm, tr, l, r);
combine(v);
}
};
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
int n, q;
while(cin >> n >> q)
{
string s;
cin >> s;
SegTree T;
T.init(n);
T.build(0, 0, n, s);
while(q--)
{
int l, r;
cin >> l >> r;
T.upd(0, 0, n, l - 1, r);
assert(T.lazy[0] == 0);
LL sum = T.sum[0];
LL cnt = T.cnt[0];
//cout << sum << " " << cnt << "\n";
cout << 2 * sum - cnt * cnt << "\n";
}
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3552kb
input:
5 4 bbobo 1 3 2 3 3 4 4 5 4 6 bobo 1 2 1 3 1 4 2 3 2 4 3 4 4 0 bobo
output:
3 1 7 9 2 5 5 7 2 4
result:
wrong answer 1st lines differ - expected: '2', found: '3'