제출 #25491

#제출 시각아이디문제언어결과실행 시간메모리
25491Bruteforceman코끼리 (Dancing Elephants) (IOI11_elephants)C++11
97 / 100
9000 ms23612 KiB
#include "elephants.h" #include "bits/stdc++.h" using namespace std; int n; int a[150010]; int len; const int magic = 390; vector <int> v[1000]; vector <int> dp[1000]; vector <int> nxt[1000]; int bucket[150010]; int tot; int counter; bool cmp(int x, int y) { return a[x] < a[y]; } int search(int b, int e, int block, int value) { if(b == e) { return a[v[block][b]] <= value ? b : -1; } int m = (b + e + 1) >> 1; if(a[v[block][m]] <= value) return search(m, e, block, value); else return search(b, m-1, block, value); } void get_done(int b) { if(v[b].empty()) return ; int sz = v[b].size(); nxt[b].resize(sz); dp[b].resize(sz); int pointer = sz-1; for(int i = sz-1; i >= 0; i--) { while(pointer >= 0 && a[v[b][i]] + len < a[v[b][pointer]]) { --pointer; } int id = pointer; if(id == sz - 1) { dp[b][i] = 1; nxt[b][i] = a[v[b][i]] + len; } else { dp[b][i] = dp[b][id + 1] + 1; nxt[b][i] = nxt[b][id + 1]; } } } void init(int N, int L, int X[]) { tot = (N-1) / magic; len = L; n = N; for(int i = 0; i < n; i++) { a[i] = X[i]; } for(int i = 0; i < n; i++) { v[i / magic].push_back(i); bucket[i] = i / magic; } for(int i = 0; i <= tot; i++) { get_done(i); } counter = 0; } int query() { int ans = 0; int cover = -1; for(int i = 0; i <= tot; i++) { if(v[i].empty()) continue; int sz = v[i].size(); int u = search(0, sz-1, i, cover); if(u < sz-1) { ans += dp[i][u + 1]; cover = nxt[i][u + 1]; } } return ans; } void rebuild() { for(int i = 0; i <= tot; i++) { v[i].clear(); } vector <int> pos; for(int i = 0; i < n; i++) { pos.push_back(i); } sort(pos.begin(), pos.end(), cmp); for(int i = 0; i < n; i++) { bucket[pos[i]] = i / magic; v[i / magic].push_back(pos[i]); } for(int i = 0; i <= tot; i++) { get_done(i); } } int update(int i, int y) { ++counter; if(counter == magic) { counter = 0; rebuild(); } int b1 = bucket[i]; int b2 = tot; v[b1].erase(find(v[b1].begin(), v[b1].end(), i)); a[i] = y; for(int x = 0; x <= tot; x++) { if(v[x].empty()) continue; if(a[i] <= a[v[x].back()]) { b2 = x; break; } } bucket[i] = b2; v[b2].push_back(i); sort(v[b2].begin(), v[b2].end(), cmp); get_done(b1); get_done(b2); return query(); }
#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...