Submission #1022747

# Submission time Handle Problem Language Result Execution time Memory
1022747 2024-07-14T04:32:04 Z socpite Dancing Elephants (IOI11_elephants) C++14
26 / 100
9000 ms 47648 KB
#include "elephants.h"
#include<bits/stdc++.h>
using namespace std;

const int blsz = 400;
const int maxn = 2e5+5;
const int INF = 2e9+5;

map<int, int> sp[18];
multiset<int> current;
multiset<int> changed;

int A[maxn];

int n, l;

void build_sp(){

	changed = {INF};

	sp[0].clear();
	for(auto v: current){
		if(v == INF)continue;
		sp[0][v] = *current.upper_bound(v + l);
	}
	sp[0][INF] = INF;
	for(int i = 1; i < 18; i++){
		sp[i].clear();
		for(auto v: current){
			sp[i][v] = sp[i-1][sp[i-1][v]];
		}
	}
}

void init(int N, int L, int X[])
{
  	n = N;
	l = L;
	current.insert(INF);
	for(int i = 0; i < N; i++){
		A[i] = X[i];
		current.insert(A[i]);
	}
	build_sp();
}

int update(int i, int y)
{
	current.erase(current.find(A[i]));
	changed.insert(A[i]);
	A[i] = y;
	current.insert(A[i]);
	changed.insert(A[i]);

	int realcnt = 0, ans = 0;
	int pos = *current.begin();
	while(pos != INF){
		realcnt++;
		if(changed.find(pos) != changed.end()){
			if(current.find(pos) == current.end())pos = *current.upper_bound(pos);
			else {
				ans++;
				pos = *current.upper_bound(pos + l);
			}
		}
		else {
			int nxt_change = *changed.upper_bound(pos);
			for(int i = 17; i >= 0; i--){
				if(sp[i][pos] < nxt_change){
					pos = sp[i][pos];
					ans += (1<<i);
				}
			}
			pos = *current.upper_bound(pos + l);
			ans++;
		}
	}
	if(realcnt >= blsz)build_sp();
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 4431 ms 12340 KB Output is correct
8 Correct 6034 ms 17716 KB Output is correct
9 Execution timed out 9045 ms 47648 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 4431 ms 12340 KB Output is correct
8 Correct 6034 ms 17716 KB Output is correct
9 Execution timed out 9045 ms 47648 KB Time limit exceeded
10 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 1 ms 348 KB Output is correct
5 Correct 2 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 4431 ms 12340 KB Output is correct
8 Correct 6034 ms 17716 KB Output is correct
9 Execution timed out 9045 ms 47648 KB Time limit exceeded
10 Halted 0 ms 0 KB -