Submission #915102

# Submission time Handle Problem Language Result Execution time Memory
915102 2024-01-23T10:52:07 Z manizare Bubble Sort 2 (JOI18_bubblesort2) C++14
100 / 100
2464 ms 126840 KB
#include<bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#define pb push_back
#define F first
#define S second 
#define all(a) a.begin(),a.end()
#define pii pair <int,int>
#define PII pair<pii , pii>
#define ld long double
#define sz(v) (int)v.size()
#define rep(i , a , b) for(int i=a;i <= (b);i++)
#define per(i , a , b) for(int i=a;i >= (b);i--)
using namespace std ;   
const int maxn = 1e6 + 10 ,  mod = 1e9 + 7 , inf =1e9  ;
vector <int> cm ;
set <int> s[maxn] ;
int seg[4*maxn] , lz[4*maxn]  , w[maxn] ;

void shi(int p , int l , int r){
    int mid =(l+r)/2 , pl =p<<1 , pr = p<<1|1;
    seg[pl] += lz[p] ;
    seg[pr] += lz[p] ;
    lz[pl] += lz[p] ;
    lz[pr] += lz[p] ;
    lz[p] = 0;
}
void upd(int le ,int ri , int w, int p =1 , int l = 0 , int r =sz(cm)-1){
    int mid = (l+r)/2 ,pl =p<<1 ,pr =p<<1|1 ;
    if(le > r || l > ri)return ;
    if(le <= l && r <= ri){
        seg[p] += w ;
        lz[p] += w; 
        return ;
    }
    if(l!=r)shi(p,l,r);
    upd(le,ri,w,pl,l,mid);
    upd(le,ri,w,pr,mid+1,r);
    seg[p] = max(seg[pl] , seg[pr]) ;
}

int val(int x){
    if(sz(s[x]) == 0)return -inf ;
    return (*s[x].rbegin()) ;
}

vector<int> countScans(vector<int> A, vector<int> X, vector<int> V) {
    int n = sz(A) , q = sz(X);
    rep(i , 0 , n-1){
        cm.pb(A[i]) ;
    }
    rep(i,0,sz(X)-1){
        cm.pb(V[i]);
    }
    sort(all(cm));
    cm.resize(unique(all(cm)) - cm.begin()) ;
    rep(i , 0, n-1){
        A[i] =lower_bound(all(cm) , A[i]) - cm.begin() ;
        s[A[i]].insert(i) ;
        upd(A[i] , sz(cm)-1 , -1);
    }
    rep(i , 0 , sz(V)-1){
        V[i] = lower_bound(all(cm) , V[i]) - cm.begin();
    }
    rep(i , 0 , sz(cm)-1){
        w[i] = val(i) ;
        upd(i , i , w[i]) ;
    }
    vector <int> res ;
    rep(i , 0 , q-1){
        int f=  A[X[i]]; 
        upd(f , f , -w[f]) ;
        upd(V[i] , V[i] , -w[V[i]]);
        upd(f , sz(cm)-1 , 1);
        s[f].erase(X[i]) ;
        s[V[i]].insert(X[i]) ;
        w[f] = val(f);
        w[V[i]] = val(V[i]) ;
        upd(V[i] , V[i] , w[V[i]]) ;
        upd(f ,  f , w[f]);
        A[X[i]] =V[i] ;
        upd(V[i] , sz(cm)-1 , -1) ;
        res.pb(seg[1]+1) ;
    }
    return res; 
}
/*
signed main(){
    ios::sync_with_stdio(0);cin.tie(0); 
    int n , q ;
    cin >> n >> q;
    vector <int> a ;
    rep(i , 1, n){
        int x;
        cin >> x ;
        a.pb(x);
    }
    vector <int> X , V ;
    rep(i , 1, q){
        int x, v;
        cin >>x>> v ;
        X.pb(x);V.pb(v);
    }
    vector <int> ans = countScans(a,X,V) ;
    for(int x : ans){
        cout << x << "\n" ;
    }
    return 0;   
}

*/

Compilation message

bubblesort2.cpp: In function 'void shi(int, int, int)':
bubblesort2.cpp:20:9: warning: unused variable 'mid' [-Wunused-variable]
   20 |     int mid =(l+r)/2 , pl =p<<1 , pr = p<<1|1;
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 15 ms 49648 KB Output is correct
2 Correct 15 ms 49744 KB Output is correct
3 Correct 18 ms 49756 KB Output is correct
4 Correct 19 ms 49832 KB Output is correct
5 Correct 18 ms 49756 KB Output is correct
6 Correct 18 ms 51804 KB Output is correct
7 Correct 19 ms 51804 KB Output is correct
8 Correct 19 ms 51804 KB Output is correct
9 Correct 19 ms 49896 KB Output is correct
10 Correct 18 ms 49840 KB Output is correct
11 Correct 17 ms 49756 KB Output is correct
12 Correct 17 ms 49892 KB Output is correct
13 Correct 18 ms 49756 KB Output is correct
14 Correct 20 ms 50140 KB Output is correct
15 Correct 17 ms 49756 KB Output is correct
16 Correct 17 ms 49888 KB Output is correct
17 Correct 17 ms 49752 KB Output is correct
18 Correct 20 ms 49728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 49648 KB Output is correct
2 Correct 15 ms 49744 KB Output is correct
3 Correct 18 ms 49756 KB Output is correct
4 Correct 19 ms 49832 KB Output is correct
5 Correct 18 ms 49756 KB Output is correct
6 Correct 18 ms 51804 KB Output is correct
7 Correct 19 ms 51804 KB Output is correct
8 Correct 19 ms 51804 KB Output is correct
9 Correct 19 ms 49896 KB Output is correct
10 Correct 18 ms 49840 KB Output is correct
11 Correct 17 ms 49756 KB Output is correct
12 Correct 17 ms 49892 KB Output is correct
13 Correct 18 ms 49756 KB Output is correct
14 Correct 20 ms 50140 KB Output is correct
15 Correct 17 ms 49756 KB Output is correct
16 Correct 17 ms 49888 KB Output is correct
17 Correct 17 ms 49752 KB Output is correct
18 Correct 20 ms 49728 KB Output is correct
19 Correct 31 ms 50524 KB Output is correct
20 Correct 32 ms 50524 KB Output is correct
21 Correct 32 ms 52632 KB Output is correct
22 Correct 34 ms 50672 KB Output is correct
23 Correct 31 ms 50540 KB Output is correct
24 Correct 31 ms 50524 KB Output is correct
25 Correct 30 ms 50624 KB Output is correct
26 Correct 30 ms 50524 KB Output is correct
27 Correct 30 ms 50656 KB Output is correct
28 Correct 29 ms 50524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 27 ms 51292 KB Output is correct
2 Correct 58 ms 52620 KB Output is correct
3 Correct 84 ms 53960 KB Output is correct
4 Correct 95 ms 53836 KB Output is correct
5 Correct 101 ms 53960 KB Output is correct
6 Correct 88 ms 53960 KB Output is correct
7 Correct 81 ms 53884 KB Output is correct
8 Correct 82 ms 53964 KB Output is correct
9 Correct 81 ms 54004 KB Output is correct
10 Correct 68 ms 53892 KB Output is correct
11 Correct 68 ms 53964 KB Output is correct
12 Correct 71 ms 53960 KB Output is correct
13 Correct 81 ms 53904 KB Output is correct
14 Correct 67 ms 53964 KB Output is correct
15 Correct 70 ms 53960 KB Output is correct
16 Correct 68 ms 53960 KB Output is correct
17 Correct 66 ms 53896 KB Output is correct
18 Correct 65 ms 53964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 49648 KB Output is correct
2 Correct 15 ms 49744 KB Output is correct
3 Correct 18 ms 49756 KB Output is correct
4 Correct 19 ms 49832 KB Output is correct
5 Correct 18 ms 49756 KB Output is correct
6 Correct 18 ms 51804 KB Output is correct
7 Correct 19 ms 51804 KB Output is correct
8 Correct 19 ms 51804 KB Output is correct
9 Correct 19 ms 49896 KB Output is correct
10 Correct 18 ms 49840 KB Output is correct
11 Correct 17 ms 49756 KB Output is correct
12 Correct 17 ms 49892 KB Output is correct
13 Correct 18 ms 49756 KB Output is correct
14 Correct 20 ms 50140 KB Output is correct
15 Correct 17 ms 49756 KB Output is correct
16 Correct 17 ms 49888 KB Output is correct
17 Correct 17 ms 49752 KB Output is correct
18 Correct 20 ms 49728 KB Output is correct
19 Correct 31 ms 50524 KB Output is correct
20 Correct 32 ms 50524 KB Output is correct
21 Correct 32 ms 52632 KB Output is correct
22 Correct 34 ms 50672 KB Output is correct
23 Correct 31 ms 50540 KB Output is correct
24 Correct 31 ms 50524 KB Output is correct
25 Correct 30 ms 50624 KB Output is correct
26 Correct 30 ms 50524 KB Output is correct
27 Correct 30 ms 50656 KB Output is correct
28 Correct 29 ms 50524 KB Output is correct
29 Correct 27 ms 51292 KB Output is correct
30 Correct 58 ms 52620 KB Output is correct
31 Correct 84 ms 53960 KB Output is correct
32 Correct 95 ms 53836 KB Output is correct
33 Correct 101 ms 53960 KB Output is correct
34 Correct 88 ms 53960 KB Output is correct
35 Correct 81 ms 53884 KB Output is correct
36 Correct 82 ms 53964 KB Output is correct
37 Correct 81 ms 54004 KB Output is correct
38 Correct 68 ms 53892 KB Output is correct
39 Correct 68 ms 53964 KB Output is correct
40 Correct 71 ms 53960 KB Output is correct
41 Correct 81 ms 53904 KB Output is correct
42 Correct 67 ms 53964 KB Output is correct
43 Correct 70 ms 53960 KB Output is correct
44 Correct 68 ms 53960 KB Output is correct
45 Correct 66 ms 53896 KB Output is correct
46 Correct 65 ms 53964 KB Output is correct
47 Correct 579 ms 77620 KB Output is correct
48 Correct 2266 ms 120416 KB Output is correct
49 Correct 2381 ms 126320 KB Output is correct
50 Correct 2446 ms 126332 KB Output is correct
51 Correct 2420 ms 126736 KB Output is correct
52 Correct 2464 ms 126544 KB Output is correct
53 Correct 2426 ms 126272 KB Output is correct
54 Correct 2201 ms 126440 KB Output is correct
55 Correct 2329 ms 126516 KB Output is correct
56 Correct 2106 ms 126840 KB Output is correct
57 Correct 2238 ms 126820 KB Output is correct
58 Correct 2060 ms 126576 KB Output is correct
59 Correct 1878 ms 124732 KB Output is correct
60 Correct 1853 ms 124748 KB Output is correct
61 Correct 1837 ms 125116 KB Output is correct
62 Correct 1744 ms 124384 KB Output is correct
63 Correct 1830 ms 124600 KB Output is correct
64 Correct 1797 ms 124500 KB Output is correct
65 Correct 1597 ms 124108 KB Output is correct
66 Correct 1624 ms 124028 KB Output is correct
67 Correct 1635 ms 123912 KB Output is correct