답안 #25492

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
25492 2017-06-22T12:39:48 Z Bruteforceman 코끼리 (Dancing Elephants) (IOI11_elephants) C++11
97 / 100
9000 ms 23840 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);

	int pointer = sz-1;
	for(int i = sz-1; i >= 0; i--) {
		while(pointer >= 0 && a[v[b][i]] + len < a[v[b][pointer]]) {
			--pointer;
		}
		int id = pointer;
		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() {
	vector <int> pos;
	for(int i = 0; i <= tot; i++) {
		for(auto j : v[i]) {
			pos.push_back(j);
		}
		v[i].clear();
	}
	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 3406 ms 19440 KB Output is correct
2 Correct 2013 ms 19664 KB Output is correct
3 Correct 1753 ms 20296 KB Output is correct
4 Correct 743 ms 20140 KB Output is correct
5 Correct 843 ms 20140 KB Output is correct
6 Correct 2393 ms 20536 KB Output is correct
7 Correct 743 ms 20140 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1979 ms 19660 KB Output is correct
2 Correct 2356 ms 19708 KB Output is correct
3 Correct 3166 ms 20528 KB Output is correct
4 Correct 3319 ms 21464 KB Output is correct
5 Correct 3539 ms 21468 KB Output is correct
6 Correct 6063 ms 20912 KB Output is correct
7 Correct 3706 ms 21464 KB Output is correct
8 Correct 3579 ms 21468 KB Output is correct
9 Correct 1663 ms 20916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 8519 ms 23728 KB Output is correct
2 Execution timed out 9000 ms 23840 KB Execution timed out
3 Halted 0 ms 0 KB -