Submission #423186

#TimeUsernameProblemLanguageResultExecution timeMemory
423186arayiDancing Elephants (IOI11_elephants)C++17
26 / 100
9087 ms7504 KiB
#include "elephants.h" #include <map> #include <unordered_map> #include <set> #include <iostream> using namespace std; const int N = 1e5 + 30; const int T = 69; int n, l, fr, sc; int x[N]; map <int, int> mp; map <int, int> nax, haj, a, b; set <int> fp; void go(int x) { int sm = 1, s = 0; int nx = x, v = x; while (s < T) { s++; if (v > nx + l) sm++, nx = v; if (v == sc) break; v = haj[v]; } a[x] = sm; b[x] = nx + l; } void add(int x) { mp[x]++; auto i1 = fp.lower_bound(x); if (i1 != fp.end()) haj[x] = *i1, nax[*i1] = x; if (i1 != fp.begin()) nax[x] = *(--i1), haj[*i1] = x; fp.insert(x); i1 = fp.end(); fr = *fp.begin(), sc = *(--i1); int v = x; for (int i = 0; i <= T + 1; i++) { go(v); if (v == fr) break; v = nax[v]; } } void rmv(int x) { mp[x]--; if(x != sc && x != fr) haj[nax[x]] = haj[x], nax[haj[x]] = nax[x]; fp.erase(x); auto i1 = fp.end(); fr = *fp.begin(), sc = *(--i1); int v = x; for (int i = 0; i <= T + 1; i++) { if (v == fr) break; v = nax[v]; go(v); } } int ans() { int v = fr, ret = 0; while (v < sc) { ret += a[v]; if (b[v] >= sc) break; v = *fp.lower_bound(b[v] + 1); } return ret; } void init(int N, int L, int X[]) { n = N; l = L; for (int i = 0; i < n; i++) { x[i] = X[i]; //cout << x[i] << endl; if (mp[x[i]] == 0) add(x[i]); else mp[x[i]]++; } } int update(int i, int y) { if (mp[x[i]] == 1) rmv(x[i]); else mp[x[i]]--; x[i] = y; if (mp[y] == 0) add(y); else mp[y]++; return ans(); }
#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...