답안 #25490

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
25490 2017-06-22T12:27:51 Z Bruteforceman 코끼리 (Dancing Elephants) (IOI11_elephants) C++11
50 / 100
9000 ms 23376 KB
#include "elephants.h"
#include "bits/stdc++.h"
using namespace std;

int n;
int a[150010];
int len;
const int magic = 390;
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();
}
# 결과 실행 시간 메모리 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
# 결과 실행 시간 메모리 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
# 결과 실행 시간 메모리 Grader output
1 Correct 6303 ms 19440 KB Output is correct
2 Correct 4566 ms 19664 KB Output is correct
3 Correct 4879 ms 20296 KB Output is correct
4 Correct 2736 ms 20140 KB Output is correct
5 Correct 2639 ms 20140 KB Output is correct
6 Correct 5439 ms 20536 KB Output is correct
7 Correct 2533 ms 20140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4323 ms 19668 KB Output is correct
2 Correct 5439 ms 19708 KB Output is correct
3 Correct 7926 ms 20528 KB Output is correct
4 Execution timed out 9000 ms 21464 KB Execution timed out
5 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 9000 ms 23376 KB Execution timed out
2 Halted 0 ms 0 KB -