제출 #1240066

#제출 시각아이디문제언어결과실행 시간메모리
1240066countless코끼리 (Dancing Elephants) (IOI11_elephants)C++20
26 / 100
9091 ms6268 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 MX = 1e9; const int INF = 1e9+5; int n, l, b, sz; 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]; } sz = sqrt(MX) + 2; while (sz * sz >= MX) sz--; sz++; b = (MX + sz - 1) / sz; buckets.resize(b); for (int i = 0; i < n; i++) { buckets[x[i] / sz].insert(x[i]); } for (int i = 0; i < b; i++) { buckets[i].compute(); } } int update(int i, int y) { int give = y / sz, take = x[i] / sz; buckets[take].erase(x[i]); buckets[take].compute(); x[i] = y; buckets[give].insert(y); buckets[give].compute(); int ans = 0, at = -INF; for (int j = 0; j < b; j++) { 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...