Submission #498887

# Submission time Handle Problem Language Result Execution time Memory
498887 2021-12-26T14:07:02 Z sidon Dancing Elephants (IOI11_elephants) C++17
100 / 100
5279 ms 6508 KB
#include <bits/stdc++.h>
using namespace std;
#include "elephants.h"
 
const int MAX_N = 150'000, B = 650, 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;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 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 0 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 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 0 ms 332 KB Output is correct
7 Correct 778 ms 1256 KB Output is correct
8 Correct 765 ms 1504 KB Output is correct
9 Correct 689 ms 2212 KB Output is correct
10 Correct 667 ms 2216 KB Output is correct
11 Correct 689 ms 2244 KB Output is correct
12 Correct 1018 ms 2248 KB Output is correct
13 Correct 810 ms 2120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 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 0 ms 332 KB Output is correct
7 Correct 778 ms 1256 KB Output is correct
8 Correct 765 ms 1504 KB Output is correct
9 Correct 689 ms 2212 KB Output is correct
10 Correct 667 ms 2216 KB Output is correct
11 Correct 689 ms 2244 KB Output is correct
12 Correct 1018 ms 2248 KB Output is correct
13 Correct 810 ms 2120 KB Output is correct
14 Correct 761 ms 1672 KB Output is correct
15 Correct 1131 ms 1816 KB Output is correct
16 Correct 1763 ms 2460 KB Output is correct
17 Correct 1690 ms 2984 KB Output is correct
18 Correct 1926 ms 3008 KB Output is correct
19 Correct 1116 ms 2972 KB Output is correct
20 Correct 1683 ms 2984 KB Output is correct
21 Correct 1627 ms 3100 KB Output is correct
22 Correct 1289 ms 2980 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 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 0 ms 332 KB Output is correct
7 Correct 778 ms 1256 KB Output is correct
8 Correct 765 ms 1504 KB Output is correct
9 Correct 689 ms 2212 KB Output is correct
10 Correct 667 ms 2216 KB Output is correct
11 Correct 689 ms 2244 KB Output is correct
12 Correct 1018 ms 2248 KB Output is correct
13 Correct 810 ms 2120 KB Output is correct
14 Correct 761 ms 1672 KB Output is correct
15 Correct 1131 ms 1816 KB Output is correct
16 Correct 1763 ms 2460 KB Output is correct
17 Correct 1690 ms 2984 KB Output is correct
18 Correct 1926 ms 3008 KB Output is correct
19 Correct 1116 ms 2972 KB Output is correct
20 Correct 1683 ms 2984 KB Output is correct
21 Correct 1627 ms 3100 KB Output is correct
22 Correct 1289 ms 2980 KB Output is correct
23 Correct 3854 ms 5956 KB Output is correct
24 Correct 4082 ms 5952 KB Output is correct
25 Correct 2996 ms 5952 KB Output is correct
26 Correct 3780 ms 5960 KB Output is correct
27 Correct 4338 ms 5964 KB Output is correct
28 Correct 2752 ms 2216 KB Output is correct
29 Correct 2743 ms 2216 KB Output is correct
30 Correct 2641 ms 2168 KB Output is correct
31 Correct 2531 ms 2244 KB Output is correct
32 Correct 3532 ms 6088 KB Output is correct
33 Correct 2361 ms 5968 KB Output is correct
34 Correct 3760 ms 5960 KB Output is correct
35 Correct 2186 ms 6016 KB Output is correct
36 Correct 2218 ms 5960 KB Output is correct
37 Correct 4227 ms 6508 KB Output is correct
38 Correct 4367 ms 5968 KB Output is correct
39 Correct 3387 ms 5960 KB Output is correct
40 Correct 5181 ms 6084 KB Output is correct
41 Correct 5175 ms 5964 KB Output is correct
42 Correct 5279 ms 5960 KB Output is correct