Submission #402931

# Submission time Handle Problem Language Result Execution time Memory
402931 2021-05-12T14:33:24 Z Antekb Dancing Elephants (IOI11_elephants) C++14
100 / 100
8996 ms 12224 KB
#include "elephants.h"
#include<bits/stdc++.h>
using namespace std;
#define st first
#define nd second
#define mp(x, y) make_pair(x, y)
#define pb(x) push_back(x)

int n, l;
vector<int> pocz;
vector<vector<int> > V;
vector<vector<int> > gdzie, ile;
vector<int> pos;
const int K=300;
void init(int N, int L, int X[])
{
	n = N;
	l=L;
	pos.resize(n);

	for(int i=0; i<n; i++){
		pos[i]=X[i];
	}
}
int cnt=0;
int find(int x){
	return max(0, (int)(upper_bound(pocz.begin(), pocz.end(), x)-pocz.begin()-1));
}
void build(int x){
	//cout<<x<<"a\n";
	if(!V[x].size())return;
	//sort(V[x].begin(), V[x].end());
	pocz[x]=V[x][0];
	gdzie[x].resize(V[x].size());
	ile[x].resize(V[x].size());
	int t=V[x].size();
	for(int i=V[x].size()-1; i>=0; i--){
		while(V[x][t-1]>V[x][i]+l)t--;
		if(t==V[x].size()){
			ile[x][i]=1;
			gdzie[x][i]=V[x][i]+l;
		}
		else{
			ile[x][i]=ile[x][t]+1;
			gdzie[x][i]=gdzie[x][t];
		}
		//cout<<i<<" "<<V[x][i]<<" "<<t<<" "<<gdzie[x][i]<<" "<<ile[x][i]<<"\n";
	}
}
void usun(int k, int x){
	vector<int> V2;
	for(int i=0; i<V[k].size(); i++){
		if(V[k][i]==x){
			x=-1;
			continue;
		}
		V2.pb(V[k][i]);
	}
	V[k]=V2;
	build(k);
}
void dodaj(int k, int x){
	vector<int> V2;
	bool b=0;
	for(int i=0; i<V[k].size(); i++){
		if(!b && V[k][i]>x){
			V2.pb(x);
			b=1;
		}
		V2.pb(V[k][i]);
	}
	if(!b){
		V2.pb(x);
	}
	V[k]=V2;
	build(k);
}
int query(){
	/*for(int i=0; i<V.size(); i++){
		cout<<pocz[i]<<"\n";
		for(int j=0; j<V[i].size(); j++){
			cout<<V[i][j]<<" "<<ile[i][j]<<" "<<gdzie[i][j]<<"\n";
		}
	}*/
	int ans=0;
	int akt=-1;
	for(int i=0; i<V.size(); i++){
		if(!V[i].size() || akt>=V[i].back())continue;
		else{
			int j=upper_bound(V[i].begin(), V[i].end(), akt)-V[i].begin();
			ans+=ile[i][j];
			akt=gdzie[i][j];
		}
	}
	return ans;
}
int update(int i, int y)
{
	if(cnt%K==0){
		V.resize((n+K-1)/K);
		gdzie.resize((n+K-1)/K);
		ile.resize((n+K-1)/K);
		pocz.resize((n+K-1)/K);
		vector<int> pos2=pos;
		sort(pos2.begin(), pos2.end());
		for(int i=0; i<V.size(); i++)V[i].clear();
		for(int i=0; i<n; i++){
			V[i/K].pb(pos2[i]);
		}
		for(int i=0; i<V.size(); i++)build(i);
	}
	/*cout<<V.size()<<"\n";
	for(int i=0; i<V.size(); i++){
		cout<<pocz[i]<<" "<<V[i].size()<<"\n";
	}*/
	int t=find(pos[i]);
	//cout<<t<<"\n";
	usun(t, pos[i]);
	pos[i]=y;
	t=find(pos[i]);
	//cout<<t<<"\n";
	dodaj(t, pos[i]);
	cnt++;
	return query();
}

Compilation message

elephants.cpp: In function 'void build(int)':
elephants.cpp:39:7: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   39 |   if(t==V[x].size()){
      |      ~^~~~~~~~~~~~~
elephants.cpp: In function 'void usun(int, int)':
elephants.cpp:52:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |  for(int i=0; i<V[k].size(); i++){
      |               ~^~~~~~~~~~~~
elephants.cpp: In function 'void dodaj(int, int)':
elephants.cpp:65:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   65 |  for(int i=0; i<V[k].size(); i++){
      |               ~^~~~~~~~~~~~
elephants.cpp: In function 'int query()':
elephants.cpp:87:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   87 |  for(int i=0; i<V.size(); i++){
      |               ~^~~~~~~~~
elephants.cpp: In function 'int update(int, int)':
elephants.cpp:106:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  106 |   for(int i=0; i<V.size(); i++)V[i].clear();
      |                ~^~~~~~~~~
elephants.cpp:110:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  110 |   for(int i=0; i<V.size(); i++)build(i);
      |                ~^~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 358 ms 1316 KB Output is correct
8 Correct 394 ms 1436 KB Output is correct
9 Correct 556 ms 2404 KB Output is correct
10 Correct 732 ms 2184 KB Output is correct
11 Correct 721 ms 2172 KB Output is correct
12 Correct 1176 ms 2620 KB Output is correct
13 Correct 746 ms 2176 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 358 ms 1316 KB Output is correct
8 Correct 394 ms 1436 KB Output is correct
9 Correct 556 ms 2404 KB Output is correct
10 Correct 732 ms 2184 KB Output is correct
11 Correct 721 ms 2172 KB Output is correct
12 Correct 1176 ms 2620 KB Output is correct
13 Correct 746 ms 2176 KB Output is correct
14 Correct 568 ms 1884 KB Output is correct
15 Correct 645 ms 1872 KB Output is correct
16 Correct 1756 ms 2840 KB Output is correct
17 Correct 2093 ms 3504 KB Output is correct
18 Correct 2240 ms 3608 KB Output is correct
19 Correct 1316 ms 2980 KB Output is correct
20 Correct 2103 ms 3560 KB Output is correct
21 Correct 2112 ms 3612 KB Output is correct
22 Correct 1322 ms 2972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 358 ms 1316 KB Output is correct
8 Correct 394 ms 1436 KB Output is correct
9 Correct 556 ms 2404 KB Output is correct
10 Correct 732 ms 2184 KB Output is correct
11 Correct 721 ms 2172 KB Output is correct
12 Correct 1176 ms 2620 KB Output is correct
13 Correct 746 ms 2176 KB Output is correct
14 Correct 568 ms 1884 KB Output is correct
15 Correct 645 ms 1872 KB Output is correct
16 Correct 1756 ms 2840 KB Output is correct
17 Correct 2093 ms 3504 KB Output is correct
18 Correct 2240 ms 3608 KB Output is correct
19 Correct 1316 ms 2980 KB Output is correct
20 Correct 2103 ms 3560 KB Output is correct
21 Correct 2112 ms 3612 KB Output is correct
22 Correct 1322 ms 2972 KB Output is correct
23 Correct 4719 ms 6800 KB Output is correct
24 Correct 5385 ms 11628 KB Output is correct
25 Correct 4205 ms 11260 KB Output is correct
26 Correct 6513 ms 10864 KB Output is correct
27 Correct 6947 ms 10804 KB Output is correct
28 Correct 1420 ms 5160 KB Output is correct
29 Correct 1439 ms 5156 KB Output is correct
30 Correct 1453 ms 5060 KB Output is correct
31 Correct 1431 ms 5156 KB Output is correct
32 Correct 5383 ms 10488 KB Output is correct
33 Correct 5476 ms 9848 KB Output is correct
34 Correct 5889 ms 10816 KB Output is correct
35 Correct 4586 ms 10856 KB Output is correct
36 Correct 2757 ms 10488 KB Output is correct
37 Correct 8535 ms 12224 KB Output is correct
38 Correct 6123 ms 9796 KB Output is correct
39 Correct 5747 ms 10764 KB Output is correct
40 Correct 6182 ms 9716 KB Output is correct
41 Correct 8863 ms 11708 KB Output is correct
42 Correct 8996 ms 11904 KB Output is correct