Submission #96742

# Submission time Handle Problem Language Result Execution time Memory
96742 2019-02-11T15:59:51 Z jangwonyoung Dancing Elephants (IOI11_elephants) C++14
100 / 100
3613 ms 11140 KB
#include "elephants.h"
#include<iostream>
#include<queue>
using namespace std;
const int bs=400;
int bc;
int x[150000];
int n,l;
vector<int>bl[400];
vector<int>dp[400];
vector<int>en[400];
int z[150000];
int rnd=0;
void yena(int pos){
	dp[pos].resize(bl[pos].size()); dp[pos].shrink_to_fit();
	en[pos].resize(bl[pos].size()); en[pos].shrink_to_fit();
	if(bl[pos].empty()) return;
	int ptr=bl[pos].size();
	for(int i=(int)bl[pos].size()-1; i>=0 ;i--){
		while(ptr!=0 && bl[pos][ptr-1]>l+bl[pos][i]) --ptr;
		if(ptr==bl[pos].size()) dp[pos][i]=1,en[pos][i]=bl[pos][i]+l+1;
		else dp[pos][i]=1+dp[pos][ptr],en[pos][i]=en[pos][ptr];
	}
}
int sakura(){
	int ans=0,cur=0;
	for(int i=0; i<bc ;i++){
		if(bl[i].empty() || bl[i].back()<cur) continue;
		int pos=lower_bound(bl[i].begin(),bl[i].end(),cur)-bl[i].begin();
		ans+=dp[i][pos],cur=en[i][pos];
	}
	return ans;
}
void iu(){
	int tzuyu=0;
	for(int i=0; i<bc ;i++){
		for(auto cur:bl[i]) z[tzuyu++]=cur;
		bl[i].clear();
	}
	for(int i=0; i<n ;i++) bl[i/bs].push_back(z[i]);
	for(int i=0; i<bc ;i++){
		bl[i].shrink_to_fit();
		yena(i);
	}
}
int find(int x){
	for(int i=0; i<bc ;i++) if(!bl[i].empty() && bl[i].back()>=x) return i;
	return bc-1;
}
void init(int N, int L, int X[]){
	n=N;l=L;
	bc=(n-1)/bs+1;
	for(int i=0; i<n ;i++){
		x[i]=X[i];
		bl[i/bs].push_back(x[i]);
	}
	for(int i=0; i<bc ;i++) yena(i);
}
int update(int i, int y){
	if(++rnd==bs){
		rnd=0;
		iu();
	}
	int pos=find(x[i]);
	for(auto& cur:bl[pos]){
		if(cur==x[i]){
			cur=2e9;break;
		}
	}
	for(int i=1; i<bl[pos].size() ;i++) if(bl[pos][i]<bl[pos][i-1]) swap(bl[pos][i-1],bl[pos][i]);
	bl[pos].pop_back();yena(pos);
	x[i]=y;
	pos=find(x[i]);
	bl[pos].push_back(x[i]);
	for(int i=bl[pos].size()-1; i>=1 ;i--) if(bl[pos][i]<bl[pos][i-1]) swap(bl[pos][i-1],bl[pos][i]);
	yena(pos);
	return sakura();
}

Compilation message

elephants.cpp: In function 'void yena(int)':
elephants.cpp:21:9: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   if(ptr==bl[pos].size()) dp[pos][i]=1,en[pos][i]=bl[pos][i]+l+1;
      ~~~^~~~~~~~~~~~~~~~
elephants.cpp: In function 'int update(int, int)':
elephants.cpp:70:16: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  for(int i=1; i<bl[pos].size() ;i++) if(bl[pos][i]<bl[pos][i-1]) swap(bl[pos][i-1],bl[pos][i]);
               ~^~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 0 ms 380 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 0 ms 380 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 328 ms 1272 KB Output is correct
8 Correct 376 ms 1656 KB Output is correct
9 Correct 414 ms 2384 KB Output is correct
10 Correct 412 ms 2296 KB Output is correct
11 Correct 396 ms 2424 KB Output is correct
12 Correct 636 ms 2524 KB Output is correct
13 Correct 437 ms 2424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 0 ms 380 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 328 ms 1272 KB Output is correct
8 Correct 376 ms 1656 KB Output is correct
9 Correct 414 ms 2384 KB Output is correct
10 Correct 412 ms 2296 KB Output is correct
11 Correct 396 ms 2424 KB Output is correct
12 Correct 636 ms 2524 KB Output is correct
13 Correct 437 ms 2424 KB Output is correct
14 Correct 414 ms 1988 KB Output is correct
15 Correct 508 ms 3320 KB Output is correct
16 Correct 1040 ms 4472 KB Output is correct
17 Correct 1044 ms 5112 KB Output is correct
18 Correct 1159 ms 5240 KB Output is correct
19 Correct 731 ms 5212 KB Output is correct
20 Correct 1066 ms 5112 KB Output is correct
21 Correct 1052 ms 5224 KB Output is correct
22 Correct 771 ms 4600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 0 ms 380 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 328 ms 1272 KB Output is correct
8 Correct 376 ms 1656 KB Output is correct
9 Correct 414 ms 2384 KB Output is correct
10 Correct 412 ms 2296 KB Output is correct
11 Correct 396 ms 2424 KB Output is correct
12 Correct 636 ms 2524 KB Output is correct
13 Correct 437 ms 2424 KB Output is correct
14 Correct 414 ms 1988 KB Output is correct
15 Correct 508 ms 3320 KB Output is correct
16 Correct 1040 ms 4472 KB Output is correct
17 Correct 1044 ms 5112 KB Output is correct
18 Correct 1159 ms 5240 KB Output is correct
19 Correct 731 ms 5212 KB Output is correct
20 Correct 1066 ms 5112 KB Output is correct
21 Correct 1052 ms 5224 KB Output is correct
22 Correct 771 ms 4600 KB Output is correct
23 Correct 2767 ms 11028 KB Output is correct
24 Correct 2848 ms 10940 KB Output is correct
25 Correct 2303 ms 10932 KB Output is correct
26 Correct 2657 ms 10976 KB Output is correct
27 Correct 2784 ms 10824 KB Output is correct
28 Correct 1626 ms 5240 KB Output is correct
29 Correct 1577 ms 5368 KB Output is correct
30 Correct 1656 ms 5288 KB Output is correct
31 Correct 1594 ms 5264 KB Output is correct
32 Correct 2175 ms 10488 KB Output is correct
33 Correct 1710 ms 9848 KB Output is correct
34 Correct 2481 ms 10588 KB Output is correct
35 Correct 1695 ms 10872 KB Output is correct
36 Correct 1203 ms 10336 KB Output is correct
37 Correct 2883 ms 11128 KB Output is correct
38 Correct 2492 ms 9592 KB Output is correct
39 Correct 2467 ms 10616 KB Output is correct
40 Correct 2497 ms 9592 KB Output is correct
41 Correct 3502 ms 10628 KB Output is correct
42 Correct 3613 ms 11140 KB Output is correct