Submission #652100

# Submission time Handle Problem Language Result Execution time Memory
652100 2022-10-21T10:05:26 Z ymm Bubble Sort 2 (JOI18_bubblesort2) C++17
100 / 100
3479 ms 68460 KB
#include "bubblesort2.h"
#include <bits/stdc++.h>
#define Loop(x,l,r) for (ll x = (l); x < (ll)(r); ++x)
#define LoopR(x,l,r) for (ll x = (r)-1; x >= (ll)(l); --x)
typedef long long ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll , ll > pll;
using namespace std;

mt19937_64 rd(time(0));

const int N = 500'010;
struct node {
	node *l, *r;
	ll weight;
	pii key;
	int sz;
	int mx;
} pool[2*N];

node *new_node()
{
	static int nxt = 0;
	pool[nxt].weight = rd();
	return &pool[nxt++];
}

void up(node *t)
{
	const int inf = 1e9;
	t->mx = t->key.second - (t->l? t->l->sz: 0);
	t->mx = max(t->mx, t->l? t->l->mx: -inf);
	t->mx = max(t->mx, t->r? t->r->mx - (t->l? t->l->sz: 0) - 1: -inf);
	t->sz = 1 + (t->l? t->l->sz: 0) + (t->r? t->r->sz: 0);
}

node *merge(node *l, node *r)
{
	if (!l)
		return r;
	if (!r)
		return l;
	if (l->weight > r->weight) {
		l->r = merge(l->r, r);
		up(l);
		return l;
	} else {
		r->l = merge(l, r->l);
		up(r);
		return r;
	}
}

pair<node *, node *> split(node *t, pii key)
{
	if (!t)
		return {};
	if (t->key < key) {
		auto [l, r] = split(t->r, key);
		t->r = l;
		up(t);
		return {t, r};
	} else {
		auto [l, r] = split(t->l, key);
		t->l = r;
		up(t);
		return {l, t};
	}
}

node *erase(node *t, pii key)
{
	auto [l, tmp1] = split(t, key);
	key.second++;
	auto [tmp2, r] = split(tmp1, key);
	key.second--;
	assert(tmp2->key == key);
	return merge(l, r);
}

node *insert(node *t, pii key)
{
	node *v = new_node();
	v->key = key;
	up(v);
	auto [l, r] = split(t, key);
	node *tmp;
	tmp = merge(l, v);
	tmp = merge(tmp, r);
	return tmp;
}

int a[N];
node *treap;
int n, q;

vector<int> countScans(vector<int> A, vector<int> X, vector<int> V)
{
	n = A.size();
	q = X.size();
	vector<int> ans;
	Loop (i,0,n) {
		a[i] = A[i];
		treap = insert(treap, {a[i], i});
	}
	Loop (i,0,q) {
		int p = X[i];
		treap = erase(treap, {a[p], p});
		a[p] = V[i];
		treap = insert(treap, {a[p], p});
		ans.push_back(treap->mx);
	}
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 16 ms 39380 KB Output is correct
2 Correct 18 ms 39380 KB Output is correct
3 Correct 20 ms 39476 KB Output is correct
4 Correct 20 ms 39464 KB Output is correct
5 Correct 20 ms 39508 KB Output is correct
6 Correct 19 ms 39500 KB Output is correct
7 Correct 20 ms 39456 KB Output is correct
8 Correct 23 ms 39540 KB Output is correct
9 Correct 21 ms 39588 KB Output is correct
10 Correct 19 ms 39532 KB Output is correct
11 Correct 21 ms 39508 KB Output is correct
12 Correct 20 ms 39488 KB Output is correct
13 Correct 18 ms 39508 KB Output is correct
14 Correct 19 ms 39496 KB Output is correct
15 Correct 23 ms 39568 KB Output is correct
16 Correct 25 ms 39464 KB Output is correct
17 Correct 24 ms 39544 KB Output is correct
18 Correct 21 ms 39500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 39380 KB Output is correct
2 Correct 18 ms 39380 KB Output is correct
3 Correct 20 ms 39476 KB Output is correct
4 Correct 20 ms 39464 KB Output is correct
5 Correct 20 ms 39508 KB Output is correct
6 Correct 19 ms 39500 KB Output is correct
7 Correct 20 ms 39456 KB Output is correct
8 Correct 23 ms 39540 KB Output is correct
9 Correct 21 ms 39588 KB Output is correct
10 Correct 19 ms 39532 KB Output is correct
11 Correct 21 ms 39508 KB Output is correct
12 Correct 20 ms 39488 KB Output is correct
13 Correct 18 ms 39508 KB Output is correct
14 Correct 19 ms 39496 KB Output is correct
15 Correct 23 ms 39568 KB Output is correct
16 Correct 25 ms 39464 KB Output is correct
17 Correct 24 ms 39544 KB Output is correct
18 Correct 21 ms 39500 KB Output is correct
19 Correct 30 ms 39872 KB Output is correct
20 Correct 31 ms 39824 KB Output is correct
21 Correct 31 ms 39852 KB Output is correct
22 Correct 35 ms 39876 KB Output is correct
23 Correct 36 ms 39884 KB Output is correct
24 Correct 30 ms 39872 KB Output is correct
25 Correct 29 ms 39872 KB Output is correct
26 Correct 29 ms 39840 KB Output is correct
27 Correct 30 ms 39824 KB Output is correct
28 Correct 29 ms 39824 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 42 ms 39756 KB Output is correct
2 Correct 80 ms 40740 KB Output is correct
3 Correct 133 ms 41756 KB Output is correct
4 Correct 139 ms 41688 KB Output is correct
5 Correct 147 ms 41872 KB Output is correct
6 Correct 138 ms 41872 KB Output is correct
7 Correct 133 ms 41724 KB Output is correct
8 Correct 159 ms 41744 KB Output is correct
9 Correct 152 ms 41680 KB Output is correct
10 Correct 100 ms 41800 KB Output is correct
11 Correct 104 ms 41804 KB Output is correct
12 Correct 90 ms 41740 KB Output is correct
13 Correct 93 ms 41760 KB Output is correct
14 Correct 92 ms 41800 KB Output is correct
15 Correct 91 ms 41844 KB Output is correct
16 Correct 72 ms 41756 KB Output is correct
17 Correct 77 ms 41756 KB Output is correct
18 Correct 91 ms 41784 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 16 ms 39380 KB Output is correct
2 Correct 18 ms 39380 KB Output is correct
3 Correct 20 ms 39476 KB Output is correct
4 Correct 20 ms 39464 KB Output is correct
5 Correct 20 ms 39508 KB Output is correct
6 Correct 19 ms 39500 KB Output is correct
7 Correct 20 ms 39456 KB Output is correct
8 Correct 23 ms 39540 KB Output is correct
9 Correct 21 ms 39588 KB Output is correct
10 Correct 19 ms 39532 KB Output is correct
11 Correct 21 ms 39508 KB Output is correct
12 Correct 20 ms 39488 KB Output is correct
13 Correct 18 ms 39508 KB Output is correct
14 Correct 19 ms 39496 KB Output is correct
15 Correct 23 ms 39568 KB Output is correct
16 Correct 25 ms 39464 KB Output is correct
17 Correct 24 ms 39544 KB Output is correct
18 Correct 21 ms 39500 KB Output is correct
19 Correct 30 ms 39872 KB Output is correct
20 Correct 31 ms 39824 KB Output is correct
21 Correct 31 ms 39852 KB Output is correct
22 Correct 35 ms 39876 KB Output is correct
23 Correct 36 ms 39884 KB Output is correct
24 Correct 30 ms 39872 KB Output is correct
25 Correct 29 ms 39872 KB Output is correct
26 Correct 29 ms 39840 KB Output is correct
27 Correct 30 ms 39824 KB Output is correct
28 Correct 29 ms 39824 KB Output is correct
29 Correct 42 ms 39756 KB Output is correct
30 Correct 80 ms 40740 KB Output is correct
31 Correct 133 ms 41756 KB Output is correct
32 Correct 139 ms 41688 KB Output is correct
33 Correct 147 ms 41872 KB Output is correct
34 Correct 138 ms 41872 KB Output is correct
35 Correct 133 ms 41724 KB Output is correct
36 Correct 159 ms 41744 KB Output is correct
37 Correct 152 ms 41680 KB Output is correct
38 Correct 100 ms 41800 KB Output is correct
39 Correct 104 ms 41804 KB Output is correct
40 Correct 90 ms 41740 KB Output is correct
41 Correct 93 ms 41760 KB Output is correct
42 Correct 92 ms 41800 KB Output is correct
43 Correct 91 ms 41844 KB Output is correct
44 Correct 72 ms 41756 KB Output is correct
45 Correct 77 ms 41756 KB Output is correct
46 Correct 91 ms 41784 KB Output is correct
47 Correct 625 ms 48296 KB Output is correct
48 Correct 2871 ms 66180 KB Output is correct
49 Correct 3479 ms 68332 KB Output is correct
50 Correct 3059 ms 68428 KB Output is correct
51 Correct 2976 ms 68372 KB Output is correct
52 Correct 2887 ms 68156 KB Output is correct
53 Correct 2851 ms 68100 KB Output is correct
54 Correct 2573 ms 68396 KB Output is correct
55 Correct 2803 ms 68436 KB Output is correct
56 Correct 2381 ms 68344 KB Output is correct
57 Correct 2664 ms 68460 KB Output is correct
58 Correct 2445 ms 68428 KB Output is correct
59 Correct 2125 ms 67004 KB Output is correct
60 Correct 2049 ms 66972 KB Output is correct
61 Correct 1924 ms 66968 KB Output is correct
62 Correct 1826 ms 67048 KB Output is correct
63 Correct 1850 ms 66948 KB Output is correct
64 Correct 1911 ms 66904 KB Output is correct
65 Correct 1683 ms 66736 KB Output is correct
66 Correct 1687 ms 66732 KB Output is correct
67 Correct 1737 ms 66792 KB Output is correct