Submission #423407

#TimeUsernameProblemLanguageResultExecution timeMemory
423407arayiDancing Elephants (IOI11_elephants)C++17
26 / 100
9084 ms4044 KiB
#include "elephants.h" #include <bits/stdc++.h> #include <set> #define MP make_pair using namespace std; const int N = 1e6 + 30; int n, l; set <pair<int, int> > fp; int x[N], fr, sc; int haj[N], nax[N]; void rmv(int i) { if(i != fr && i != sc) { nax[haj[i]]= nax[i]; haj[nax[i]] = haj[i]; } fp.erase(MP(x[i], i)); auto i1 = fp.end(); fr = (*fp.begin()).second, sc = (*(--i1)).second; } void add(int i) { auto i1 = fp.lower_bound(MP(x[i], i)); if(i1 != fp.end()) nax[(*i1).second] = i, haj[i] = (*i1).second; if(i1 != fp.begin()) haj[(*(--i1)).second] = i, nax[i] = (*i1).second; fp.insert(MP(x[i], i)); i1 = fp.end(); fr = (*fp.begin()).second, sc = (*(--i1)).second; } int go() { int v = fr, sm = 1, nx = x[fr] + l; while(nx < x[sc]) { while(x[v] <= nx) v = haj[v]; sm++, nx = x[v] + l; } return sm; } void init(int N, int L, int X[]) { n=N, l=L; for(int i = 0; i < n; i++) { x[i] = X[i]; add(i); } } int update(int i, int y) { rmv(i); x[i] = y; add(i); return go(); }
#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...