답안 #498885

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
498885 2021-12-26T14:05:54 Z sidon 코끼리 (Dancing Elephants) (IOI11_elephants) C++17
100 / 100
8201 ms 6624 KB
#include <bits/stdc++.h>
using namespace std;
#include "elephants.h"
 
const int MAX_N = 150'000, B = 400, INF = 2e9;
 
int N, L, LIM, X[MAX_N], Y[MAX_N], num[MAX_N], pos[MAX_N], q_;
 
vector<int> a[B];
 
void recalculate(int j) {
	auto &c = a[j];
	int sz = size(c), pt = sz;
 
	for(int i = sz; --i >= 0; ) {
		while(pt && X[c[i]] + L < X[c[pt-1]]) --pt;
 
		num[c[i]] = pt < sz ? num[c[pt]] + 1 : 1;
		pos[c[i]] = pt < sz ? pos[c[pt]] : X[c[i]] + L;
	}
}
 
void init(int n, int l, int x[]) {
	N = n, L = l, LIM = (N - 1)/B + 1;
	for(int i = 0; i < N; i++) {
		X[i] = x[i];
		Y[i] = i/B;
		a[i/B].push_back(i);
	}
	for(int i = 0; i < LIM; i++)
		recalculate(i);
}

int lowerB(int val, int j){
	int r = -1;
	for(int k=512; k/=2; ) 
		while(r + k < (int)size(a[j]) && X[a[j][r+k]] < val) r += k;
	return r + 1;
}

int update(int i, int y) {
	int l = Y[i], p = 0;
	while(a[l][p] != i) ++p;
	a[l].erase(begin(a[l]) + p);
	recalculate(l);

	X[i] = y;
 
	for(l = 0; l < LIM; l++)
		if(!empty(a[l]) && X[a[l][0]] > X[i]) break;
	if(l) --l;
	p = lowerB(y, l);

	Y[i] = l;
	a[l].insert(begin(a[l]) + p, i);
	recalculate(l);
 
	if(!(++q_ % (B - 2))){
		for(int j = i = 0; i < LIM; i++) {
			for(int &v : a[i]) pos[j++] = v;
			a[i].clear();
		}
		for(i = 0; i < N; i++) {
			Y[pos[i]] = i/B;
			a[i/B].push_back(pos[i]);
		}
		for(i = 0; i < LIM; i++)
			recalculate(i);
	}
 
	int res = 0, curr = -1;
 
	for(int k = 0; k < LIM; k++) {
		if(empty(a[k]) || curr >= X[a[k].back()]) continue;

 		int j = lowerB(curr + 1, k);
 
		res += num[a[k][j]];
		curr = pos[a[k][j]];
	}
	return res;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 500 ms 1228 KB Output is correct
8 Correct 535 ms 1356 KB Output is correct
9 Correct 539 ms 2160 KB Output is correct
10 Correct 638 ms 2164 KB Output is correct
11 Correct 546 ms 2184 KB Output is correct
12 Correct 827 ms 2080 KB Output is correct
13 Correct 758 ms 2244 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 500 ms 1228 KB Output is correct
8 Correct 535 ms 1356 KB Output is correct
9 Correct 539 ms 2160 KB Output is correct
10 Correct 638 ms 2164 KB Output is correct
11 Correct 546 ms 2184 KB Output is correct
12 Correct 827 ms 2080 KB Output is correct
13 Correct 758 ms 2244 KB Output is correct
14 Correct 498 ms 1692 KB Output is correct
15 Correct 778 ms 1744 KB Output is correct
16 Correct 1313 ms 2420 KB Output is correct
17 Correct 1387 ms 3020 KB Output is correct
18 Correct 1561 ms 3012 KB Output is correct
19 Correct 1106 ms 2896 KB Output is correct
20 Correct 1376 ms 2904 KB Output is correct
21 Correct 1460 ms 2900 KB Output is correct
22 Correct 1333 ms 2944 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 500 ms 1228 KB Output is correct
8 Correct 535 ms 1356 KB Output is correct
9 Correct 539 ms 2160 KB Output is correct
10 Correct 638 ms 2164 KB Output is correct
11 Correct 546 ms 2184 KB Output is correct
12 Correct 827 ms 2080 KB Output is correct
13 Correct 758 ms 2244 KB Output is correct
14 Correct 498 ms 1692 KB Output is correct
15 Correct 778 ms 1744 KB Output is correct
16 Correct 1313 ms 2420 KB Output is correct
17 Correct 1387 ms 3020 KB Output is correct
18 Correct 1561 ms 3012 KB Output is correct
19 Correct 1106 ms 2896 KB Output is correct
20 Correct 1376 ms 2904 KB Output is correct
21 Correct 1460 ms 2900 KB Output is correct
22 Correct 1333 ms 2944 KB Output is correct
23 Correct 5028 ms 5844 KB Output is correct
24 Correct 4540 ms 5780 KB Output is correct
25 Correct 3825 ms 5772 KB Output is correct
26 Correct 4634 ms 5788 KB Output is correct
27 Correct 4589 ms 5788 KB Output is correct
28 Correct 1793 ms 2208 KB Output is correct
29 Correct 1752 ms 2228 KB Output is correct
30 Correct 1726 ms 2328 KB Output is correct
31 Correct 1640 ms 2236 KB Output is correct
32 Correct 3650 ms 5776 KB Output is correct
33 Correct 2628 ms 5860 KB Output is correct
34 Correct 5137 ms 5780 KB Output is correct
35 Correct 2554 ms 5776 KB Output is correct
36 Correct 2023 ms 5776 KB Output is correct
37 Correct 5853 ms 6624 KB Output is correct
38 Correct 7226 ms 5776 KB Output is correct
39 Correct 5400 ms 5784 KB Output is correct
40 Correct 8201 ms 5784 KB Output is correct
41 Correct 6193 ms 5784 KB Output is correct
42 Correct 6148 ms 5828 KB Output is correct