Submission #548083

# Submission time Handle Problem Language Result Execution time Memory
548083 2022-04-12T11:23:44 Z blue Bubble Sort 2 (JOI18_bubblesort2) C++17
38 / 100
445 ms 9564 KB
#include "bubblesort2.h"
#include <vector>
#include <set>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std;

using vi = vector<int>;
#define sz(x) int(x.size())

struct sdata
{
	set<int> inds;
	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 = -3'000'000;
			s[i].count = 0;
		}
		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])
		{
			s[i].inds.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])
		{
			s[i].inds.erase(id);
			s[i].count--;
			s[i].currans = (s[i].inds.empty() ? -3'000'000 : *s[i].inds.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]);
		}
	}
};

vi countScans(vi A_, vi X, vi V)
{
	A = A_;
	N = sz(A);
	Q = sz(X);

	map<int, int> vals;
	for(int i = 0; i < N; i++)
		vals[A[i]] = 0;

	for(int j = 0; j < Q; j++)
		vals[V[j]] = 0;

	int ct = -1;
	for(auto& z : vals)
	{
		z.second = ++ct;
	}

	// cerr << "values # = " << sz(vals) << '\n';

	vi answer(Q);


	segtree S(N+Q);

	for(int i = 0; i < N; i++)
	{
		// cerr << "insert " << i << " at " << vals[A[i]] << '\n';
		S.insert(1, vals[A[i]], i);
	}

	for(int j = 0; j < Q; j++)
	{
		S.erase(1, vals[A[X[j]]], X[j]);
		A[X[j]] = V[j];
		S.insert(1, vals[A[X[j]]], X[j]);

		answer[j] = S.s[1].currans;
	}

	return answer;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 596 KB Output is correct
2 Correct 3 ms 852 KB Output is correct
3 Correct 7 ms 1632 KB Output is correct
4 Correct 8 ms 1620 KB Output is correct
5 Correct 7 ms 1620 KB Output is correct
6 Correct 10 ms 1620 KB Output is correct
7 Correct 10 ms 1588 KB Output is correct
8 Correct 7 ms 1592 KB Output is correct
9 Correct 7 ms 1632 KB Output is correct
10 Correct 7 ms 1588 KB Output is correct
11 Correct 7 ms 1620 KB Output is correct
12 Correct 7 ms 1628 KB Output is correct
13 Correct 10 ms 1636 KB Output is correct
14 Correct 9 ms 1620 KB Output is correct
15 Correct 7 ms 1620 KB Output is correct
16 Correct 6 ms 1620 KB Output is correct
17 Correct 8 ms 1620 KB Output is correct
18 Correct 9 ms 1524 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 596 KB Output is correct
2 Correct 3 ms 852 KB Output is correct
3 Correct 7 ms 1632 KB Output is correct
4 Correct 8 ms 1620 KB Output is correct
5 Correct 7 ms 1620 KB Output is correct
6 Correct 10 ms 1620 KB Output is correct
7 Correct 10 ms 1588 KB Output is correct
8 Correct 7 ms 1592 KB Output is correct
9 Correct 7 ms 1632 KB Output is correct
10 Correct 7 ms 1588 KB Output is correct
11 Correct 7 ms 1620 KB Output is correct
12 Correct 7 ms 1628 KB Output is correct
13 Correct 10 ms 1636 KB Output is correct
14 Correct 9 ms 1620 KB Output is correct
15 Correct 7 ms 1620 KB Output is correct
16 Correct 6 ms 1620 KB Output is correct
17 Correct 8 ms 1620 KB Output is correct
18 Correct 9 ms 1524 KB Output is correct
19 Correct 30 ms 5172 KB Output is correct
20 Correct 41 ms 5832 KB Output is correct
21 Correct 33 ms 5876 KB Output is correct
22 Correct 45 ms 5844 KB Output is correct
23 Correct 32 ms 5664 KB Output is correct
24 Correct 31 ms 5744 KB Output is correct
25 Correct 30 ms 5676 KB Output is correct
26 Correct 30 ms 5588 KB Output is correct
27 Correct 35 ms 5572 KB Output is correct
28 Correct 36 ms 5648 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 445 ms 9564 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 596 KB Output is correct
2 Correct 3 ms 852 KB Output is correct
3 Correct 7 ms 1632 KB Output is correct
4 Correct 8 ms 1620 KB Output is correct
5 Correct 7 ms 1620 KB Output is correct
6 Correct 10 ms 1620 KB Output is correct
7 Correct 10 ms 1588 KB Output is correct
8 Correct 7 ms 1592 KB Output is correct
9 Correct 7 ms 1632 KB Output is correct
10 Correct 7 ms 1588 KB Output is correct
11 Correct 7 ms 1620 KB Output is correct
12 Correct 7 ms 1628 KB Output is correct
13 Correct 10 ms 1636 KB Output is correct
14 Correct 9 ms 1620 KB Output is correct
15 Correct 7 ms 1620 KB Output is correct
16 Correct 6 ms 1620 KB Output is correct
17 Correct 8 ms 1620 KB Output is correct
18 Correct 9 ms 1524 KB Output is correct
19 Correct 30 ms 5172 KB Output is correct
20 Correct 41 ms 5832 KB Output is correct
21 Correct 33 ms 5876 KB Output is correct
22 Correct 45 ms 5844 KB Output is correct
23 Correct 32 ms 5664 KB Output is correct
24 Correct 31 ms 5744 KB Output is correct
25 Correct 30 ms 5676 KB Output is correct
26 Correct 30 ms 5588 KB Output is correct
27 Correct 35 ms 5572 KB Output is correct
28 Correct 36 ms 5648 KB Output is correct
29 Incorrect 445 ms 9564 KB Output isn't correct
30 Halted 0 ms 0 KB -