Submission #40954

#TimeUsernameProblemLanguageResultExecution timeMemory
40954IvanCLightning Conductor (POI11_pio)C++14
100 / 100
501 ms11668 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...