Submission #346184

#TimeUsernameProblemLanguageResultExecution timeMemory
346184casperwangDancing Elephants (IOI11_elephants)C++14
26 / 100
22 ms2796 KiB
#include "elephants.h" #include <bits/stdc++.h> #define pb push_back #define All(x) x.begin(), x.end() #define pii pair<int,int> #define ff first #define ss second using namespace std; #define debug(args...) kout("[ " + string(#args) + " ]", args) void kout() { cerr << endl; } template <class T, class ...U> void kout(T a, U ...b) { cerr << a << ' ',kout(b...); } template <class T> void pary(T L, T R) { while (L != R) cerr << *L << " \n"[++L==R]; } const int MAXN = 150000; const int K = 380; int n, m, seg; vector <pii> a; vector <vector<pii>> B; vector <pii> rng; vector <int> pos; vector <pii> info; void build_block(int id) { int len = B[id].size(); sort(All(B[id])); for (int i = len-1; i >= 0; i--) { pos[B[id][i].ss] = id; auto it = upper_bound(All(B[id]), pii(B[id][i].ff + seg, n)); if (it == B[id].end()) { info[B[id][i].ss] = pii(1, B[id][i].ff + seg); } else { info[B[id][i].ss] = pii(info[it->ss].ff + 1, info[it->ss].ss); } } rng[id] = pii(B[id][0].ff, B[id][len-1].ff); assert((!id || rng[id-1].ss <= rng[id].ff) && (id==m-1 || rng[id+1].ss >= rng[id].ss)); } void build() { sort(All(a)); for (int i = 0; i < m; i++) B[i].clear(); for (int i = 0; i < n; i++) B[i/K].pb(a[i]); for (int i = 0; i < m; i++) build_block(i); sort(All(a), [](const pii x, const pii y) { return x.ss < y.ss; }); } void init(int N, int L, int X[]) { n = N, m = (n-1)/K+1, seg = L; a.clear(), a.resize(n); pos.clear(), pos.resize(n); info.clear(), info.resize(n); B.clear(), B.resize(m); rng.clear(), rng.resize(m); for (int i = 0; i < n; i++) a[i].ff = X[i], a[i].ss = i; build(); } int solve() { int ans = 0, now = -1; for (int i = 0; i < m; i++) { pii tmp = *upper_bound(All(B[i]), pii(now, n+1)); ans += info[tmp.ss].ff; now = info[tmp.ss].ss; } return ans; } int update(int i, int y) { int id = pos[i]; vector <pii> tmp(B[id].size()-1); int c = 0; for (int j = 0; j < (int)B[id].size(); j++) { if (B[id][j].ss == i) continue; tmp[c++] = B[id][j]; } B[id] = tmp; build_block(id); a[i].ff = y; for (int j = 0; j < m; j++) { if ((!j || rng[j-1].ss <= a[i].ff) && (j==m-1 || rng[j+1].ff >= a[i].ff)) { B[j].pb(a[i]); build_block(j); break; } } return solve(); }
#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...