Submission #67232

# Submission time Handle Problem Language Result Execution time Memory
67232 2018-08-13T17:05:44 Z MatheusLealV Bubble Sort 2 (JOI18_bubblesort2) C++11
100 / 100
5576 ms 237596 KB
#include "bubblesort2.h"
#include <bits/stdc++.h>
#define N 1000050
#define l (2*nod)
#define r (2*nod + 1)
#define mid ((a + b)/2)
using namespace std;
typedef long long ll;

int inf = 2000000000;

int n, v[N], c, bit[N], lim;

vector<int> val;

map<int, int> mapa;

set<int> pos[N];

struct T
{
	int tree[4*N], lazy[4*N];

	inline void init()
	{
		for(int i = 0; i < 4*N; i++) lazy[i] = tree[i] = 0;
	}

	inline void prop(int nod, int a, int b)
	{
		if(!lazy[nod]) return;

		tree[nod] += lazy[nod];

		if(a != b)
		{
			lazy[l] += lazy[nod];

			lazy[r] += lazy[nod];
		}

		lazy[nod] = 0;

		return;
	}

	void upd(int nod, int a, int b, int i, int j, int x)
	{
		prop(nod, a, b);

		if(j < a or i > b) return;

		if(i <= a and j >= b)
		{
			tree[nod] += x;

			if(a != b)
			{
				lazy[l] += x;

				lazy[r] += x;
			}

			return;
		}

		upd(l, a, mid, i, j, x), upd(r, mid + 1, b, i, j, x);

		tree[nod] = max(tree[l], tree[r]);
	}

	int query(int nod, int a, int b, int i, int j)
	{
		prop(nod, a, b);

		if(j < a or i > b) return -inf;

		if(i <= a and j >= b) return tree[nod];

		return max(query(l, a, mid, i, j), query(r, mid + 1, b, i, j));
	}

} Tree;

inline void remove(int x, int po)
{
	Tree.upd(1, 1, lim, x, lim, 1);

	int p = -(*pos[x].begin());

	pos[x].erase(-po);

	if(p == po)
	{
		int pp = -(*pos[x].begin());

		Tree.upd(1, 1, lim, x, x, pp - p);
	}
}

inline void add(int x, int po)
{
	Tree.upd(1, 1, lim, x, lim, -1);

	int p = -(*pos[x].begin());

	if(po > p)
	{
		Tree.upd(1, 1, lim, x, x, po - p);
	}

	pos[x].insert(-po);
}

vector<int> countScans(vector<int> A, vector<int> X, vector<int> V)
{
	int Q = X.size();

	n = A.size();

	for(auto x: A) val.push_back(x);

	for(auto x: V) val.push_back(x);

	sort(val.begin(), val.end());

	for(auto x: val) if(!mapa[x]) mapa[x] = ++c;

	for(int i = 0; i < N; i ++) pos[i].insert(10000);

	for(int i = 0; i < n; i++) v[i] = mapa[A[i]];

	for(int i = 0; i < Q; i++) V[i] = mapa[V[i]];

	for(int i = 0; i < n; i++) pos[v[i]].insert(-i);

	vector<int> answer(Q);

	Tree.init();

	lim = N - 1;

	for(int i = 0, soma = 0; i < N; i++)
	{
		soma += pos[i].size() - 1;

		if(pos[i].empty()) continue;

		int x = -(*pos[i].begin());

		Tree.upd(1, 1, lim, i, i, x - soma);
	}

	for(int j = 0; j < Q; j++)
	{
		int x = X[j], val = v[X[j]], novo = V[j];

		remove(val, x);

		add(novo, x);

		v[x] = novo;

		answer[j] = 1 + Tree.query(1, 1, lim, 1, lim);
	}

	return answer;
}
# Verdict Execution time Memory Grader output
1 Correct 362 ms 125740 KB Output is correct
2 Correct 374 ms 125928 KB Output is correct
3 Correct 372 ms 126108 KB Output is correct
4 Correct 470 ms 126108 KB Output is correct
5 Correct 421 ms 126208 KB Output is correct
6 Correct 345 ms 126248 KB Output is correct
7 Correct 425 ms 126324 KB Output is correct
8 Correct 420 ms 126324 KB Output is correct
9 Correct 351 ms 126328 KB Output is correct
10 Correct 346 ms 126328 KB Output is correct
11 Correct 351 ms 126328 KB Output is correct
12 Correct 367 ms 126328 KB Output is correct
13 Correct 367 ms 126460 KB Output is correct
14 Correct 377 ms 126460 KB Output is correct
15 Correct 401 ms 126460 KB Output is correct
16 Correct 358 ms 126460 KB Output is correct
17 Correct 345 ms 126460 KB Output is correct
18 Correct 374 ms 126460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 362 ms 125740 KB Output is correct
2 Correct 374 ms 125928 KB Output is correct
3 Correct 372 ms 126108 KB Output is correct
4 Correct 470 ms 126108 KB Output is correct
5 Correct 421 ms 126208 KB Output is correct
6 Correct 345 ms 126248 KB Output is correct
7 Correct 425 ms 126324 KB Output is correct
8 Correct 420 ms 126324 KB Output is correct
9 Correct 351 ms 126328 KB Output is correct
10 Correct 346 ms 126328 KB Output is correct
11 Correct 351 ms 126328 KB Output is correct
12 Correct 367 ms 126328 KB Output is correct
13 Correct 367 ms 126460 KB Output is correct
14 Correct 377 ms 126460 KB Output is correct
15 Correct 401 ms 126460 KB Output is correct
16 Correct 358 ms 126460 KB Output is correct
17 Correct 345 ms 126460 KB Output is correct
18 Correct 374 ms 126460 KB Output is correct
19 Correct 417 ms 127280 KB Output is correct
20 Correct 493 ms 127424 KB Output is correct
21 Correct 436 ms 127424 KB Output is correct
22 Correct 377 ms 127424 KB Output is correct
23 Correct 461 ms 127424 KB Output is correct
24 Correct 385 ms 127424 KB Output is correct
25 Correct 425 ms 127424 KB Output is correct
26 Correct 458 ms 127448 KB Output is correct
27 Correct 479 ms 127448 KB Output is correct
28 Correct 380 ms 127448 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 376 ms 127804 KB Output is correct
2 Correct 546 ms 129476 KB Output is correct
3 Correct 593 ms 131056 KB Output is correct
4 Correct 610 ms 131692 KB Output is correct
5 Correct 563 ms 132320 KB Output is correct
6 Correct 524 ms 132768 KB Output is correct
7 Correct 501 ms 133348 KB Output is correct
8 Correct 515 ms 133756 KB Output is correct
9 Correct 524 ms 133840 KB Output is correct
10 Correct 638 ms 133840 KB Output is correct
11 Correct 567 ms 133840 KB Output is correct
12 Correct 542 ms 133840 KB Output is correct
13 Correct 525 ms 133840 KB Output is correct
14 Correct 509 ms 133840 KB Output is correct
15 Correct 454 ms 133840 KB Output is correct
16 Correct 511 ms 133840 KB Output is correct
17 Correct 466 ms 133840 KB Output is correct
18 Correct 472 ms 133840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 362 ms 125740 KB Output is correct
2 Correct 374 ms 125928 KB Output is correct
3 Correct 372 ms 126108 KB Output is correct
4 Correct 470 ms 126108 KB Output is correct
5 Correct 421 ms 126208 KB Output is correct
6 Correct 345 ms 126248 KB Output is correct
7 Correct 425 ms 126324 KB Output is correct
8 Correct 420 ms 126324 KB Output is correct
9 Correct 351 ms 126328 KB Output is correct
10 Correct 346 ms 126328 KB Output is correct
11 Correct 351 ms 126328 KB Output is correct
12 Correct 367 ms 126328 KB Output is correct
13 Correct 367 ms 126460 KB Output is correct
14 Correct 377 ms 126460 KB Output is correct
15 Correct 401 ms 126460 KB Output is correct
16 Correct 358 ms 126460 KB Output is correct
17 Correct 345 ms 126460 KB Output is correct
18 Correct 374 ms 126460 KB Output is correct
19 Correct 417 ms 127280 KB Output is correct
20 Correct 493 ms 127424 KB Output is correct
21 Correct 436 ms 127424 KB Output is correct
22 Correct 377 ms 127424 KB Output is correct
23 Correct 461 ms 127424 KB Output is correct
24 Correct 385 ms 127424 KB Output is correct
25 Correct 425 ms 127424 KB Output is correct
26 Correct 458 ms 127448 KB Output is correct
27 Correct 479 ms 127448 KB Output is correct
28 Correct 380 ms 127448 KB Output is correct
29 Correct 376 ms 127804 KB Output is correct
30 Correct 546 ms 129476 KB Output is correct
31 Correct 593 ms 131056 KB Output is correct
32 Correct 610 ms 131692 KB Output is correct
33 Correct 563 ms 132320 KB Output is correct
34 Correct 524 ms 132768 KB Output is correct
35 Correct 501 ms 133348 KB Output is correct
36 Correct 515 ms 133756 KB Output is correct
37 Correct 524 ms 133840 KB Output is correct
38 Correct 638 ms 133840 KB Output is correct
39 Correct 567 ms 133840 KB Output is correct
40 Correct 542 ms 133840 KB Output is correct
41 Correct 525 ms 133840 KB Output is correct
42 Correct 509 ms 133840 KB Output is correct
43 Correct 454 ms 133840 KB Output is correct
44 Correct 511 ms 133840 KB Output is correct
45 Correct 466 ms 133840 KB Output is correct
46 Correct 472 ms 133840 KB Output is correct
47 Correct 1608 ms 159204 KB Output is correct
48 Correct 4822 ms 219672 KB Output is correct
49 Correct 5223 ms 228568 KB Output is correct
50 Correct 5099 ms 237596 KB Output is correct
51 Correct 5061 ms 237596 KB Output is correct
52 Correct 5479 ms 237596 KB Output is correct
53 Correct 5377 ms 237596 KB Output is correct
54 Correct 4725 ms 237596 KB Output is correct
55 Correct 5576 ms 237596 KB Output is correct
56 Correct 4561 ms 237596 KB Output is correct
57 Correct 5275 ms 237596 KB Output is correct
58 Correct 4337 ms 237596 KB Output is correct
59 Correct 4512 ms 237596 KB Output is correct
60 Correct 3943 ms 237596 KB Output is correct
61 Correct 4599 ms 237596 KB Output is correct
62 Correct 3921 ms 237596 KB Output is correct
63 Correct 3757 ms 237596 KB Output is correct
64 Correct 4270 ms 237596 KB Output is correct
65 Correct 3957 ms 237596 KB Output is correct
66 Correct 3815 ms 237596 KB Output is correct
67 Correct 3543 ms 237596 KB Output is correct