Submission #119729

#TimeUsernameProblemLanguageResultExecution timeMemory
119729nvmdavaDancing Elephants (IOI11_elephants)C++17
0 / 100
2 ms384 KiB
#include "elephants.h" #include <bits/stdc++.h> #define ss second #define ff first using namespace std; int n, l; pair<int, int> a[50005]; int loc[50005]; void sorter(int id){ while(id + 1 < n && a[id].ff > a[id + 1].ff){ swap(a[id], a[id + 1]); swap(loc[a[id].ff], loc[a[id + 1].ff]); id++; } while(id && a[id].ff < a[id - 1].ff){ swap(a[id], a[id - 1]); swap(loc[a[id].ss], loc[a[id - 1].ss]); id--; } } int count(){ int lst = a[0].ff; int res = 1; for(int i = 1; i < n; i++){ if(a[i].ff > lst + l){ res++; lst = a[i].ff; } } return res; } void init(int N, int L, int X[]){ n = N; l = L; for(int i = 0; i < N; i++){ a[i].first = X[i]; a[i].second = i; } sort(X, X + N); for(int i = 0; i < N; i++){ loc[a[i].second] = i; } } int update(int i, int y){ a[loc[i]].ff = y; sorter(loc[i]); return count(); }
#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...