Submission #202097

# Submission time Handle Problem Language Result Execution time Memory
202097 2020-02-13T21:18:20 Z wilwxk Bubble Sort 2 (JOI18_bubblesort2) C++14
100 / 100
4720 ms 133064 KB
#include "bubblesort2.h"
#include <bits/stdc++.h>
using namespace std;
 
struct node {
	int mx, qtd, lz;
};
 
const int MAXN = 1e6+6;
const int INF = 5e7;
map<int, int> mp;
vector<int> ans;
int pos[MAXN];
int mpcnt[MAXN], mpaux[MAXN];
node seg[MAXN*4];
int n, q, mpn;
 
void refresh(int sind, int l, int r) {
	if(!seg[sind].lz) return;
	seg[sind].mx += seg[sind].lz;
	int val = seg[sind].lz;
	seg[sind].lz = 0;
	if(l == r) return;
	int e = sind*2; int d = e+1;
	seg[e].lz += val;
	seg[d].lz += val;
}
 
int query(int sind, int l, int r, int ql, int qr) {
	refresh(sind, l, r);
	if(ql > r || qr < l) return 0;
	if(ql <= l && qr >= r) return seg[sind].qtd;
	int m = (l+r)/2;
	int e = sind*2; int d = e+1;
	return query(e, l, m, ql, qr) + query(d, m+1, r, ql, qr);
}
 
void update1(int sind, int l, int r, int qind, int val) {
	refresh(sind, l, r);
	if(qind > r || qind < l) return;
	if(l == r) {
		seg[sind].mx = val;
		seg[sind].qtd = val != -INF;
		return;
	}
	int m = (l+r)/2;
	int e = sind*2; int d = e+1;
	update1(e, l, m, qind, val);
	update1(d, m+1, r, qind, val);
	seg[sind].mx = max(seg[e].mx, seg[d].mx);
	seg[sind].qtd = seg[e].qtd + seg[d].qtd;
}
 
void update2(int sind, int l, int r, int ql, int qr, int val) {
	refresh(sind, l, r);
	if(ql > r || qr < l) return;
	if(ql <= l && qr >= r) {
		seg[sind].lz += val;
		refresh(sind, l, r);
		return;
	}
	int m = (l+r)/2;
	int e = sind*2; int d = e+1;
	update2(e, l, m, ql, qr, val);
	update2(d, m+1, r, ql, qr, val);
	seg[sind].mx = max(seg[e].mx, seg[d].mx);
	seg[sind].qtd = seg[e].qtd + seg[d].qtd;
}
 
vector<int> countScans(vector<int> input, vector<int> qi, vector<int> qv){
	n = input.size();
	q = qi.size();
	
	for(int val : input) mp[val] = 1;
	for(int val : qv) mp[val] = 1;
	for(auto &mit : mp) mit.second = ++mpn;
	for(int &val : input) val = mp[val], mpcnt[val]++;
	for(int &val : qv) val = mp[val], mpcnt[val]++;
	for(int i = 2; i <= mpn; i++) mpcnt[i] += mpcnt[i-1];
	mpn = mpcnt[mpn];
 
	for(int i = 1; i <= 4*mpn; i++) seg[i].mx = -INF;
	for(int i = 0; i < n; i++) {
		int val = input[i];
		mpaux[val]++;
		pos[i] = mpcnt[val-1]+mpaux[val];
		int presum = query(1, 1, mpn, 1, mpcnt[val]);
		update2(1, 1, mpn, mpcnt[val-1]+1, mpn, -1);
		update1(1, 1, mpn, pos[i], i-presum);
	}
	// printf("mx %d\n", seg[1].mx);
	for(int i = 0; i < q; i++) {
		int ind = qi[i], val = qv[i];
		update2(1, 1, mpn, mpcnt[input[ind]-1]+1, mpn, 1);
		update1(1, 1, mpn, pos[ind], -INF);
		input[ind] = val;
		mpaux[val]++;
		pos[ind] = mpcnt[val-1]+mpaux[val];
		int presum = query(1, 1, mpn, 1, mpcnt[val]);
		// printf("%d: %d - %d %d >> %d\n", ind, val, pos[ind], presum, ind-presum);
		update2(1, 1, mpn, mpcnt[val-1]+1, mpn, -1);
		update1(1, 1, mpn, pos[ind], ind-presum);
		ans.push_back(seg[1].mx);
	}
 
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 6 ms 504 KB Output is correct
2 Correct 7 ms 508 KB Output is correct
3 Correct 11 ms 888 KB Output is correct
4 Correct 11 ms 1016 KB Output is correct
5 Correct 11 ms 888 KB Output is correct
6 Correct 11 ms 760 KB Output is correct
7 Correct 11 ms 888 KB Output is correct
8 Correct 12 ms 888 KB Output is correct
9 Correct 11 ms 888 KB Output is correct
10 Correct 11 ms 888 KB Output is correct
11 Correct 11 ms 892 KB Output is correct
12 Correct 11 ms 888 KB Output is correct
13 Correct 10 ms 764 KB Output is correct
14 Correct 12 ms 760 KB Output is correct
15 Correct 11 ms 760 KB Output is correct
16 Correct 10 ms 892 KB Output is correct
17 Correct 10 ms 1016 KB Output is correct
18 Correct 10 ms 888 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 504 KB Output is correct
2 Correct 7 ms 508 KB Output is correct
3 Correct 11 ms 888 KB Output is correct
4 Correct 11 ms 1016 KB Output is correct
5 Correct 11 ms 888 KB Output is correct
6 Correct 11 ms 760 KB Output is correct
7 Correct 11 ms 888 KB Output is correct
8 Correct 12 ms 888 KB Output is correct
9 Correct 11 ms 888 KB Output is correct
10 Correct 11 ms 888 KB Output is correct
11 Correct 11 ms 892 KB Output is correct
12 Correct 11 ms 888 KB Output is correct
13 Correct 10 ms 764 KB Output is correct
14 Correct 12 ms 760 KB Output is correct
15 Correct 11 ms 760 KB Output is correct
16 Correct 10 ms 892 KB Output is correct
17 Correct 10 ms 1016 KB Output is correct
18 Correct 10 ms 888 KB Output is correct
19 Correct 30 ms 2168 KB Output is correct
20 Correct 34 ms 2528 KB Output is correct
21 Correct 35 ms 2424 KB Output is correct
22 Correct 32 ms 2424 KB Output is correct
23 Correct 32 ms 2296 KB Output is correct
24 Correct 33 ms 2292 KB Output is correct
25 Correct 31 ms 2272 KB Output is correct
26 Correct 32 ms 2272 KB Output is correct
27 Correct 29 ms 2168 KB Output is correct
28 Correct 30 ms 2296 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 36 ms 2172 KB Output is correct
2 Correct 105 ms 4472 KB Output is correct
3 Correct 184 ms 7540 KB Output is correct
4 Correct 170 ms 7540 KB Output is correct
5 Correct 191 ms 7540 KB Output is correct
6 Correct 160 ms 7540 KB Output is correct
7 Correct 161 ms 7540 KB Output is correct
8 Correct 164 ms 7540 KB Output is correct
9 Correct 167 ms 7668 KB Output is correct
10 Correct 129 ms 7644 KB Output is correct
11 Correct 133 ms 7608 KB Output is correct
12 Correct 127 ms 7540 KB Output is correct
13 Correct 128 ms 7540 KB Output is correct
14 Correct 137 ms 7708 KB Output is correct
15 Correct 136 ms 7540 KB Output is correct
16 Correct 134 ms 7544 KB Output is correct
17 Correct 142 ms 7540 KB Output is correct
18 Correct 131 ms 7540 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 6 ms 504 KB Output is correct
2 Correct 7 ms 508 KB Output is correct
3 Correct 11 ms 888 KB Output is correct
4 Correct 11 ms 1016 KB Output is correct
5 Correct 11 ms 888 KB Output is correct
6 Correct 11 ms 760 KB Output is correct
7 Correct 11 ms 888 KB Output is correct
8 Correct 12 ms 888 KB Output is correct
9 Correct 11 ms 888 KB Output is correct
10 Correct 11 ms 888 KB Output is correct
11 Correct 11 ms 892 KB Output is correct
12 Correct 11 ms 888 KB Output is correct
13 Correct 10 ms 764 KB Output is correct
14 Correct 12 ms 760 KB Output is correct
15 Correct 11 ms 760 KB Output is correct
16 Correct 10 ms 892 KB Output is correct
17 Correct 10 ms 1016 KB Output is correct
18 Correct 10 ms 888 KB Output is correct
19 Correct 30 ms 2168 KB Output is correct
20 Correct 34 ms 2528 KB Output is correct
21 Correct 35 ms 2424 KB Output is correct
22 Correct 32 ms 2424 KB Output is correct
23 Correct 32 ms 2296 KB Output is correct
24 Correct 33 ms 2292 KB Output is correct
25 Correct 31 ms 2272 KB Output is correct
26 Correct 32 ms 2272 KB Output is correct
27 Correct 29 ms 2168 KB Output is correct
28 Correct 30 ms 2296 KB Output is correct
29 Correct 36 ms 2172 KB Output is correct
30 Correct 105 ms 4472 KB Output is correct
31 Correct 184 ms 7540 KB Output is correct
32 Correct 170 ms 7540 KB Output is correct
33 Correct 191 ms 7540 KB Output is correct
34 Correct 160 ms 7540 KB Output is correct
35 Correct 161 ms 7540 KB Output is correct
36 Correct 164 ms 7540 KB Output is correct
37 Correct 167 ms 7668 KB Output is correct
38 Correct 129 ms 7644 KB Output is correct
39 Correct 133 ms 7608 KB Output is correct
40 Correct 127 ms 7540 KB Output is correct
41 Correct 128 ms 7540 KB Output is correct
42 Correct 137 ms 7708 KB Output is correct
43 Correct 136 ms 7540 KB Output is correct
44 Correct 134 ms 7544 KB Output is correct
45 Correct 142 ms 7540 KB Output is correct
46 Correct 131 ms 7540 KB Output is correct
47 Correct 1053 ms 39664 KB Output is correct
48 Correct 4166 ms 121580 KB Output is correct
49 Correct 4410 ms 132704 KB Output is correct
50 Correct 4560 ms 132936 KB Output is correct
51 Correct 4566 ms 132704 KB Output is correct
52 Correct 4608 ms 132844 KB Output is correct
53 Correct 4720 ms 132864 KB Output is correct
54 Correct 4177 ms 133020 KB Output is correct
55 Correct 4588 ms 132820 KB Output is correct
56 Correct 4097 ms 132804 KB Output is correct
57 Correct 4474 ms 133064 KB Output is correct
58 Correct 4144 ms 132792 KB Output is correct
59 Correct 3771 ms 124904 KB Output is correct
60 Correct 3782 ms 124840 KB Output is correct
61 Correct 3855 ms 124680 KB Output is correct
62 Correct 3753 ms 121232 KB Output is correct
63 Correct 3603 ms 121264 KB Output is correct
64 Correct 3656 ms 121268 KB Output is correct
65 Correct 3434 ms 117900 KB Output is correct
66 Correct 3531 ms 117704 KB Output is correct
67 Correct 3400 ms 117700 KB Output is correct