Submission #40954

# Submission time Handle Problem Language Result Execution time Memory
40954 2018-02-10T12:46:29 Z IvanC Lightning Conductor (POI11_pio) C++14
100 / 100
501 ms 11668 KB
#include <bits/stdc++.h>
#define gc getchar_unlocked
inline void getint(int &x){
    int c = gc();
    x = 0;
    for(;(c<48 || c>57);c = gc());
    for(;c>47 && c<58;c = gc()) {x = (x<<1) + (x<<3) + c - 48;}
}
inline void print(int n)
{
	if (n == 0)
	{
		putchar_unlocked('0');
		putchar_unlocked('\n');
	}
	else if (n == -1)
	{
		putchar_unlocked('-');
		putchar_unlocked('1');
		putchar_unlocked('\n');
	}
	else
	{
		char buf[11];
		buf[10] = '\n';
		int i = 9;
		while (n)
		{
			buf[i--] = n % 10 + '0';
			n /= 10;
		}
		while (buf[i] != '\n')
			putchar_unlocked(buf[++i]);
	}
}
using namespace std;
const int MAXN = 500010;
int BUCKET;
vector<int> maiores,minpos,maxpos;
int vetor[MAXN],N,raizes[MAXN];
int main(){
	getint(N);
	BUCKET = min((int)ceil(sqrt(N)),200);
	int atual = 0;
	for(int i = 1;i<=N;i++){
		getint(vetor[i]);
		maiores.push_back(vetor[i]);
		if(atual * atual < i) atual++;
		raizes[i] = atual;
	}
	sort(maiores.begin(),maiores.end());
	maiores.erase(unique(maiores.begin(),maiores.end()),maiores.end());
	reverse(maiores.begin(),maiores.end());
	while(maiores.size() >= BUCKET) maiores.pop_back();
	reverse(maiores.begin(),maiores.end());
	minpos.assign(maiores.size(),MAXN);
	maxpos.assign(maiores.size(),1);
	for(int i = 1;i<=N;i++){
		int idx = lower_bound(maiores.begin(),maiores.end(),vetor[i]) - maiores.begin();
		if(maiores[idx] != vetor[i]) continue;
		minpos[idx] = min(minpos[idx],i);
		maxpos[idx] = max(maxpos[idx],i);
	}
	for(int i = 1;i<=N;i++){
		int p = 0;
		for(int j = 0;j<maiores.size();j++){
			int davez = raizes[max(abs(i - minpos[j]),abs(i - maxpos[j]))] + (maiores[j] - vetor[i]);
			p = max(p,davez);
		}
		print(p);
	}
	return 0;
}

Compilation message

pio.cpp: In function 'int main()':
pio.cpp:54:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
  while(maiores.size() >= BUCKET) maiores.pop_back();
                       ^
pio.cpp:66:18: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
   for(int j = 0;j<maiores.size();j++){
                  ^
# Verdict Execution time Memory Grader output
1 Correct 2 ms 248 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 480 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 1204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 1796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 47 ms 1800 KB Output is correct
2 Correct 5 ms 1800 KB Output is correct
3 Correct 55 ms 1944 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 74 ms 2312 KB Output is correct
2 Correct 15 ms 2312 KB Output is correct
3 Correct 79 ms 2868 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 184 ms 4404 KB Output is correct
2 Correct 29 ms 4404 KB Output is correct
3 Correct 203 ms 4968 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 351 ms 8328 KB Output is correct
2 Correct 47 ms 8328 KB Output is correct
3 Correct 333 ms 8364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 501 ms 11532 KB Output is correct
2 Correct 66 ms 11532 KB Output is correct
3 Correct 467 ms 11592 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 378 ms 11592 KB Output is correct
2 Correct 68 ms 11592 KB Output is correct
3 Correct 480 ms 11668 KB Output is correct