Submission #25488

# Submission time Handle Problem Language Result Execution time Memory
25488 2017-06-22T12:22:14 Z Bruteforceman Dancing Elephants (IOI11_elephants) C++11
50 / 100
9000 ms 23564 KB
#include "elephants.h"
#include "bits/stdc++.h"
using namespace std;

int n;
int a[150010];
int len;
const int magic = 320;
vector <int> v[1000];
vector <int> dp[1000];
vector <int> nxt[1000];

int bucket[150010];
int tot;
int counter;

bool cmp(int x, int y) {
	return a[x] < a[y];
}
int search(int b, int e, int block, int value) {
	if(b == e) {
		return a[v[block][b]] <= value ? b : -1;
	}
	int m = (b + e + 1) >> 1;
	if(a[v[block][m]] <= value) return search(m, e, block, value);
	else return search(b, m-1, block, value);
}
void get_done(int b) {
	if(v[b].empty()) return ;
	int sz = v[b].size();
	nxt[b].resize(sz);
	dp[b].resize(sz);

	for(int i = sz-1; i >= 0; i--) {
		int id = search(0, sz-1, b, a[v[b][i]] + len);
		if(id == sz - 1) {
			dp[b][i] = 1;
			nxt[b][i] = a[v[b][i]] + len;
		} else {
			dp[b][i] = dp[b][id + 1] + 1;
			nxt[b][i] = nxt[b][id + 1];
		}
	}
}
void init(int N, int L, int X[])
{
	tot = (N-1) / magic;
	len = L;
	n = N;
	for(int i = 0; i < n; i++) {
  		a[i] = X[i];
  	}
  	for(int i = 0; i < n; i++) {
  		v[i / magic].push_back(i);
  		bucket[i] = i / magic;
  	}
  	for(int i = 0; i <= tot; i++) {
  		get_done(i);
  	}
  	counter = 0;
}
int query() {
	int ans = 0;
	int cover = -1;
	for(int i = 0; i <= tot; i++) {
		if(v[i].empty()) continue;
		int sz = v[i].size();
		int u = search(0, sz-1, i, cover);
		if(u < sz-1) {
			ans += dp[i][u + 1];
			cover = nxt[i][u + 1];
		}
	}
	return ans;
}

void rebuild() {
	for(int i = 0; i <= tot; i++) {
		v[i].clear();
	}
	vector <int> pos;
	for(int i = 0; i < n; i++) {
		pos.push_back(i);
	}
	sort(pos.begin(), pos.end(), cmp);
	for(int i = 0; i < n; i++) {
		bucket[pos[i]] = i / magic;
		v[i / magic].push_back(pos[i]);
	}
	for(int i = 0; i <= tot; i++) {
		get_done(i);
	}
}
int update(int i, int y)
{
	++counter;
	if(counter == magic) {
		counter = 0;
		rebuild();
	}
	int b1 = bucket[i];
	int b2 = tot;
	v[b1].erase(find(v[b1].begin(), v[b1].end(), i));

	a[i] = y;
	for(int x = 0; x <= tot; x++) {
		if(v[x].empty()) continue;
		if(a[i] <= a[v[x].back()]) {
			b2 = x;
			break;
		}
	}
	bucket[i] = b2;
	v[b2].push_back(i);
	sort(v[b2].begin(), v[b2].end(), cmp);
	get_done(b1);
	get_done(b2);
	return query();
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 18892 KB Output is correct
2 Correct 0 ms 18892 KB Output is correct
3 Correct 0 ms 18892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 18892 KB Output is correct
2 Correct 0 ms 18892 KB Output is correct
3 Correct 0 ms 18892 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4956 ms 19476 KB Output is correct
2 Correct 4476 ms 19724 KB Output is correct
3 Correct 3746 ms 20364 KB Output is correct
4 Correct 2433 ms 20196 KB Output is correct
5 Correct 2483 ms 20196 KB Output is correct
6 Correct 4943 ms 20592 KB Output is correct
7 Correct 2299 ms 20196 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3513 ms 19700 KB Output is correct
2 Correct 4509 ms 19736 KB Output is correct
3 Correct 6959 ms 20584 KB Output is correct
4 Correct 7946 ms 21548 KB Output is correct
5 Correct 8013 ms 21544 KB Output is correct
6 Execution timed out 9000 ms 20992 KB Execution timed out
7 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Execution timed out 9000 ms 23564 KB Execution timed out
2 Halted 0 ms 0 KB -