Submission #529382

#TimeUsernameProblemLanguageResultExecution timeMemory
529382flappybirdDancing Elephants (IOI11_elephants)C++17
50 / 100
9071 ms21472 KiB
#include "elephants.h" #include <bits/stdc++.h> #pragma GCC optimize("O3") #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") #pragma GCC target("avx,avx2,fma") using namespace std; typedef long long ll; typedef pair<int, int> pi; #define MAX 150010 #define B 200 int N; int L; int arr[MAX]; int cnt; map<int, int> ncnt; int gcnt; set<int> allv; set<pair<int, pi>> bukkit[MAX]; //refresh bukkit void refb(int b) { if (bukkit[b].empty()) return; set<pair<int, pi>> s1; for (auto it = prev(bukkit[b].end());; it--) { int x = it->first; int e = x + L; auto ub = s1.lower_bound(make_pair(e + 1, pi(0, 0))); pair<int, pi> ins; ins.first = x; if (ub == s1.end()) ins.second = pi(1, e); else ins.second = pi(ub->second.first + 1, ub->second.second); s1.insert(ins); if (it == bukkit[b].begin()) break; } bukkit[b].swap(s1); } void ref() { for (int i = 0; i < gcnt; i++) bukkit[i].clear(); gcnt = 0; for (auto v : allv) { if (bukkit[gcnt].size() == B) gcnt++; bukkit[gcnt].insert(make_pair(v, pi(0, 0))); } gcnt++; for (int i = 0; i < gcnt; i++) refb(i); } int calc() { int en = -2, i; int cnt = 0; for (i = 0; i < gcnt; i++) { if (bukkit[i].empty()) continue; auto ub = bukkit[i].lower_bound(make_pair(en + 1, pi(0, 0))); if (ub == bukkit[i].end()) continue; cnt += ub->second.first; en = ub->second.second; } return cnt; } void init(int N, int L, int X[]) { ::N = N; ::L = L; int i; for (i = 0; i < N; i++) arr[i] = X[i], allv.insert(arr[i]), ncnt[arr[i]]++; ref(); } int update(int i, int y) { cnt++; if (cnt == B) ref(), cnt = 0; int x = arr[i]; arr[i] = y; ncnt[x]--; if (ncnt[x] == 0) { int i, ind = 0; for (i = 0; i < gcnt; i++) if (bukkit[i].size() && bukkit[i].begin()->first <= x) ind = i; auto it = bukkit[ind].lower_bound(make_pair(x, pi(0, 0))); bukkit[ind].erase(it); allv.erase(x); refb(ind); } if (ncnt[y] == 0) { allv.insert(y); int i, ind = 0; for (i = 0; i < gcnt; i++) if (bukkit[i].size() && bukkit[i].begin()->first <= y) ind = i; bukkit[ind].insert(make_pair(y, pi(0, 0))); allv.insert(y); refb(ind); } ncnt[y]++; return calc(); }
#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...