Submission #548099

# Submission time Handle Problem Language Result Execution time Memory
548099 2022-04-12T12:00:57 Z blue Bubble Sort 2 (JOI18_bubblesort2) C++17
100 / 100
4002 ms 211776 KB
#include "bubblesort2.h"
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;
 
using vi = vector<int>;
using pii = pair<int, int>;
#define sz(x) int(x.size())

set<int> inds[1'000'000];
 
struct sdata
{
	int currans;
	int count;
};
 
sdata combine(sdata X, sdata Y)
{
	sdata res;
	res.count = X.count + Y.count;
	res.currans = max(X.currans, Y.currans - X.count);
	return res;
}
 
int N, Q;
vi A;
 
struct segtree
{
	int Z;
	vi l, r;
	vector<sdata> s;
 
	void build(int i, int L, int R)
	{
		l[i] = L;
		r[i] = R;
		if(L == R)
		{
			s[i].currans = (inds[l[i]].empty() ? -3'000'000 : *inds[l[i]].rbegin());
			s[i].count = sz(inds[l[i]]);
		}
		else
		{
			int m = (L+R)/2;
			build(2*i, L, m);
			build(2*i+1, m+1, R);
			s[i] = combine(s[2*i], s[2*i+1]);
		}
 
		// cerr << L << ' ' << R << " : " << s[i].currans << ' ' << s[i].count << '\n';
	}
 
	segtree(int K)
	{
		Z = 4*K;
 
		l = r = vi(1+Z);
		s = vector<sdata>(1+Z);
 
		build(1, 0, K-1);
	}
 
	void insert(int i, int p, int id)
	{
		if(l[i] == r[i])
		{
			inds[l[i]].insert(id);
			s[i].currans = max(s[i].currans, id);
			s[i].count++;
		}
		else
		{
			if(p <= (l[i]+r[i])/2)
				insert(2*i, p, id);
			else
				insert(2*i+1, p, id);
 
			s[i] = combine(s[2*i], s[2*i+1]);
		}
 
		// cerr << l[i] << ' ' << r[i] << " : " << s[i].currans << ' ' << s[i].count << '\n';
	}
 
	void erase(int i, int p, int id)
	{
		if(l[i] == r[i])
		{
			inds[l[i]].erase(id);
			s[i].count--;
			s[i].currans = (inds[l[i]].empty() ? -3'000'000 : *inds[l[i]].rbegin());
		}
		else
		{
			if(p <= (l[i]+r[i])/2)
				erase(2*i, p, id);
			else
				erase(2*i+1, p, id);
 
			s[i] = combine(s[2*i], s[2*i+1]);
		}

		// cerr << l[i] << ' ' << r[i] << " : " << s[i].currans << ' ' << s[i].count << '\n';
	}
};
 
vi countScans(vi A_, vi X, vi V)
{
	A = A_;
	N = sz(A);
	Q = sz(X);
 
	map<pii, int> vals;
	for(int i = 0; i < N; i++)
		vals[{A[i], i}] = 0;
 
	for(int j = 0; j < Q; j++)
		vals[{V[j], X[j]}] = 0;
 
	int ct = -1;
	for(auto& z : vals)
	{
		z.second = ++ct;

		// cerr << z.first.first << " - " << z.second << '\n';
	}
 
	// cerr << "values # = " << sz(vals) << '\n';
 
	vi answer(Q);


 
 

	for(int i = 0; i < N; i++)
		inds[vals[{A[i], i}]].insert(i);

	segtree S(N+Q);
 
	// for(int i = 0; i < N; i++)
	// {
	// 	S.insert(1, vals[{A[i], i}], i);
	// }
 
	for(int j = 0; j < Q; j++)
	{
		S.erase(1, vals[{A[X[j]], X[j]}], X[j]);
		A[X[j]] = V[j];
		S.insert(1, vals[{A[X[j]], X[j]}], X[j]);
 
		answer[j] = S.s[1].currans;
	}
 
	return answer;
}
# Verdict Execution time Memory Grader output
1 Correct 23 ms 47316 KB Output is correct
2 Correct 26 ms 47464 KB Output is correct
3 Correct 30 ms 47788 KB Output is correct
4 Correct 25 ms 47888 KB Output is correct
5 Correct 25 ms 47896 KB Output is correct
6 Correct 27 ms 47820 KB Output is correct
7 Correct 28 ms 47852 KB Output is correct
8 Correct 26 ms 47924 KB Output is correct
9 Correct 26 ms 47804 KB Output is correct
10 Correct 25 ms 47828 KB Output is correct
11 Correct 27 ms 47772 KB Output is correct
12 Correct 25 ms 47828 KB Output is correct
13 Correct 28 ms 47828 KB Output is correct
14 Correct 27 ms 47820 KB Output is correct
15 Correct 27 ms 47824 KB Output is correct
16 Correct 28 ms 47792 KB Output is correct
17 Correct 26 ms 47768 KB Output is correct
18 Correct 25 ms 47828 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 47316 KB Output is correct
2 Correct 26 ms 47464 KB Output is correct
3 Correct 30 ms 47788 KB Output is correct
4 Correct 25 ms 47888 KB Output is correct
5 Correct 25 ms 47896 KB Output is correct
6 Correct 27 ms 47820 KB Output is correct
7 Correct 28 ms 47852 KB Output is correct
8 Correct 26 ms 47924 KB Output is correct
9 Correct 26 ms 47804 KB Output is correct
10 Correct 25 ms 47828 KB Output is correct
11 Correct 27 ms 47772 KB Output is correct
12 Correct 25 ms 47828 KB Output is correct
13 Correct 28 ms 47828 KB Output is correct
14 Correct 27 ms 47820 KB Output is correct
15 Correct 27 ms 47824 KB Output is correct
16 Correct 28 ms 47792 KB Output is correct
17 Correct 26 ms 47768 KB Output is correct
18 Correct 25 ms 47828 KB Output is correct
19 Correct 38 ms 49492 KB Output is correct
20 Correct 41 ms 49916 KB Output is correct
21 Correct 39 ms 49868 KB Output is correct
22 Correct 40 ms 49904 KB Output is correct
23 Correct 36 ms 49732 KB Output is correct
24 Correct 36 ms 49632 KB Output is correct
25 Correct 36 ms 49636 KB Output is correct
26 Correct 46 ms 49620 KB Output is correct
27 Correct 39 ms 49648 KB Output is correct
28 Correct 48 ms 49616 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 41 ms 52556 KB Output is correct
2 Correct 117 ms 58076 KB Output is correct
3 Correct 207 ms 63660 KB Output is correct
4 Correct 261 ms 63712 KB Output is correct
5 Correct 201 ms 63564 KB Output is correct
6 Correct 227 ms 63484 KB Output is correct
7 Correct 248 ms 63496 KB Output is correct
8 Correct 206 ms 63540 KB Output is correct
9 Correct 234 ms 63536 KB Output is correct
10 Correct 154 ms 60840 KB Output is correct
11 Correct 129 ms 60824 KB Output is correct
12 Correct 143 ms 60828 KB Output is correct
13 Correct 151 ms 60760 KB Output is correct
14 Correct 125 ms 60784 KB Output is correct
15 Correct 117 ms 60860 KB Output is correct
16 Correct 106 ms 60740 KB Output is correct
17 Correct 120 ms 60868 KB Output is correct
18 Correct 109 ms 60876 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 47316 KB Output is correct
2 Correct 26 ms 47464 KB Output is correct
3 Correct 30 ms 47788 KB Output is correct
4 Correct 25 ms 47888 KB Output is correct
5 Correct 25 ms 47896 KB Output is correct
6 Correct 27 ms 47820 KB Output is correct
7 Correct 28 ms 47852 KB Output is correct
8 Correct 26 ms 47924 KB Output is correct
9 Correct 26 ms 47804 KB Output is correct
10 Correct 25 ms 47828 KB Output is correct
11 Correct 27 ms 47772 KB Output is correct
12 Correct 25 ms 47828 KB Output is correct
13 Correct 28 ms 47828 KB Output is correct
14 Correct 27 ms 47820 KB Output is correct
15 Correct 27 ms 47824 KB Output is correct
16 Correct 28 ms 47792 KB Output is correct
17 Correct 26 ms 47768 KB Output is correct
18 Correct 25 ms 47828 KB Output is correct
19 Correct 38 ms 49492 KB Output is correct
20 Correct 41 ms 49916 KB Output is correct
21 Correct 39 ms 49868 KB Output is correct
22 Correct 40 ms 49904 KB Output is correct
23 Correct 36 ms 49732 KB Output is correct
24 Correct 36 ms 49632 KB Output is correct
25 Correct 36 ms 49636 KB Output is correct
26 Correct 46 ms 49620 KB Output is correct
27 Correct 39 ms 49648 KB Output is correct
28 Correct 48 ms 49616 KB Output is correct
29 Correct 41 ms 52556 KB Output is correct
30 Correct 117 ms 58076 KB Output is correct
31 Correct 207 ms 63660 KB Output is correct
32 Correct 261 ms 63712 KB Output is correct
33 Correct 201 ms 63564 KB Output is correct
34 Correct 227 ms 63484 KB Output is correct
35 Correct 248 ms 63496 KB Output is correct
36 Correct 206 ms 63540 KB Output is correct
37 Correct 234 ms 63536 KB Output is correct
38 Correct 154 ms 60840 KB Output is correct
39 Correct 129 ms 60824 KB Output is correct
40 Correct 143 ms 60828 KB Output is correct
41 Correct 151 ms 60760 KB Output is correct
42 Correct 125 ms 60784 KB Output is correct
43 Correct 117 ms 60860 KB Output is correct
44 Correct 106 ms 60740 KB Output is correct
45 Correct 120 ms 60868 KB Output is correct
46 Correct 109 ms 60876 KB Output is correct
47 Correct 916 ms 96536 KB Output is correct
48 Correct 3406 ms 196252 KB Output is correct
49 Correct 3853 ms 211604 KB Output is correct
50 Correct 3867 ms 211656 KB Output is correct
51 Correct 3760 ms 211688 KB Output is correct
52 Correct 4002 ms 211612 KB Output is correct
53 Correct 3999 ms 211748 KB Output is correct
54 Correct 3727 ms 211700 KB Output is correct
55 Correct 3854 ms 211668 KB Output is correct
56 Correct 3632 ms 211748 KB Output is correct
57 Correct 3900 ms 211776 KB Output is correct
58 Correct 3625 ms 211724 KB Output is correct
59 Correct 3056 ms 203888 KB Output is correct
60 Correct 3002 ms 203916 KB Output is correct
61 Correct 2993 ms 203840 KB Output is correct
62 Correct 2880 ms 199848 KB Output is correct
63 Correct 2917 ms 199904 KB Output is correct
64 Correct 2861 ms 199984 KB Output is correct
65 Correct 2663 ms 196028 KB Output is correct
66 Correct 2595 ms 196012 KB Output is correct
67 Correct 2426 ms 196024 KB Output is correct