QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#158005#7108. Couleurucup-team956#AC ✓1864ms50540kbC++202.5kb2023-09-02 16:07:082023-09-02 16:07:08

Judging History

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

  • [2023-09-02 16:07:08]
  • 评测
  • 测评结果:AC
  • 用时:1864ms
  • 内存:50540kb
  • [2023-09-02 16:07:08]
  • 提交

answer

#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=a;i<=b;++i)
#define int long long
using namespace std;
const int _=1e5+7;
int n,a[_];
namespace TREE {
    #define ls(x) e[x].l
    #define rs(x) e[x].r
    struct node {int l,r,siz;}e[_*22];
    int cnt;
    void insert(int l,int r,int L,int x,int &y) {
        e[y=++cnt]=e[x];
        e[y].siz++;
        if(l==r) return;
        int mid=(l+r)>>1;
        if(L<=mid) insert(l,mid,L,ls(x),ls(y));
        else insert(mid+1,r,L,rs(x),rs(y));
    }
    int query(int l,int r,int L,int R,int x,int y) {
        if(L>R) return 0;
        if(L<=l&&r<=R) return e[y].siz-e[x].siz;
        int mid=(l+r)>>1,ans=0;
        if(L<=mid) ans+=query(l,mid,L,R,ls(x),ls(y));
        if(R>mid) ans+=query(mid+1,r,L,R,rs(x),rs(y));
        return ans;
    }
}
void solve() {
    TREE::cnt=0;
    cin>>n;
    vector<int> rt(n+1);
    FOR(i,1,n) {
        cin>>a[i];
        TREE::insert(1,n,a[i],rt[i-1],rt[i]);
    }
    int last_ans=0;
    FOR(i,1,n) last_ans+=TREE::query(1,n,1,a[i]-1,rt[i],rt[n]);
    multiset<int> S;
    multiset<array<int,3>> T;
    S.insert(last_ans);
    T.insert({n,1,last_ans});
    FOR(TTT,1,n) {
        last_ans=(*S.rbegin());
        cout<<last_ans<<" \n"[TTT==n];

        int x;
        cin>>x;
        x=x^last_ans;
        
        auto [r,l,tot]=*T.lower_bound({x,0,0});


        T.erase(T.lower_bound({x,0,0}));
        S.erase(S.find(tot));
        if(l<=x-1) tot-=TREE::query(1,n,a[x]+1,n,rt[l-1],rt[x-1]);
        if(x+1<=r) tot-=TREE::query(1,n,1,a[x]-1,rt[x],rt[r]);

        if(r-x < x-l)  {
            int res=0;
            FOR(i,x+1,r) {
                res+=TREE::query(1,n,1,a[i]-1,rt[i],rt[r]);
                if(l<=x-1) tot-=TREE::query(1,n,a[i]+1,n,rt[l-1],rt[x-1]);
            }

            if(l<=x-1) S.insert(tot-res),T.insert({x-1,l,tot-res});
            if(x+1<=r) S.insert(res),T.insert({r,x+1,res});
        } else {
            int res=0;
            FOR(i,l,x-1) {
                res+=TREE::query(1,n,1,a[i]-1,rt[i],rt[x-1]);
                if(x+1<=r) tot-=TREE::query(1,n,1,a[i]-1,rt[x],rt[r]);
            }

            if(l<=x-1) S.insert(res),T.insert({x-1,l,res});
            if(x+1<=r) S.insert(tot-res),T.insert({r,x+1,tot-res});
        }

    }
}
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int T;
    cin>>T;
    while(T--) {
        solve();
    }   
    return 0;
}

这程序好像有点Bug,我给组数据试试?

详细

Test #1:

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

input:

3
5
4 3 1 1 1
5 4 5 3 1
10
9 7 1 4 7 8 5 7 4 8
21 8 15 5 9 2 4 5 10 6
15
4 8 8 1 12 1 10 14 7 14 2 9 13 10 3
37 19 23 15 7 2 10 15 2 13 4 5 8 7 10

output:

7 0 0 0 0
20 11 7 2 0 0 0 0 0 0
42 31 21 14 14 4 1 1 1 0 0 0 0 0 0

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 1864ms
memory: 50540kb

input:

11116
10
10 5 10 3 6 4 8 5 9 8
31 27 24 11 12 3 0 2 3 1
10
8 2 7 2 8 10 1 10 9 10
6 5 2 13 2 1 0 1 3 1
10
7 10 7 6 1 3 10 6 7 9
21 18 10 1 6 5 4 8 9 10
10
2 10 4 8 8 5 7 2 6 7
20 10 9 1 15 0 4 2 9 7
10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
10
1 2 3 4 5 6 7 8 9 10
6 3 5 2 7 10 9 1 4 8
10
1 10 1 3...

output:

21 18 16 12 10 6 4 1 1 0
12 12 10 10 4 4 4 2 1 0
20 16 9 5 3 3 3 0 0 0
22 14 8 8 5 5 2 1 1 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
19 12 7 4 4 2 2 1 0 0
20 18 8 3 1 1 0 0 0 0
45 21 21 10 3 3 3 0 0 0
17 11 8 2 1 1 1 0 0 0
13 4 1 0 0 0 0 0 0 0
29 27 22 15 9 7 4 3 1 0
26 16 9 2 1 1 1 1 1 0
0 0 0 0 0 ...

result:

ok 11116 lines

Extra Test:

score: 0
Extra Test Passed