Submission #503348

# Submission time Handle Problem Language Result Execution time Memory
503348 2022-01-07T17:10:07 Z amunduzbaev Bubble Sort 2 (JOI18_bubblesort2) C++14
100 / 100
2943 ms 104148 KB
#include "bubblesort2.h"
#include "bits/stdc++.h"
using namespace std;
#ifndef EVAL
#include "grader.cpp"
#endif

#define ar array
//~ #define int long long

const int N = 1e6 + 5;

struct ST{
	int tree[1 << 21], p[1 << 21];
	
	void push(int x, int lx, int rx){
		if(lx == rx || !p[x]) return;
		tree[x<<1] += p[x], tree[x<<1|1] += p[x];
		p[x<<1] += p[x], p[x<<1|1] += p[x];
		p[x] = 0;
	}
	
	void add(int l, int r, int v, int lx = 0, int rx = N, int x = 1){
		if(lx > r || rx < l) return;
		if(lx >= l && rx <= r){
			tree[x] += v, p[x] += v;
			return;
		} push(x, lx, rx);
		int m = (lx + rx) >> 1;
		add(l, r, v, lx, m, x<<1), add(l, r, v, m+1, rx, x<<1|1);
		tree[x] = max(tree[x<<1], tree[x<<1|1]);
	}
}tree;

//~ #define i32 int32_t

vector<int> countScans(vector<int> X, vector<int> in, vector<int> Y){
	vector<long long> a, val;
	for(auto x : X) a.push_back(x);
	for(auto x : Y) val.push_back(x);
	int n = (int)a.size(), q = (int)in.size();
	map<long long, int> mm;
	
	for(int i=0;i<n;i++) a[i] = a[i] * 1ll * n + i, mm[a[i]];
	for(int i=0;i<q;i++) val[i] = val[i] * 1ll * n + in[i], mm[val[i]];
	
	{
		int in = 0;
		for(auto& x : mm) x.second = in++;
		for(int i=0;i<n;i++) a[i] = mm[a[i]];
		for(int i=0;i<q;i++) val[i] = mm[val[i]];
	}
	
	for(int i=0;i<n;i++) tree.add(a[i], a[i], i), tree.add(a[i] + 1, N, -1);
	vector<int> res;
	for(int j=0;j<q;j++){
		int i = in[j], v = val[j];
		tree.add(a[i] + 1, N, +1);
		tree.add(a[i], a[i], -i);
		a[i] = v;
		tree.add(a[i], a[i], i);
		tree.add(a[i] + 1, N, -1);
		
		res.push_back(tree.tree[1]);
	} return res;
}

/*

4 2
1 2 3 4
0 3
2 1

*/
# Verdict Execution time Memory Grader output
1 Correct 2 ms 460 KB Output is correct
2 Correct 2 ms 588 KB Output is correct
3 Correct 5 ms 824 KB Output is correct
4 Correct 5 ms 844 KB Output is correct
5 Correct 5 ms 844 KB Output is correct
6 Correct 5 ms 844 KB Output is correct
7 Correct 9 ms 860 KB Output is correct
8 Correct 5 ms 844 KB Output is correct
9 Correct 5 ms 844 KB Output is correct
10 Correct 6 ms 804 KB Output is correct
11 Correct 5 ms 716 KB Output is correct
12 Correct 7 ms 716 KB Output is correct
13 Correct 5 ms 716 KB Output is correct
14 Correct 5 ms 716 KB Output is correct
15 Correct 4 ms 720 KB Output is correct
16 Correct 4 ms 728 KB Output is correct
17 Correct 4 ms 696 KB Output is correct
18 Correct 4 ms 716 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 460 KB Output is correct
2 Correct 2 ms 588 KB Output is correct
3 Correct 5 ms 824 KB Output is correct
4 Correct 5 ms 844 KB Output is correct
5 Correct 5 ms 844 KB Output is correct
6 Correct 5 ms 844 KB Output is correct
7 Correct 9 ms 860 KB Output is correct
8 Correct 5 ms 844 KB Output is correct
9 Correct 5 ms 844 KB Output is correct
10 Correct 6 ms 804 KB Output is correct
11 Correct 5 ms 716 KB Output is correct
12 Correct 7 ms 716 KB Output is correct
13 Correct 5 ms 716 KB Output is correct
14 Correct 5 ms 716 KB Output is correct
15 Correct 4 ms 720 KB Output is correct
16 Correct 4 ms 728 KB Output is correct
17 Correct 4 ms 696 KB Output is correct
18 Correct 4 ms 716 KB Output is correct
19 Correct 17 ms 2020 KB Output is correct
20 Correct 21 ms 2216 KB Output is correct
21 Correct 20 ms 2252 KB Output is correct
22 Correct 20 ms 2236 KB Output is correct
23 Correct 18 ms 1996 KB Output is correct
24 Correct 19 ms 1988 KB Output is correct
25 Correct 18 ms 1956 KB Output is correct
26 Correct 18 ms 1988 KB Output is correct
27 Correct 18 ms 1980 KB Output is correct
28 Correct 18 ms 1860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 37 ms 3312 KB Output is correct
2 Correct 79 ms 7096 KB Output is correct
3 Correct 149 ms 11152 KB Output is correct
4 Correct 186 ms 11164 KB Output is correct
5 Correct 156 ms 11068 KB Output is correct
6 Correct 141 ms 10976 KB Output is correct
7 Correct 139 ms 10940 KB Output is correct
8 Correct 153 ms 10968 KB Output is correct
9 Correct 140 ms 11008 KB Output is correct
10 Correct 133 ms 7688 KB Output is correct
11 Correct 108 ms 7652 KB Output is correct
12 Correct 125 ms 7796 KB Output is correct
13 Correct 106 ms 7700 KB Output is correct
14 Correct 105 ms 7716 KB Output is correct
15 Correct 116 ms 7696 KB Output is correct
16 Correct 108 ms 7740 KB Output is correct
17 Correct 102 ms 7724 KB Output is correct
18 Correct 100 ms 7748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 460 KB Output is correct
2 Correct 2 ms 588 KB Output is correct
3 Correct 5 ms 824 KB Output is correct
4 Correct 5 ms 844 KB Output is correct
5 Correct 5 ms 844 KB Output is correct
6 Correct 5 ms 844 KB Output is correct
7 Correct 9 ms 860 KB Output is correct
8 Correct 5 ms 844 KB Output is correct
9 Correct 5 ms 844 KB Output is correct
10 Correct 6 ms 804 KB Output is correct
11 Correct 5 ms 716 KB Output is correct
12 Correct 7 ms 716 KB Output is correct
13 Correct 5 ms 716 KB Output is correct
14 Correct 5 ms 716 KB Output is correct
15 Correct 4 ms 720 KB Output is correct
16 Correct 4 ms 728 KB Output is correct
17 Correct 4 ms 696 KB Output is correct
18 Correct 4 ms 716 KB Output is correct
19 Correct 17 ms 2020 KB Output is correct
20 Correct 21 ms 2216 KB Output is correct
21 Correct 20 ms 2252 KB Output is correct
22 Correct 20 ms 2236 KB Output is correct
23 Correct 18 ms 1996 KB Output is correct
24 Correct 19 ms 1988 KB Output is correct
25 Correct 18 ms 1956 KB Output is correct
26 Correct 18 ms 1988 KB Output is correct
27 Correct 18 ms 1980 KB Output is correct
28 Correct 18 ms 1860 KB Output is correct
29 Correct 37 ms 3312 KB Output is correct
30 Correct 79 ms 7096 KB Output is correct
31 Correct 149 ms 11152 KB Output is correct
32 Correct 186 ms 11164 KB Output is correct
33 Correct 156 ms 11068 KB Output is correct
34 Correct 141 ms 10976 KB Output is correct
35 Correct 139 ms 10940 KB Output is correct
36 Correct 153 ms 10968 KB Output is correct
37 Correct 140 ms 11008 KB Output is correct
38 Correct 133 ms 7688 KB Output is correct
39 Correct 108 ms 7652 KB Output is correct
40 Correct 125 ms 7796 KB Output is correct
41 Correct 106 ms 7700 KB Output is correct
42 Correct 105 ms 7716 KB Output is correct
43 Correct 116 ms 7696 KB Output is correct
44 Correct 108 ms 7740 KB Output is correct
45 Correct 102 ms 7724 KB Output is correct
46 Correct 100 ms 7748 KB Output is correct
47 Correct 677 ms 32380 KB Output is correct
48 Correct 2780 ms 95416 KB Output is correct
49 Correct 2938 ms 104040 KB Output is correct
50 Correct 2935 ms 104116 KB Output is correct
51 Correct 2898 ms 104144 KB Output is correct
52 Correct 2927 ms 104088 KB Output is correct
53 Correct 2943 ms 104148 KB Output is correct
54 Correct 2646 ms 103972 KB Output is correct
55 Correct 2880 ms 104104 KB Output is correct
56 Correct 2594 ms 103844 KB Output is correct
57 Correct 2850 ms 103820 KB Output is correct
58 Correct 2620 ms 103848 KB Output is correct
59 Correct 2396 ms 94024 KB Output is correct
60 Correct 2454 ms 93864 KB Output is correct
61 Correct 2414 ms 93876 KB Output is correct
62 Correct 2364 ms 88984 KB Output is correct
63 Correct 2325 ms 88788 KB Output is correct
64 Correct 2299 ms 88880 KB Output is correct
65 Correct 2206 ms 83708 KB Output is correct
66 Correct 2215 ms 83400 KB Output is correct
67 Correct 2211 ms 83328 KB Output is correct