Submission #842825

# Submission time Handle Problem Language Result Execution time Memory
842825 2023-09-03T11:53:40 Z Hakiers Bubble Sort 2 (JOI18_bubblesort2) C++17
100 / 100
3827 ms 156760 KB
#include <bits/stdc++.h>
using namespace std;
const int BASE = 1 << 20;
int TREE[BASE << 1];
int LAZY[BASE << 1];
int actsetindex[BASE];
map<int, int> mapa;
priority_queue<int> Q[BASE];

void push(int v, int l, int r){
	TREE[l] += LAZY[v];
	TREE[r] += LAZY[v];
	
	LAZY[l] += LAZY[v];
	LAZY[r] += LAZY[v];
	
	LAZY[v] = 0;

}

void update(int v, int l, int r, int a, int b, int val){
	if(r < a || b < l) return;
	else if(a <= l && r <= b){
		TREE[v] += val;
		LAZY[v] += val;
	}
	else{
		int mid = (l+r)/2;
		push(v, 2*v, 2*v+1);
		update(2*v, l, mid, a, b, val);
		update(2*v+1, mid+1, r, a, b, val);
		
		TREE[v] = max(TREE[2*v], TREE[2*v+1]);
	}
}

void scale(){
	int x = 0;
	
	for(auto it = mapa.begin(); it != mapa.end(); ++it)
		it->second = x++;

}

void repair(int val){

	if(actsetindex[Q[val].top()] == val) return;
	
 	update(1, 0, BASE-1, val, val, -Q[val].top());
	
	while(Q[val].size() && actsetindex[Q[val].top()] != val)
		Q[val].pop();
		
	if(Q[val].size())
 		update(1, 0, BASE-1, val, val, Q[val].top());
}

vector<int> countScans(vector <int> A, vector<int> X, vector<int> V){
//int main(){
	//int n, q;
	
	//cin >> n >> q;
	//vector<int> A(n, 0);
	//vector<int> X(q, 0);
	//vector<int> V(q, 0);
	
	//for(int i = 0; i < (int)A.size(); i++)
		//cin >> A[i];
	//for(int i = 0; i < (int)X.size(); i++)
		//cin >> X[i];
	//for(int i = 0; i < (int)V.size(); i++)
		//cin >> V[i];
		
	
	for(auto u : A)
		mapa[u];
		
	for(auto u : V)
		mapa[u];
	scale();
	
	for(int i = 0; i < (int)A.size(); i++)
		A[i] = mapa[A[i]];
	for(int i = 0; i < (int)V.size(); i++){
		V[i] = mapa[V[i]];
		X[i]+= 1;
	}
		
	
	
	for(int i = 0; i < (int)A.size(); i++){
		if(Q[A[i]].size())
			update(1, 0, BASE-1, A[i], A[i], -Q[A[i]].top());
		
		update(1, 0, BASE-1, A[i], A[i], i+1);
		update(1, 0, BASE-1, A[i], BASE-1, -1);
		actsetindex[i+1] = A[i];
		Q[A[i]].push(i+1);
	}
	
	//cout << max(TREE[1], 0) << endl;
	
	vector<int> res;
	
	for(int i = 0; i < (int)V.size(); i++){
		
		int idx = X[i];
		int what = actsetindex[idx];
		
		update(1, 0, BASE-1, what, BASE-1, 1);
		actsetindex[idx] = V[i];
		repair(what);
		
		
		if(Q[V[i]].size())
			update(1, 0, BASE-1, V[i], V[i], -Q[V[i]].top());
		
		
		Q[V[i]].push(idx);
		
		update(1, 0, BASE-1, V[i], V[i], Q[V[i]].top());
		update(1, 0, BASE-1, V[i], BASE-1, -1);
		
		res.push_back(max(TREE[1], 0));
		//cout << max(TREE[1], 0) << endl;	
	}
	
	return res;
	
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 43612 KB Output is correct
2 Correct 11 ms 43868 KB Output is correct
3 Correct 14 ms 44196 KB Output is correct
4 Correct 14 ms 44124 KB Output is correct
5 Correct 14 ms 44124 KB Output is correct
6 Correct 12 ms 44124 KB Output is correct
7 Correct 13 ms 44124 KB Output is correct
8 Correct 14 ms 44376 KB Output is correct
9 Correct 14 ms 44124 KB Output is correct
10 Correct 12 ms 44120 KB Output is correct
11 Correct 13 ms 44148 KB Output is correct
12 Correct 16 ms 43868 KB Output is correct
13 Correct 12 ms 43868 KB Output is correct
14 Correct 14 ms 43868 KB Output is correct
15 Correct 14 ms 43868 KB Output is correct
16 Correct 13 ms 43868 KB Output is correct
17 Correct 12 ms 43960 KB Output is correct
18 Correct 13 ms 44036 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 43612 KB Output is correct
2 Correct 11 ms 43868 KB Output is correct
3 Correct 14 ms 44196 KB Output is correct
4 Correct 14 ms 44124 KB Output is correct
5 Correct 14 ms 44124 KB Output is correct
6 Correct 12 ms 44124 KB Output is correct
7 Correct 13 ms 44124 KB Output is correct
8 Correct 14 ms 44376 KB Output is correct
9 Correct 14 ms 44124 KB Output is correct
10 Correct 12 ms 44120 KB Output is correct
11 Correct 13 ms 44148 KB Output is correct
12 Correct 16 ms 43868 KB Output is correct
13 Correct 12 ms 43868 KB Output is correct
14 Correct 14 ms 43868 KB Output is correct
15 Correct 14 ms 43868 KB Output is correct
16 Correct 13 ms 43868 KB Output is correct
17 Correct 12 ms 43960 KB Output is correct
18 Correct 13 ms 44036 KB Output is correct
19 Correct 26 ms 45128 KB Output is correct
20 Correct 29 ms 45292 KB Output is correct
21 Correct 28 ms 45312 KB Output is correct
22 Correct 28 ms 45416 KB Output is correct
23 Correct 28 ms 45140 KB Output is correct
24 Correct 27 ms 44996 KB Output is correct
25 Correct 26 ms 45148 KB Output is correct
26 Correct 26 ms 45148 KB Output is correct
27 Correct 26 ms 44884 KB Output is correct
28 Correct 37 ms 44892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 44124 KB Output is correct
2 Correct 86 ms 45048 KB Output is correct
3 Correct 127 ms 48092 KB Output is correct
4 Correct 128 ms 48216 KB Output is correct
5 Correct 120 ms 48304 KB Output is correct
6 Correct 155 ms 48360 KB Output is correct
7 Correct 118 ms 48308 KB Output is correct
8 Correct 115 ms 48272 KB Output is correct
9 Correct 109 ms 48336 KB Output is correct
10 Correct 117 ms 48336 KB Output is correct
11 Correct 109 ms 48200 KB Output is correct
12 Correct 110 ms 48336 KB Output is correct
13 Correct 124 ms 48180 KB Output is correct
14 Correct 113 ms 48200 KB Output is correct
15 Correct 127 ms 48196 KB Output is correct
16 Correct 130 ms 48076 KB Output is correct
17 Correct 120 ms 48080 KB Output is correct
18 Correct 125 ms 48164 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 43612 KB Output is correct
2 Correct 11 ms 43868 KB Output is correct
3 Correct 14 ms 44196 KB Output is correct
4 Correct 14 ms 44124 KB Output is correct
5 Correct 14 ms 44124 KB Output is correct
6 Correct 12 ms 44124 KB Output is correct
7 Correct 13 ms 44124 KB Output is correct
8 Correct 14 ms 44376 KB Output is correct
9 Correct 14 ms 44124 KB Output is correct
10 Correct 12 ms 44120 KB Output is correct
11 Correct 13 ms 44148 KB Output is correct
12 Correct 16 ms 43868 KB Output is correct
13 Correct 12 ms 43868 KB Output is correct
14 Correct 14 ms 43868 KB Output is correct
15 Correct 14 ms 43868 KB Output is correct
16 Correct 13 ms 43868 KB Output is correct
17 Correct 12 ms 43960 KB Output is correct
18 Correct 13 ms 44036 KB Output is correct
19 Correct 26 ms 45128 KB Output is correct
20 Correct 29 ms 45292 KB Output is correct
21 Correct 28 ms 45312 KB Output is correct
22 Correct 28 ms 45416 KB Output is correct
23 Correct 28 ms 45140 KB Output is correct
24 Correct 27 ms 44996 KB Output is correct
25 Correct 26 ms 45148 KB Output is correct
26 Correct 26 ms 45148 KB Output is correct
27 Correct 26 ms 44884 KB Output is correct
28 Correct 37 ms 44892 KB Output is correct
29 Correct 37 ms 44124 KB Output is correct
30 Correct 86 ms 45048 KB Output is correct
31 Correct 127 ms 48092 KB Output is correct
32 Correct 128 ms 48216 KB Output is correct
33 Correct 120 ms 48304 KB Output is correct
34 Correct 155 ms 48360 KB Output is correct
35 Correct 118 ms 48308 KB Output is correct
36 Correct 115 ms 48272 KB Output is correct
37 Correct 109 ms 48336 KB Output is correct
38 Correct 117 ms 48336 KB Output is correct
39 Correct 109 ms 48200 KB Output is correct
40 Correct 110 ms 48336 KB Output is correct
41 Correct 124 ms 48180 KB Output is correct
42 Correct 113 ms 48200 KB Output is correct
43 Correct 127 ms 48196 KB Output is correct
44 Correct 130 ms 48076 KB Output is correct
45 Correct 120 ms 48080 KB Output is correct
46 Correct 125 ms 48164 KB Output is correct
47 Correct 910 ms 81008 KB Output is correct
48 Correct 3357 ms 147332 KB Output is correct
49 Correct 3441 ms 156400 KB Output is correct
50 Correct 3827 ms 156312 KB Output is correct
51 Correct 3071 ms 156428 KB Output is correct
52 Correct 2944 ms 156496 KB Output is correct
53 Correct 2933 ms 156568 KB Output is correct
54 Correct 2745 ms 156404 KB Output is correct
55 Correct 2875 ms 156600 KB Output is correct
56 Correct 2669 ms 156760 KB Output is correct
57 Correct 2873 ms 156448 KB Output is correct
58 Correct 2684 ms 156580 KB Output is correct
59 Correct 2307 ms 144928 KB Output is correct
60 Correct 2337 ms 144944 KB Output is correct
61 Correct 2276 ms 144996 KB Output is correct
62 Correct 2239 ms 139732 KB Output is correct
63 Correct 2226 ms 139820 KB Output is correct
64 Correct 2188 ms 139644 KB Output is correct
65 Correct 2132 ms 134684 KB Output is correct
66 Correct 2102 ms 134504 KB Output is correct
67 Correct 2041 ms 134508 KB Output is correct