Submission #241638

#TimeUsernameProblemLanguageResultExecution timeMemory
241638ChrisTLightning Conductor (POI11_pio)C++17
100 / 100
740 ms17016 KiB
#include <bits/stdc++.h> using namespace std; using pii = pair<int,int>; using pib = pair<int,bool>; using ll = long long; using ld = long double; #define all(x) (x).begin(),(x).end() #ifdef fread_unlocked #define fread fread_unlocked #define fwrite fwrite_unlocked #endif #define lc ind<<1 #define rc ind<<1|1 const int MN = 501265, MOD = 1e9+7, BASE = 31; int h[MN]; ld mx[MN]; ld get (int x, int y) { return h[y] + sqrtl(abs(x-y)); } int intersect (int a, int b) { //when does a pass b? int low = 1, high = min(a,b) - 1, mid, ans = 0; while (low <= high) { mid = (low + high) / 2; if (get(mid,a) > get(mid,b)) low = (ans = mid) + 1; else high = mid - 1; } return ans; } // -1 -1 -1 -1 0 0 0 0 1 1 1 1 int main () { int n; scanf ("%d",&n); for (int i = 1; i <= n; i++) scanf ("%d",h+i); deque<int> dq; for (int i = n; i >= 1; i--) { while ((int)dq.size()>1 && get(i,dq.front()) < get(i,dq[1])) dq.pop_front(); if (i<n) mx[i] = max(mx[i],get(i,dq.front())); while ((int)dq.size() > 1 && intersect(i,dq.back()) > intersect(dq.back(),dq[(int)dq.size()-2])) dq.pop_back(); dq.push_back(i); } dq.clear(); reverse(h+1,h+1+n); for (int i = n; i >= 1; i--) { while ((int)dq.size()>1 && get(i,dq.front()) < get(i,dq[1])) dq.pop_front(); if (i<n) mx[n-i+1] = max(mx[n-i+1],get(i,dq.front())); while ((int)dq.size() > 1 && intersect(i,dq.back()) > intersect(dq.back(),dq[(int)dq.size()-2])) dq.pop_back(); dq.push_back(i); } for (int i = 1; i <= n; i++) printf ("%d\n",(int)ceill(max((ld)0,mx[i] - h[n-i+1]))); return 0; }

Compilation message (stderr)

pio.cpp: In function 'int main()':
pio.cpp:31:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf ("%d",&n);
  ~~~~~~^~~~~~~~~
pio.cpp:32:37: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  for (int i = 1; i <= n; i++) scanf ("%d",h+i);
                               ~~~~~~^~~~~~~~~~
#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...