QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#356096 | #2831. Game Theory | LittleXi# | WA | 153ms | 3592kb | C++20 | 2.7kb | 2024-03-17 15:31:24 | 2024-03-17 15:31:25 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5+5;
using ll = long long;
const ll mod = 998244353;
int n,q;
string S;
pair<ll,ll> operator+(pair<ll,ll> a, pair<ll,ll> b)
{
return {a.first + b.first, a.second + b.second};
}
struct SEG
{
struct node
{
int l,r;
ll cnt1, cnt1i; //区间内1的数量,1的下标和
bool flip;
}t[MAXN<<2];
#define ls (p<<1)
#define rs ((p<<1)|1)
void upd(int p)
{
t[p].cnt1 = (t[p].r - t[p].l + 1) - t[p].cnt1;
t[p].cnt1i = 1ll * (t[p].l + t[p].r) * (t[p].r - t[p].l + 1) / 2 - t[p].cnt1i;
t[p].flip ^= 1;
}
void pushup(int p)
{
t[p].cnt1 = t[ls].cnt1 + t[rs].cnt1;
t[p].cnt1i = t[ls].cnt1i + t[rs].cnt1i;
}
void pushdown(int p)
{
if(t[p].flip)
{
upd(ls); upd(rs);
t[p].flip = 0;
}
}
void build(int p, int l, int r)
{
t[p].l = l; t[p].r = r; t[p].flip = 0;
if(l == r)
{
if(S[l-1] == '1') t[p].cnt1 = 1, t[p].cnt1i = l;
else t[p].cnt1 = t[p].cnt1i = 0;
return;
}
int mid = (l+r)/2;
build(ls, l, mid); build(rs, mid+1, r);
pushup(p);
}
void update(int p, int L, int R)
{
if(L <= t[p].l && t[p].r <= R)
{
upd(p);
return;
}
pushdown(p);
int mid = (t[p].l + t[p].r) / 2;
if(L <= mid) update(ls, L, R);
if(R > mid) update(rs, L, R);
pushup(p);
}
pair<ll,ll> query(int p, int L, int R)
{
if(L <= t[p].l && t[p].r <= R)
{
return {t[p].cnt1, t[p].cnt1i};
}
pushdown(p);
int mid = (t[p].l + t[p].r) / 2;
pair<ll,ll> ret = {0, 0};
if(L <= mid) ret = ret + query(ls, L, R);
if(R > mid) ret = ret + query(rs, L, R);
return ret;
}
}seg;
void solve()
{
cin >> S;
seg.build(1, 1, n);
while(q--)
{
int l,r; cin >> l >> r;
seg.update(1, l, r);
int s = seg.query(1, 1, n).first;
int val = seg.query(1, s, s).first;
ll suma = ((1 <= s-1) ? 1ll * s * (s-1) / 2 - seg.query(1, 1, s-1).second : 0);
ll sumb = ((s+1 <= n) ? seg.query(1, s+1, n).second : 0);
ll ans = (val == 1 ? sumb - suma + s : sumb - suma - s);
ans = ans % mod;
//printf("s=%d, val=%d, suma=%lld, sumb=%lld, ans=%lld\n",s,val,suma,sumb,ans);
cout << ans << endl;
}
}
int main()
{
while(cin >> n >> q)
{
solve();
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3580kb
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: 1ms
memory: 3560kb
input:
1 1 0 1 1
output:
1
result:
ok single line: '1'
Test #3:
score: -100
Wrong Answer
time: 153ms
memory: 3592kb
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 1 1 1 0 1 0 1 2 0 0 2 0 1 2 0 1 1 1 0 1 2 1 0 0 1 1 2 1 0 1 1 1 2 1 0 1 0 0 1 0 1 0 2 2 1 0 1 2 1 1 0 2 0 2 1 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 1 0 1 0 0 1 1 0 1 0 1 2 0 2 1 0 0 1 1 2 0 1 1 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 1 1 0 1 0 1 0 1 ...
result:
wrong answer 2nd lines differ - expected: '3', found: '1'