답안 #62053

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
62053 2018-07-27T10:19:02 Z aome 코끼리 (Dancing Elephants) (IOI11_elephants) C++17
26 / 100
37 ms 2752 KB
#include "elephants.h"

#include <bits/stdc++.h>

using namespace std;

const int N = 15005;
const int B = 500;

int n, L;
int a[N], in[N];
int jump[N], f[N];
int szVec;
vector<int> arr;
vector< pair<int, int> > vec[N];

void calc(vector< pair<int, int> > &vec) {
	int ptr = 0, sz = vec.size();
	for (int i = 0; i < sz; ++i) {
		while (ptr < sz && vec[ptr].first <= vec[i].first + L) ptr++;
		if (ptr == sz) jump[vec[i].second] = -1;
		else jump[vec[i].second] = vec[ptr].second;
	}
	for (int i = sz - 1; i >= 0; --i) {
		int j = vec[i].second;
		int k = jump[j];
		if (k == -1) f[j] = 0;
		else {
			f[j] = f[k] + 1;
			if (jump[k] != -1) jump[j] = jump[k];
		}
	}
}

void init(int _n, int _L, int X[]) {
	n = _n, L = _L;
	for (int i = 0; i < n; ++i) a[i] = X[i];
	for (int i = 0; i < n; i += B) {
		int r = min(n, i + B) - 1;
		for (int j = i; j <= r; ++j) {
			vec[szVec].push_back({a[j], j});
			in[j] = szVec;
		}
		calc(vec[szVec]), arr.push_back(szVec++);
	}
}

void push(int p, int x) {
	vector< pair<int, int> > &cur = vec[arr[p]];
	vector< pair<int, int> > buf = cur; cur.clear();
	bool flag = 0;
	for (auto i : buf) {
		if (!flag && i.first > a[x]) {
			flag = 1, cur.push_back({a[x], x});
		}	
		cur.push_back(i);
	}
	if (!flag) cur.push_back({a[x], x});
	buf.clear();
	if (cur.size() == B * 2) {
		for (int i = B; i < B * 2; ++i) {
			buf.push_back(cur[i]);
			in[cur[i].second] = szVec;
		}
		cur.resize(B);
		arr.insert(arr.begin() + p, szVec);
		vec[szVec++] = buf;
		calc(cur), calc(buf);
	}
	else {
		calc(cur);
	}
}

int get() {
	int res = 0, cur = -1e9;
	for (auto i : arr) {
		if (vec[i].back().first <= cur) continue;
		++res;
		auto j = lower_bound(vec[i].begin(), vec[i].end(), make_pair(cur + 1, 0));
		res += f[j -> second];
		cur = a[jump[j -> second]] + L;
	}
	return res;
}

int update(int x, int y) {
	if (n == 1) return 1;
	for (int i = 0; i < arr.size(); ++i) {
		int id = arr[i];
		if (id != in[x]) continue;
		vector< pair<int, int> > tmp = vec[id]; vec[id].clear();
		for (auto j : tmp) if (j.second != x) vec[id].push_back(j);
		if (!vec[id].size()) {
			arr.erase(arr.begin() + i); break;
		}
		calc(vec[id]); break;
	}
	a[x] = y;
	bool flag = 0;
	for (int i = 0; i < arr.size(); ++i) {
		int id = arr[i];
		if (vec[id][0].first > a[x] || vec[id].back().first < a[x]) continue;
		flag = 1, in[x] = arr[i], push(i, x); break;
	}
	if (!flag) {
		in[x] = arr.back();
		push(arr.size() - 1, x);
	}
	return get();
}

Compilation message

elephants.cpp: In function 'int update(int, int)':
elephants.cpp:89:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < arr.size(); ++i) {
                  ~~^~~~~~~~~~~~
elephants.cpp:101:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for (int i = 0; i < arr.size(); ++i) {
                  ~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 632 KB Output is correct
2 Correct 4 ms 868 KB Output is correct
3 Correct 3 ms 868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 632 KB Output is correct
2 Correct 4 ms 868 KB Output is correct
3 Correct 3 ms 868 KB Output is correct
4 Correct 3 ms 868 KB Output is correct
5 Correct 3 ms 868 KB Output is correct
6 Correct 4 ms 940 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 632 KB Output is correct
2 Correct 4 ms 868 KB Output is correct
3 Correct 3 ms 868 KB Output is correct
4 Correct 3 ms 868 KB Output is correct
5 Correct 3 ms 868 KB Output is correct
6 Correct 4 ms 940 KB Output is correct
7 Incorrect 37 ms 2752 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 632 KB Output is correct
2 Correct 4 ms 868 KB Output is correct
3 Correct 3 ms 868 KB Output is correct
4 Correct 3 ms 868 KB Output is correct
5 Correct 3 ms 868 KB Output is correct
6 Correct 4 ms 940 KB Output is correct
7 Incorrect 37 ms 2752 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 632 KB Output is correct
2 Correct 4 ms 868 KB Output is correct
3 Correct 3 ms 868 KB Output is correct
4 Correct 3 ms 868 KB Output is correct
5 Correct 3 ms 868 KB Output is correct
6 Correct 4 ms 940 KB Output is correct
7 Incorrect 37 ms 2752 KB Output isn't correct
8 Halted 0 ms 0 KB -