QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#788501#9802. Light Up the Gridlilab#TL 0ms0kbC++201.5kb2024-11-27 17:12:562024-11-27 17:12:56

Judging History

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

  • [2024-11-27 17:12:56]
  • 评测
  • 测评结果:TL
  • 用时:0ms
  • 内存:0kb
  • [2024-11-27 17:12:56]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
using ll=long long;

const ll N=5e5+100;

ll s[N],n,a[N],b[N];

ll lowbit(ll x){
    return x&(-x);
}

void update(ll p,ll x){
    for(int i=p;i<=n;i+=lowbit(i))s[i]+=x;
}

ll query(ll p){
    ll ret=0;
    for(int i=p;i;i-=lowbit(i))ret+=s[i];
    return ret;
}

ll ask(ll l,ll r){
    return query(r)-query(l-1);
}

void solve(){
    cin>>n;
    for(int i=1;i<=n;i++)cin>>a[i];
    for(int i=1;i<=n;i++)cin>>b[i];
    string ans="";
    ll cnta=0,cntb=0,ba=0,bb=0;
    for(int i=1;i<=n;i++)s[i]=0;
    for(int i=1;i<=n;i++){
        cnta+=ask(a[i]+1,n);
        update(a[i],1);
    }
    for(int i=1;i<=n;i++)s[i]=0;
    for(int i=1;i<=n;i++){
        cntb+=ask(b[i]+1,n);
        update(b[i],1);
    }
    ba=cnta&1;bb=cntb&1;
    if(ba^bb)ans+="A";
    else ans+="B";
    for(int i=1;i<n;i++){
        char t;
        ll l,r,d;
        cin>>t>>l>>r>>d;
        d%=(r-l+1);
        if(t=='A'){
            ba^=(d*(r-l+1-d))&1;
        }else{
            bb^=(d*(r-l+1-d))&1;
        }
        if(ba^bb)ans+="A";
        else ans+="B";
    }
    cout<<ans<<'\n';

}

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int t_=1;
    cin>>t_;
    while(t_--)solve();
}
/*
5
3
1 2 3
1 2 3
A 1 1 1
B 1 1 1
3
1 2 3
2 1 3
A 1 2 1
B 2 2 1
3
1 2 3
2 1 3
A 1 3 1
B 1 2 1
3
1 2 3
3 2 1
A 2 2 1
B 2 3 1
10
1 2 3 4 5 6 7 8 9 10
4 2 3 9 6 1 5 8 7 10
A 2 9 10
B 2 7 9
A 1 10 8
B 4 6 7
B 3 10 6
A 2 5 5
A 8 9 4
B 3 9 3
A 2 7 2

*/

详细

Test #1:

score: 0
Time Limit Exceeded

input:

2 1000 100 10 1
4
10
00

01
00

00
10

00
01
1
11
11

output:


result: