Submission #1240048

#TimeUsernameProblemLanguageResultExecution timeMemory
1240048countless코끼리 (Dancing Elephants) (IOI11_elephants)C++20
0 / 100
0 ms320 KiB
#include "elephants.h" #include <bits/stdc++.h> using namespace std; typedef long long ll; typedef long double ld; #define sp <<" "<< #define endl "\n" const int INF = 1e9+5; int n, l, b; struct bucket { vector<int> a; vector<int> cost, end; bool below(int x) { if (a.empty()) return true; int l = a.front(); return x <= l; } bool above(int x) { if (a.empty()) return true; int r = a.back(); return r <= x; } bool check(int x) { if (a.empty()) return false; int l = a.front(), r = a.back(); return l <= x and x <= r; } void insert(int x) { auto it = lower_bound(a.begin(), a.end(), x); a.insert(it, x); } void erase(int x) { auto it = lower_bound(a.begin(), a.end(), x); if (it == a.end() or *it != x) return; a.erase(it); } void compute() { int m = a.size(); cost.assign(m, 0); end.assign(m, 0); int j = m; for (int i = m-1; i >= 0; i--) { while (j > i+1 and a[j-1] > a[i] + l) j--; if (j < m) { cost[i] = cost[j] + 1; end[i] = end[j]; } else { cost[i] = 1; end[i] = a[i] + l; } } } }; vector<int> x; vector<bucket> buckets; void init(int N, int L, int X[]) { n = N, l = L; x.resize(N); for (int i = 0; i < N; i++) { x[i] = X[i]; } b = sqrt(n) + 2; while (b * b >= n) b--; b++; buckets.resize(b); for (int i = 0; i < b; i++) { for (int j = 0; j < n / b; j++) { if (j >= n) break; buckets[i].insert(x[i * b + j]); } } for (int i = 0; i < b; i++) { buckets[i].compute(); } } int update(int i, int y) { int give = -1, take = -1; for (int j = 0; j < b; j++) { if (buckets[j].check(x[i])) { take = j; } } for (int j = 0; j < b; j++) { if (buckets[j].below(y)) { give = j; break; } } if (give == -1) { for (int j = 0; j < b; j++) { if (buckets[j].above(y)) { give = j; } } } assert(give != -1 and take != -1); buckets[take].erase(x[i]); buckets[give].insert(y); x[i] = y; buckets[take].compute(); buckets[give].compute(); int ans = 0, at = -INF; for (int j = 0; j < b; j++) { if (buckets[j].a.empty()) continue; int idx = upper_bound(buckets[j].a.begin(), buckets[j].a.end(), at) - buckets[j].a.begin(); if (idx < buckets[j].a.size()) { ans += buckets[j].cost[idx]; at = buckets[j].end[idx]; } } 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...