Submission #363542

# Submission time Handle Problem Language Result Execution time Memory
363542 2021-02-06T13:47:20 Z soroush Dancing Elephants (IOI11_elephants) C++14
100 / 100
3551 ms 12720 KB
#include <bits/stdc++.h>
 
using namespace std;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int maxn = 3e6 + 100;
const int sq = 400;
 
int n , l , SZ , cnt , ucnt;
int x[maxn];
int a[maxn] , b[maxn];
 
struct comp{
	int a[sq * 2] , cnt[sq * 2] , lst[sq * 2] , sz;
	void init(){
		int k = sz;
		for(int i = sz ; i ; i --){
			while(k > i and a[k - 1] - a[i] > l)k --;
			if(a[sz] - a[i] <= l) cnt[i] = 1 , lst[i] = a[i] + l;
			else cnt[i] = cnt[k] + 1 , lst[i] = lst[k];
		}
	}
}comps[sq];
 
void init(int N , int L , int X[]){
	n = N , l = L;
	SZ = 380 , cnt = 1;
	for(int i = 0 ; i < n ; i ++){
		x[i] = X[i];
		if(comps[cnt].sz == SZ)cnt++;
		comps[cnt].a[++comps[cnt].sz] = x[i];
	}
	for(int i = 1 ; i <= cnt ; i ++)comps[i].init();
}
 
 
void add(int pos){
	int j , x;
	for(j = 1 ; j < cnt ; j ++)	if(comps[j].a[comps[j].sz] > pos)break;
	for(x = 1 ; x <= comps[j].sz ; x++)if(comps[j].a[x] > pos)break;
	for(int i = comps[j].sz ; i >= x ; i --) comps[j].a[i+1] = comps[j].a[i];
	comps[j].a[x] = pos;
	comps[j].sz++;
	comps[j].init();
}
 
void build(){
	int n = 0;
	for(int i = 1 ; i <= cnt ; i ++){
		for(int j = 1 ; j <= comps[i].sz ; j ++)
			b[++n] = comps[i].a[j];
		comps[i].sz = 0;
	}
	cnt = 1;
	for(int i = 1 ; i <= n ; i ++){
		if(comps[cnt].sz == SZ)cnt++;
		comps[cnt].a[++comps[cnt].sz] = b[i];
	}
	for(int i = 1 ; i <= cnt ; i ++)comps[i].init();
	ucnt = 0;
}
 
int rm(int pos){
	int j , i;
	for(j = 1 ; j < cnt ; j ++)	if(comps[j].a[1] <= pos and comps[j + 1].a[1] > pos)break;
	for(i = 1 ; i <= comps[j].sz ; i ++)if(comps[j].a[i] == pos){
		for(; i < comps[j].sz ; i ++) comps[j].a[i] = comps[j].a[i + 1];
		comps[j].sz --;
		break;
	}
	comps[j].init();
	return(comps[j].sz);
}
 
int get(){
	int ans = comps[1].cnt[1] , lst = comps[1].lst[1] , t;
	for(int i = 2 ; i <= cnt ; i ++){
		if(comps[i].a[comps[i].sz] <= lst)continue;
		int l = 1 , r = comps[i].sz;
		while(l <= r){
			int mid = (l + r) / 2;
			if(comps[i].a[mid] > lst)r = mid - 1 , t = mid;
			else l = mid + 1;
		}
		ans += comps[i].cnt[t];
		lst = comps[i].lst[t];
	}
	return(ans);
}
 
int update(int p , int v){
	if(++ucnt == SZ)build();
	if(!rm(x[p]))build();
	add(x[p] = v);
	return(get());
}

Compilation message

elephants.cpp: In function 'int get()':
elephants.cpp:87:7: warning: 't' may be used uninitialized in this function [-Wmaybe-uninitialized]
   87 |   lst = comps[i].lst[t];
      |   ~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 430 ms 1516 KB Output is correct
8 Correct 445 ms 1772 KB Output is correct
9 Correct 390 ms 2796 KB Output is correct
10 Correct 344 ms 2796 KB Output is correct
11 Correct 304 ms 2796 KB Output is correct
12 Correct 607 ms 2924 KB Output is correct
13 Correct 352 ms 2924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 430 ms 1516 KB Output is correct
8 Correct 445 ms 1772 KB Output is correct
9 Correct 390 ms 2796 KB Output is correct
10 Correct 344 ms 2796 KB Output is correct
11 Correct 304 ms 2796 KB Output is correct
12 Correct 607 ms 2924 KB Output is correct
13 Correct 352 ms 2924 KB Output is correct
14 Correct 368 ms 1904 KB Output is correct
15 Correct 681 ms 2156 KB Output is correct
16 Correct 1006 ms 3088 KB Output is correct
17 Correct 1041 ms 3820 KB Output is correct
18 Correct 1142 ms 3944 KB Output is correct
19 Correct 952 ms 3820 KB Output is correct
20 Correct 1032 ms 3816 KB Output is correct
21 Correct 1031 ms 3820 KB Output is correct
22 Correct 541 ms 3820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 364 KB Output is correct
2 Correct 1 ms 364 KB Output is correct
3 Correct 1 ms 364 KB Output is correct
4 Correct 1 ms 364 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 430 ms 1516 KB Output is correct
8 Correct 445 ms 1772 KB Output is correct
9 Correct 390 ms 2796 KB Output is correct
10 Correct 344 ms 2796 KB Output is correct
11 Correct 304 ms 2796 KB Output is correct
12 Correct 607 ms 2924 KB Output is correct
13 Correct 352 ms 2924 KB Output is correct
14 Correct 368 ms 1904 KB Output is correct
15 Correct 681 ms 2156 KB Output is correct
16 Correct 1006 ms 3088 KB Output is correct
17 Correct 1041 ms 3820 KB Output is correct
18 Correct 1142 ms 3944 KB Output is correct
19 Correct 952 ms 3820 KB Output is correct
20 Correct 1032 ms 3816 KB Output is correct
21 Correct 1031 ms 3820 KB Output is correct
22 Correct 541 ms 3820 KB Output is correct
23 Correct 2851 ms 7668 KB Output is correct
24 Correct 3181 ms 12704 KB Output is correct
25 Correct 2249 ms 12720 KB Output is correct
26 Correct 2991 ms 12652 KB Output is correct
27 Correct 3254 ms 12556 KB Output is correct
28 Correct 1523 ms 5484 KB Output is correct
29 Correct 1470 ms 5308 KB Output is correct
30 Correct 1527 ms 5308 KB Output is correct
31 Correct 1464 ms 5308 KB Output is correct
32 Correct 1987 ms 12140 KB Output is correct
33 Correct 1750 ms 11464 KB Output is correct
34 Correct 2257 ms 12344 KB Output is correct
35 Correct 1560 ms 12652 KB Output is correct
36 Correct 1050 ms 12140 KB Output is correct
37 Correct 2724 ms 12596 KB Output is correct
38 Correct 2277 ms 11372 KB Output is correct
39 Correct 2330 ms 12396 KB Output is correct
40 Correct 2290 ms 11500 KB Output is correct
41 Correct 3536 ms 12140 KB Output is correct
42 Correct 3551 ms 12396 KB Output is correct