Submission #404018

#TimeUsernameProblemLanguageResultExecution timeMemory
404018SamAndComparing Plants (IOI20_plants)C++17
0 / 100
4108 ms525812 KiB
#include "plants.h" #include <bits/stdc++.h> using namespace std; #define all(x) (x).begin(),(x).end() #define sz(x) ((int)(x).size()) #define m_p make_pair #define fi first #define se second const int N = 200005; int n, k; vector<int> r; pair<int, int> t[N * 4]; int laz[N * 4]; void shi(int pos) { t[pos * 2].fi += laz[pos]; t[pos * 2 + 1].fi += laz[pos]; laz[pos] = 0; } void bil(int tl, int tr, int pos) { if (tl == tr) { t[pos] = m_p(r[tl], tl); return; } int m = (tl + tr) / 2; bil(tl, m, pos * 2); bil(m + 1, tr, pos * 2 + 1); t[pos] = min(t[pos * 2], t[pos * 2 + 1]); } void ubd(int tl, int tr, int l, int r, int y, int pos) { if (l > r) return; if (tl == l && tr == r) { t[pos].fi += y; laz[pos] += y; return; } shi(pos); int m = (tl + tr) / 2; ubd(tl, m, l, min(m, r), y, pos * 2); ubd(m + 1, tr, max(m + 1, l), r, y, pos * 2 + 1); t[pos] = min(t[pos * 2], t[pos * 2 + 1]); } pair<int, int> qry(int tl, int tr, int l, int r, int pos) { if (l > r) return m_p(N, 0); if (tl == l && tr == r) return t[pos]; shi(pos); int m = (tl + tr) / 2; return min(qry(tl, m, l, min(m, r), pos * 2), qry(m + 1, tr, max(m + 1, l), r, pos * 2 + 1)); } vector<int> ans; void rec(int i) { while (1) { pair<int, int> u = m_p(N, 0); if (i - k + 1 >= 0) { u = min(u, qry(0, n - 1, i - k + 1, i - 1, 1)); } else { u = min(u, qry(0, n - 1, 0, i - 1, 1)); u = min(u, qry(0, n - 1, n + (i - k + 1), n - 1, 1)); } if (u.fi) break; rec(u.se); } ans.push_back(i); } void init(int k, vector<int> r) { n = sz(r); ::k = k; ::r = r; bil(0, n - 1, 1); rec(t[1].fi); } int compare_plants(int x, int y) { if (lower_bound(all(ans), x) - ans.begin() < lower_bound(all(ans), y) - ans.begin()) return 1; return -1; }
#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...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...