Submission #445815

# Submission time Handle Problem Language Result Execution time Memory
445815 2021-07-19T17:05:42 Z julian33 Bubble Sort 2 (JOI18_bubblesort2) C++14
100 / 100
2560 ms 61248 KB
#include <bits/stdc++.h>
 
 
using namespace std;
 
#ifdef LOCAL
#define deb(...) logger(#__VA_ARGS__, __VA_ARGS__)
template<typename ...Args>
void logger(string vars, Args&&... values) {
    cerr<<vars<<" = ";
    string delim="";
    (...,(cerr<<delim<<values,delim=", "));
    cerr<<"\n";
}
#else
#define deb(...) logger(#__VA_ARGS__, __VA_ARGS__)
template<typename ...Args>
void logger(string vars, Args&&... values) {}
#endif
 
#define pb push_back
#define sz(x) (int)(x.size())
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<typename T> inline void maxa(T& a,T b){a=max(a,b);}
template<typename T> inline void mina(T& a,T b){a=min(a,b);} 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int mxN=1e6+5; //make sure this is right
const int mod=1e9+7;
 
int st[4*mxN];
int a[mxN],lazy[4*mxN],cnt[mxN];
 
vector<pii> all;
int get(pii x){
    return lower_bound(all.begin(),all.end(),x)-all.begin()+1;
}
 
void push(int v){
    lazy[v<<1]+=lazy[v];
    lazy[v<<1|1]+=lazy[v];
    st[v<<1]+=lazy[v];
    st[v<<1|1]+=lazy[v];
    lazy[v]=0;
}
 
void point_upd(int v,int l,int r,int ind,int val){
    if(ind<l || ind>r)
        return;
    if(l==r){
        st[v]=val;
    } else{
        int m=(l+r)>>1;
        push(v);
        point_upd(v<<1,l,m,ind,val);
        point_upd(v<<1|1,m+1,r,ind,val);
        st[v]=max(st[v<<1],st[v<<1|1]);
    }
}
 
void range_upd(int v,int l,int r,int lq,int rq,int val){
    if(lq>rq)
        return;
    if(l>=lq && r<=rq){
        st[v]+=val;
        lazy[v]+=val;
    } else{
        int m=(l+r)>>1;
        push(v);
        range_upd(v<<1,l,m,lq,min(m,rq),val);
        range_upd(v<<1|1,m+1,r,max(lq,m+1),rq,val);
        st[v]=max(st[v<<1],st[v<<1|1]);
    }
}
 
struct BIT{
    ll bit[mxN]; 
    void upd(int x,int v){while(x<mxN){bit[x]+=v;x+=x&-x;}}
    ll sum(int x){ll res=0;while(x){res+=bit[x];x-=x&-x;}return res;} 
};
 
BIT bit;
 
vector<int> countScans(vector<int> A,vector<int> X,vector<int> V){
    int n=sz(A); int q=sz(X);
    for(int i=0;i<n;i++)
        all.pb({A[i],i});
    for(int i=0;i<q;i++)
        all.pb({V[i],X[i]});
    sort(all.begin(),all.end());
    all.resize(unique(all.begin(),all.end())-all.begin());
    vector<int> ans;
    for(int i=0;i<n;i++){
        A[i]=get({A[i],i});
        bit.upd(A[i],1);
    }
    for(int i=0;i<n;i++){
        int s=bit.sum(A[i]);
        int move=i+1-s;
        point_upd(1,1,n+q,A[i],move);
    }
    n+=q;
    for(int i=0;i<q;i++){
        V[i]=get({V[i],X[i]});
        bit.upd(A[X[i]],-1);
        point_upd(1,1,n,A[X[i]],0);
        int f=A[X[i]]; int s=V[i];
        bit.upd(s,1); int su=bit.sum(s);
        int move=X[i]+1-su;
        point_upd(1,1,n,s,move);
        if(f<s){
            range_upd(1,1,n,f+1,s-1,1);
        } else{
            range_upd(1,1,n,s+1,f-1,-1);
        }
        ans.pb(max(0,st[1]));
        A[X[i]]=s;
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 2 ms 460 KB Output is correct
3 Correct 5 ms 588 KB Output is correct
4 Correct 5 ms 588 KB Output is correct
5 Correct 5 ms 588 KB Output is correct
6 Correct 5 ms 588 KB Output is correct
7 Correct 5 ms 588 KB Output is correct
8 Correct 5 ms 588 KB Output is correct
9 Correct 5 ms 588 KB Output is correct
10 Correct 5 ms 588 KB Output is correct
11 Correct 5 ms 588 KB Output is correct
12 Correct 5 ms 604 KB Output is correct
13 Correct 5 ms 588 KB Output is correct
14 Correct 5 ms 588 KB Output is correct
15 Correct 5 ms 588 KB Output is correct
16 Correct 4 ms 588 KB Output is correct
17 Correct 4 ms 588 KB Output is correct
18 Correct 4 ms 580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 2 ms 460 KB Output is correct
3 Correct 5 ms 588 KB Output is correct
4 Correct 5 ms 588 KB Output is correct
5 Correct 5 ms 588 KB Output is correct
6 Correct 5 ms 588 KB Output is correct
7 Correct 5 ms 588 KB Output is correct
8 Correct 5 ms 588 KB Output is correct
9 Correct 5 ms 588 KB Output is correct
10 Correct 5 ms 588 KB Output is correct
11 Correct 5 ms 588 KB Output is correct
12 Correct 5 ms 604 KB Output is correct
13 Correct 5 ms 588 KB Output is correct
14 Correct 5 ms 588 KB Output is correct
15 Correct 5 ms 588 KB Output is correct
16 Correct 4 ms 588 KB Output is correct
17 Correct 4 ms 588 KB Output is correct
18 Correct 4 ms 580 KB Output is correct
19 Correct 17 ms 1308 KB Output is correct
20 Correct 21 ms 1380 KB Output is correct
21 Correct 19 ms 1340 KB Output is correct
22 Correct 23 ms 1384 KB Output is correct
23 Correct 19 ms 1328 KB Output is correct
24 Correct 19 ms 1320 KB Output is correct
25 Correct 19 ms 1304 KB Output is correct
26 Correct 24 ms 1264 KB Output is correct
27 Correct 19 ms 1228 KB Output is correct
28 Correct 18 ms 1276 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 1608 KB Output is correct
2 Correct 77 ms 3596 KB Output is correct
3 Correct 147 ms 6064 KB Output is correct
4 Correct 144 ms 6084 KB Output is correct
5 Correct 148 ms 6072 KB Output is correct
6 Correct 148 ms 6088 KB Output is correct
7 Correct 142 ms 6032 KB Output is correct
8 Correct 141 ms 6204 KB Output is correct
9 Correct 149 ms 6072 KB Output is correct
10 Correct 109 ms 4976 KB Output is correct
11 Correct 112 ms 4948 KB Output is correct
12 Correct 108 ms 4964 KB Output is correct
13 Correct 113 ms 4940 KB Output is correct
14 Correct 114 ms 5024 KB Output is correct
15 Correct 117 ms 5036 KB Output is correct
16 Correct 114 ms 4972 KB Output is correct
17 Correct 116 ms 5112 KB Output is correct
18 Correct 116 ms 4960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 332 KB Output is correct
2 Correct 2 ms 460 KB Output is correct
3 Correct 5 ms 588 KB Output is correct
4 Correct 5 ms 588 KB Output is correct
5 Correct 5 ms 588 KB Output is correct
6 Correct 5 ms 588 KB Output is correct
7 Correct 5 ms 588 KB Output is correct
8 Correct 5 ms 588 KB Output is correct
9 Correct 5 ms 588 KB Output is correct
10 Correct 5 ms 588 KB Output is correct
11 Correct 5 ms 588 KB Output is correct
12 Correct 5 ms 604 KB Output is correct
13 Correct 5 ms 588 KB Output is correct
14 Correct 5 ms 588 KB Output is correct
15 Correct 5 ms 588 KB Output is correct
16 Correct 4 ms 588 KB Output is correct
17 Correct 4 ms 588 KB Output is correct
18 Correct 4 ms 580 KB Output is correct
19 Correct 17 ms 1308 KB Output is correct
20 Correct 21 ms 1380 KB Output is correct
21 Correct 19 ms 1340 KB Output is correct
22 Correct 23 ms 1384 KB Output is correct
23 Correct 19 ms 1328 KB Output is correct
24 Correct 19 ms 1320 KB Output is correct
25 Correct 19 ms 1304 KB Output is correct
26 Correct 24 ms 1264 KB Output is correct
27 Correct 19 ms 1228 KB Output is correct
28 Correct 18 ms 1276 KB Output is correct
29 Correct 23 ms 1608 KB Output is correct
30 Correct 77 ms 3596 KB Output is correct
31 Correct 147 ms 6064 KB Output is correct
32 Correct 144 ms 6084 KB Output is correct
33 Correct 148 ms 6072 KB Output is correct
34 Correct 148 ms 6088 KB Output is correct
35 Correct 142 ms 6032 KB Output is correct
36 Correct 141 ms 6204 KB Output is correct
37 Correct 149 ms 6072 KB Output is correct
38 Correct 109 ms 4976 KB Output is correct
39 Correct 112 ms 4948 KB Output is correct
40 Correct 108 ms 4964 KB Output is correct
41 Correct 113 ms 4940 KB Output is correct
42 Correct 114 ms 5024 KB Output is correct
43 Correct 117 ms 5036 KB Output is correct
44 Correct 114 ms 4972 KB Output is correct
45 Correct 116 ms 5112 KB Output is correct
46 Correct 116 ms 4960 KB Output is correct
47 Correct 548 ms 21884 KB Output is correct
48 Correct 2318 ms 57872 KB Output is correct
49 Correct 2560 ms 61128 KB Output is correct
50 Correct 2494 ms 61060 KB Output is correct
51 Correct 2519 ms 61108 KB Output is correct
52 Correct 2471 ms 60972 KB Output is correct
53 Correct 2524 ms 61124 KB Output is correct
54 Correct 2285 ms 61140 KB Output is correct
55 Correct 2396 ms 61172 KB Output is correct
56 Correct 2238 ms 61112 KB Output is correct
57 Correct 2406 ms 61248 KB Output is correct
58 Correct 2252 ms 61236 KB Output is correct
59 Correct 2173 ms 56980 KB Output is correct
60 Correct 2149 ms 56840 KB Output is correct
61 Correct 2178 ms 56844 KB Output is correct
62 Correct 2120 ms 55332 KB Output is correct
63 Correct 2088 ms 55300 KB Output is correct
64 Correct 2116 ms 55224 KB Output is correct
65 Correct 1954 ms 53660 KB Output is correct
66 Correct 1943 ms 53684 KB Output is correct
67 Correct 1970 ms 53624 KB Output is correct