Submission #423185

# Submission time Handle Problem Language Result Execution time Memory
423185 2021-06-10T19:44:45 Z arayi Dancing Elephants (IOI11_elephants) C++17
26 / 100
9000 ms 13276 KB
#include "elephants.h"
#include <map>
#include <unordered_map>
#include <set>
#include <iostream>
using namespace std;

const int N = 1e5 + 30;
const int T = 69;
int n, l, fr, sc;
int x[N];
map <int, int> mp;
unordered_map <int, int> nax, haj, a, b;
set <int> fp;

void go(int x)
{
	int sm = 1, s = 0;
	int nx = x, v = x;
	while (s < T)
	{
		s++;
		if (v > nx + l) sm++, nx = v;
		if (v == sc) break;
		v = haj[v];
	}
	a[x] = sm;
	b[x] = nx + l;
}
void add(int x)
{
	mp[x]++;
	auto i1 = fp.lower_bound(x);
	if (i1 != fp.end()) haj[x] = *i1, nax[*i1] = x;
	if (i1 != fp.begin()) nax[x] = *(--i1), haj[*i1] = x;
	fp.insert(x);
	i1 = fp.end();
	fr = *fp.begin(), sc = *(--i1);
	int v = x;
	for (int i = 0; i <= T + 1; i++)
	{
		go(v);
		if (v == fr) break;
		v = nax[v];
	}
}
void rmv(int x)
{
	mp[x]--;
	if(x != sc && x != fr) haj[nax[x]] = haj[x], nax[haj[x]] = nax[x];
	fp.erase(x);
	auto i1 = fp.end();
	fr = *fp.begin(), sc = *(--i1);
	int v = x;
	for (int i = 0; i <= T + 1; i++)
	{
		if (v == fr) break;
		v = nax[v];
		go(v);
	}
}
int ans()
{
	int v = fr, ret = 0;
	while (v < sc)
	{
		ret += a[v];
		if (b[v] >= sc) break;
		v = *fp.lower_bound(b[v] + 1);
	}
	return ret;
}
void init(int N, int L, int X[])
{
	n = N; l = L;
	for (int i = 0; i < n; i++)
	{
		x[i] = X[i];
		//cout << x[i] << endl;
		if (mp[x[i]] == 0) add(x[i]);
		else mp[x[i]]++;
	}
}

int update(int i, int y)
{
	if (mp[x[i]] == 1) rmv(x[i]);
	else mp[x[i]]--;
	x[i] = y;
	if (mp[y] == 0) add(y);
	else mp[y]++;
	return ans();
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 332 KB Output is correct
2 Correct 3 ms 332 KB Output is correct
3 Correct 3 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 332 KB Output is correct
2 Correct 3 ms 332 KB Output is correct
3 Correct 3 ms 332 KB Output is correct
4 Correct 15 ms 332 KB Output is correct
5 Correct 12 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 332 KB Output is correct
2 Correct 3 ms 332 KB Output is correct
3 Correct 3 ms 332 KB Output is correct
4 Correct 15 ms 332 KB Output is correct
5 Correct 12 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Execution timed out 9047 ms 13276 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 332 KB Output is correct
2 Correct 3 ms 332 KB Output is correct
3 Correct 3 ms 332 KB Output is correct
4 Correct 15 ms 332 KB Output is correct
5 Correct 12 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Execution timed out 9047 ms 13276 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 4 ms 332 KB Output is correct
2 Correct 3 ms 332 KB Output is correct
3 Correct 3 ms 332 KB Output is correct
4 Correct 15 ms 332 KB Output is correct
5 Correct 12 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Execution timed out 9047 ms 13276 KB Time limit exceeded
8 Halted 0 ms 0 KB -