Submission #251589

# Submission time Handle Problem Language Result Execution time Memory
251589 2020-07-21T20:14:30 Z test2 Bubble Sort 2 (JOI18_bubblesort2) C++14
100 / 100
3907 ms 210368 KB
#include<bits/stdc++.h>
#include "bubblesort2.h"
 
using namespace std ; 

const int N = 1e6 + 7 ;  
int n; 

int tree[N * 4] , lazy[N * 4] ; 
set<int> ixs[N]; 

void update(int node , int L , int R , int l , int r , int val){
        if(l > R || r < L || l > r)
                return ; 

        if(L>=l && R<=r){
                lazy[node] += val ; 
                return ; 
        }
        int mid = (L + R) >>1  ; 

        update(node*2+1 , L , mid , l , r , val) ; 
        update(node*2+2 , mid+1 , R , l , r, val) ; 
        tree[node] = max(tree[node *2 +1] + lazy[node*2+1] , tree[node*2+2] + lazy[node *2+2] ); 
}

int query(int node , int L , int R , int l , int r ){
        if(l > R || r < L || l > r)
                return -N ; 
        if(L>=l && R<=r)
                return tree[node] + lazy[node]; 
        int mid = (L+R) >> 1 ; 
        int s1 = query(node*2+1 , L , mid , l , r) ; 
        int s2 = query(node*2+2 , mid+1 , R , l , r ) ; 
        return max(s1 , s2) + lazy[node] ; 
}
int js[N] ; 

void add(int ix , int val){
        ixs[ix].insert(val) ; 
        auto u = ixs[ix].end() ; u -- ; 
        int mx = *u ; 
        update(0 , 1, N , ix , ix , mx - js[ix]) ;
        js[ix] = mx ; 
}

void del(int ix , int val){
        ixs[ix].erase(ixs[ix].find(val)) ; 
        auto u = ixs[ix].end() ; u -- ;
        int mx = *u ; 
        update(0 , 1 , N , ix , ix , mx - js[ix]) ; 
        js[ix] = mx ;         
}

unordered_map<int , int > com ; 
vector<int> aux ; 

std::vector<int> countScans(std::vector<int> A,std::vector<int> X,std::vector<int> V){

	int Q=X.size();
        n = (int) A.size() ; 
	std::vector<int> answer(Q);

        for(auto u : A)
                aux.push_back(u) ; 
        for(auto u : V)
                aux.push_back(u) ; 
        sort(aux.begin() , aux.end()) ; 
        int l = 0 , now = 0 ;
        for(int i = 0 ;i < (int) aux.size() ;i++){
                if(aux[i] > l)
                        now ++ ; 
                com[aux[i]] = now ; 
                l = aux[i] ;
        }
        for(int i = 0 ; i < n; i++){
                A[i] = com[A[i]] ; 
        }
        for(int i = 0 ;i < Q ;i++){
                V[i] = com[V[i]] ; 
        }

        for(int i = 1 ;i<=now ; i++){
                add(i , -N  ) ; 
        }

        for(int i = 0 ; i < n; i++){
                add(A[i] , i) ; 
                update( 0 , 1 , N , A[i] , now  , -1) ; 
        }

	for (int j=0;j<Q;j++) {
                del(A[X[j]] , X[j]) ; 
                add(V[j] , X[j]) ; 
                if(V[j] >=A[X[j]]){
                        update( 0 , 1 , N , A[X[j]]  , V[j] -1 , +1) ;                 
                }
                else{
                        update( 0 , 1 ,N , V[j]  , A[X[j]] -1  , -1) ; 
                }
		A[ X[j] ] = V[ j ] ; 

                answer[j] =  query(0 , 1 , N , 1 , now  ) +1; 
                answer[j] = max(answer[j] , -100) ; 

	}
	return answer;
}
# Verdict Execution time Memory Grader output
1 Correct 26 ms 47616 KB Output is correct
2 Correct 28 ms 47616 KB Output is correct
3 Correct 31 ms 48000 KB Output is correct
4 Correct 31 ms 48000 KB Output is correct
5 Correct 33 ms 47992 KB Output is correct
6 Correct 31 ms 48000 KB Output is correct
7 Correct 31 ms 47992 KB Output is correct
8 Correct 32 ms 48000 KB Output is correct
9 Correct 41 ms 47992 KB Output is correct
10 Correct 31 ms 48000 KB Output is correct
11 Correct 31 ms 47992 KB Output is correct
12 Correct 31 ms 48000 KB Output is correct
13 Correct 30 ms 47864 KB Output is correct
14 Correct 30 ms 47872 KB Output is correct
15 Correct 39 ms 47864 KB Output is correct
16 Correct 34 ms 47872 KB Output is correct
17 Correct 30 ms 47872 KB Output is correct
18 Correct 30 ms 47872 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 47616 KB Output is correct
2 Correct 28 ms 47616 KB Output is correct
3 Correct 31 ms 48000 KB Output is correct
4 Correct 31 ms 48000 KB Output is correct
5 Correct 33 ms 47992 KB Output is correct
6 Correct 31 ms 48000 KB Output is correct
7 Correct 31 ms 47992 KB Output is correct
8 Correct 32 ms 48000 KB Output is correct
9 Correct 41 ms 47992 KB Output is correct
10 Correct 31 ms 48000 KB Output is correct
11 Correct 31 ms 47992 KB Output is correct
12 Correct 31 ms 48000 KB Output is correct
13 Correct 30 ms 47864 KB Output is correct
14 Correct 30 ms 47872 KB Output is correct
15 Correct 39 ms 47864 KB Output is correct
16 Correct 34 ms 47872 KB Output is correct
17 Correct 30 ms 47872 KB Output is correct
18 Correct 30 ms 47872 KB Output is correct
19 Correct 54 ms 49580 KB Output is correct
20 Correct 54 ms 49784 KB Output is correct
21 Correct 52 ms 49784 KB Output is correct
22 Correct 61 ms 49784 KB Output is correct
23 Correct 50 ms 49656 KB Output is correct
24 Correct 50 ms 49660 KB Output is correct
25 Correct 55 ms 49444 KB Output is correct
26 Correct 59 ms 49528 KB Output is correct
27 Correct 52 ms 49272 KB Output is correct
28 Correct 54 ms 49272 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 55 ms 49112 KB Output is correct
2 Correct 115 ms 50420 KB Output is correct
3 Correct 158 ms 51568 KB Output is correct
4 Correct 161 ms 51516 KB Output is correct
5 Correct 160 ms 51568 KB Output is correct
6 Correct 156 ms 51568 KB Output is correct
7 Correct 156 ms 51440 KB Output is correct
8 Correct 155 ms 51568 KB Output is correct
9 Correct 158 ms 51568 KB Output is correct
10 Correct 133 ms 51568 KB Output is correct
11 Correct 137 ms 51568 KB Output is correct
12 Correct 135 ms 51696 KB Output is correct
13 Correct 132 ms 51440 KB Output is correct
14 Correct 131 ms 51568 KB Output is correct
15 Correct 132 ms 51440 KB Output is correct
16 Correct 132 ms 51696 KB Output is correct
17 Correct 127 ms 51568 KB Output is correct
18 Correct 129 ms 51440 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 26 ms 47616 KB Output is correct
2 Correct 28 ms 47616 KB Output is correct
3 Correct 31 ms 48000 KB Output is correct
4 Correct 31 ms 48000 KB Output is correct
5 Correct 33 ms 47992 KB Output is correct
6 Correct 31 ms 48000 KB Output is correct
7 Correct 31 ms 47992 KB Output is correct
8 Correct 32 ms 48000 KB Output is correct
9 Correct 41 ms 47992 KB Output is correct
10 Correct 31 ms 48000 KB Output is correct
11 Correct 31 ms 47992 KB Output is correct
12 Correct 31 ms 48000 KB Output is correct
13 Correct 30 ms 47864 KB Output is correct
14 Correct 30 ms 47872 KB Output is correct
15 Correct 39 ms 47864 KB Output is correct
16 Correct 34 ms 47872 KB Output is correct
17 Correct 30 ms 47872 KB Output is correct
18 Correct 30 ms 47872 KB Output is correct
19 Correct 54 ms 49580 KB Output is correct
20 Correct 54 ms 49784 KB Output is correct
21 Correct 52 ms 49784 KB Output is correct
22 Correct 61 ms 49784 KB Output is correct
23 Correct 50 ms 49656 KB Output is correct
24 Correct 50 ms 49660 KB Output is correct
25 Correct 55 ms 49444 KB Output is correct
26 Correct 59 ms 49528 KB Output is correct
27 Correct 52 ms 49272 KB Output is correct
28 Correct 54 ms 49272 KB Output is correct
29 Correct 55 ms 49112 KB Output is correct
30 Correct 115 ms 50420 KB Output is correct
31 Correct 158 ms 51568 KB Output is correct
32 Correct 161 ms 51516 KB Output is correct
33 Correct 160 ms 51568 KB Output is correct
34 Correct 156 ms 51568 KB Output is correct
35 Correct 156 ms 51440 KB Output is correct
36 Correct 155 ms 51568 KB Output is correct
37 Correct 158 ms 51568 KB Output is correct
38 Correct 133 ms 51568 KB Output is correct
39 Correct 137 ms 51568 KB Output is correct
40 Correct 135 ms 51696 KB Output is correct
41 Correct 132 ms 51440 KB Output is correct
42 Correct 131 ms 51568 KB Output is correct
43 Correct 132 ms 51440 KB Output is correct
44 Correct 132 ms 51696 KB Output is correct
45 Correct 127 ms 51568 KB Output is correct
46 Correct 129 ms 51440 KB Output is correct
47 Correct 848 ms 91704 KB Output is correct
48 Correct 3017 ms 184532 KB Output is correct
49 Correct 3301 ms 210220 KB Output is correct
50 Correct 3287 ms 210084 KB Output is correct
51 Correct 3513 ms 210256 KB Output is correct
52 Correct 3549 ms 210244 KB Output is correct
53 Correct 3305 ms 210120 KB Output is correct
54 Correct 3104 ms 210236 KB Output is correct
55 Correct 3907 ms 210368 KB Output is correct
56 Correct 3623 ms 210244 KB Output is correct
57 Correct 3785 ms 210184 KB Output is correct
58 Correct 3724 ms 210228 KB Output is correct
59 Correct 2950 ms 190032 KB Output is correct
60 Correct 3087 ms 190052 KB Output is correct
61 Correct 2669 ms 189960 KB Output is correct
62 Correct 2766 ms 183888 KB Output is correct
63 Correct 2722 ms 184052 KB Output is correct
64 Correct 2758 ms 183880 KB Output is correct
65 Correct 2549 ms 177900 KB Output is correct
66 Correct 2484 ms 177992 KB Output is correct
67 Correct 2499 ms 177992 KB Output is correct