QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#364227#2831. Game Theoryx_jw#WA 33ms3680kbC++142.3kb2024-03-24 13:05:142024-03-24 13:05:15

Judging History

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

  • [2024-03-24 13:05:15]
  • 评测
  • 测评结果:WA
  • 用时:33ms
  • 内存:3680kb
  • [2024-03-24 13:05:14]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using db=double;
#define int long long
using pii=pair<int,int>;
#define endl "\n"
#define pb push_back
const int N = 2e6+10;
struct node{
    int l,r,s0,s1,cn1;
    int fl;
}tr[N];

#define mid (l+r>>1)
#define u tr[i]
int cnt;
void now(int &i){
    i = ++cnt;
    u.l = u.r = u.cn1 = u.s0 = u.s1 = 0;
    u.fl = 0;
}
string s1;

void up(int i){
    node &l = tr[u.l],&r = tr[u.r];
    u.cn1 = l.cn1+r.cn1;
    u.s0  = l.s0+r.s0;
    u.s1 = l.s1+r.s1;
}

void update(int i,int l,int r){
    int cn = r-l+1;
    u.cn1 = cn-u.cn1;
    swap(u.s0,u.s1);
    u.fl ^= 1;
}

void down(int i,int l,int r){
    if(!u.fl)return;
    update(u.l,l,mid);
    update(u.r,mid+1,r);
    u.fl = 0;
    return;
}

void build(int &i,int l,int r){
    now(i);
    if(l == r){
        int fl = s1[l-1] == '1';
        if(fl == 1)u.cn1++,u.s1 += l;
        else u.s0 += l;
        return;
    }
    build(u.l,l,mid);
    build(u.r,mid+1,r);
    up(i);
}

void re(int i,int l,int r,int L,int R){
    if(l > R||r < L)return;
    if(!i)return;
    if(l >= L&&r <= R){
        update(i,l,r);
        return;
    }
    down(i,l,r);
    re(u.l,l,mid,L,R);
    re(u.r,mid+1,r,L,R);
    up(i);
}

int qu(int i,int l,int r,int L,int R,int fl){
    if(l > R||r < L)return 0;
    if(!i)return 0;
    if(l >= L&&r <= R){
        if(fl == 1)return u.s1;
        else return u.s0;
    }
    down(i,l,r);
    int res = qu(u.l,l,mid,L,R,fl)+qu(u.r,mid+1,r,L,R,fl);
    up(i);
    return res;
}

const int mod = 998244353;
void solve(int n)
{
    int q,root = 0;
    cnt = 0;
    cin>>q>>s1;
    build(root,1,n);
    int s1 = qu(root,1,n,1,3,0);
    //cout<<" s1 = "<<s1<<endl;
    while(q--){
        int l,r;
        cin>>l>>r;
        re(root,1,n,l,r);
        int k = tr[root].cn1;
        int s1 = qu(root,1,n,k+1,n,1);
        int s0 = qu(root,1,n,1,k-1,0);
        //cout<<"k = "<<k<<" s1 = "<<s1<<" s0 = "<<s0<<endl;
        if(qu(root,1,n,k,k,1) == k){
            cout<<(s1-s0+k)%mod<<endl;
        }
        else {
            cout<<(s1-s0)%mod<<endl;
        }
    }
}

signed main()
{
    #ifdef ONLINE_JUDGE
    ios::sync_with_stdio(0);
    cin.tie(0),cout.tie(0);
    #endif
    int _=1;
    while(cin>>_) solve(_);
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 3616kb

input:

1 1
0
1 1

output:

1

result:

ok single line: '1'

Test #3:

score: -100
Wrong Answer
time: 33ms
memory: 3680kb

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
2
1
2
0
1
0
1
2
0
0
2
0
1
2
0
1
2
1
0
1
2
1
0
0
1
2
2
1
0
1
2
2
2
1
0
1
0
0
1
0
1
0
2
2
1
0
1
2
1
1
0
2
0
2
2
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
2
0
1
0
0
1
1
0
1
0
1
2
0
2
1
0
0
2
1
2
0
1
2
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
2
1
0
2
0
1
0
1
...

result:

wrong answer 2nd lines differ - expected: '3', found: '2'