QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#161243#7108. Couleurucup-team139#AC ✓4269ms55112kbC++233.3kb2023-09-02 23:07:312023-09-02 23:07:31

Judging History

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

  • [2023-09-02 23:07:31]
  • 评测
  • 测评结果:AC
  • 用时:4269ms
  • 内存:55112kb
  • [2023-09-02 23:07:31]
  • 提交

answer

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

const int MAXN = 100'005, LOGN = 18;
int segcnt = 0;
struct segment {
    int l, r, lid, rid, sum;
} segs[2*(2*MAXN+2*MAXN*LOGN)];
int build(int l, int r) { //$\mathcal{O}(n)$
    if(l > r) return -1;
    int id = segcnt++;
    segs[id].l = l;
    segs[id].r = r;
    if(l == r)
        segs[id].lid = -1, segs[id].rid = -1;
    else {
        int m = (l + r) / 2;
        segs[id].lid = build(l, m);
        segs[id].rid = build(m + 1, r);
    }
    segs[id].sum = 0; //initial array has only zeroes
    return id; //return the id of the new root
}
int update(int idx, int v, int id) { //$\mathcal{O}(\log{n})$
    if(id == -1) return -1;
    if(idx < segs[id].l || idx > segs[id].r)
        return id;
    int nid = segcnt++;
    segs[nid].l = segs[id].l;
    segs[nid].r = segs[id].r;
    segs[nid].lid = update(idx, v, segs[id].lid);
    segs[nid].rid = update(idx, v, segs[id].rid);
    segs[nid].sum = segs[id].sum + v; // point update
    return nid; //return the id of the new root
}
int query(int id, int l, int r) { //$\mathcal{O}(\log{n})$
    if(r < segs[id].l || segs[id].r < l) return 0;
    if(l <= segs[id].l && segs[id].r <= r)
        return segs[id].sum;
    return query(segs[id].lid, l, r) +
    query(segs[id].rid, l, r); // sum query
}

int n;
int id[MAXN];

int f(int l,int r,int low,int up){//num of elem low<=x<=up in [l,r]
    if(l>r || low>up)return 0;
    return query(id[r],low,up)-query(id[l-1],low,up);
}

void solve(int t){
    cin>>n;
    
    segcnt = 0;
    id[0]=build(1,n);
    
    vector<int> a(n+1);
    for(int i=1;i<=n;i++){
        cin>>a[i];
        id[i]=update(a[i],1,id[i-1]);
    }
    
    multiset<long long> pq;
    long long st=0;
    for(int i=1;i<n;i++){
        st+=f(i+1,n,1,a[i]-1);
        //cout<<f(i+1,n,1,a[i]-1)<<" ecco\n";
    }
    set<pair<int,long long>> block = {{0,st},{n+1,0}};
    pq.insert(st);
    cout<<st<<" ";
    
    long long last=st;
    for(int i=0;i<n;i++){
        long long p;
        cin>>p;
        p^=last;
        if(i+1==n)break;
        
        auto itr = block.lower_bound({p,0});
        auto itl = itr;
        itl--;
        
        long long val = itl->second;
        int l1=itl->first+1;
        int r1=p-1;
        int l2=p+1;
        int r2=itr->first-1;
        
        long long v1=0,v2=0,oth=0;
        
        if(r1-l1<r2-l2){
            
            for(int i=l1;i<=r1;i++){
                v1+=f(i+1,r1,1,a[i]-1);
                oth+=f(l2-1,r2,1,a[i]-1);
            }
            oth+=f(l2,r2,1,a[l2-1]-1);
            
            v2 = val-v1-oth;
        }else{
            
            for(int i=l2;i<=r2;i++){
                v2+=f(i+1,r2,1,a[i]-1);
                oth+=f(l1,r1+1,a[i]+1,n);
            }
            oth+=f(l1,r1,a[l2-1]+1,n);
            
            v1 = val-v2-oth;
        }
        
        pq.erase(pq.find(val));
        pq.insert(v1);
        pq.insert(v2);
        
        block.erase(itl);
        block.insert({l1-1,v1});
        block.insert({l2-1,v2});
        
        cout<<*pq.rbegin()<<" ";
        last=*pq.rbegin();
    }
    cout<<"\n";
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int t=1;
    cin>>t;
    for(int i=1;i<=t;i++)solve(i);
    
    return 0;
}

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

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 5756kb

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: 4269ms
memory: 55112kb

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 ...

result:

ok 11116 lines

Extra Test:

score: 0
Extra Test Passed