Submission #1015846

#TimeUsernameProblemLanguageResultExecution timeMemory
1015846u_suck_oComparing Plants (IOI20_plants)C++17
0 / 100
1 ms604 KiB
#include "bits/stdc++.h" #include "plants.h" #define MAXN 10 //200005 #define SZ 10 //524290 using namespace std; pair<int, int> seg[SZ]; int lazy[SZ]; int h[MAXN]; int n, newn; void prop(int node) { seg[2*node].first += lazy[node]; seg[2*node+1].first += lazy[node]; lazy[2*node] += lazy[node]; lazy[2*node+1] += lazy[node]; lazy[node] = 0; } void upd(int node, int l, int r, int ql, int qr, int val) { if (l > qr || r < ql) return; if (ql <= l && r <= qr) { seg[node].first += val; lazy[node] += val; return; } prop(node); int mid = (l+r)/2; upd(2*node, l, mid, ql, qr, val); upd(2*node+1, mid+1, r, ql, qr, val); seg[node] = min(seg[2*node], seg[2*node+1]); } pair<int, int> query(int node, int l, int r, int ql, int qr) { if (l > qr || r < ql) return {1e9, -1}; if (ql <= l && r <= qr) return seg[node]; prop(node); int mid = (l+r)/2; return min(query(2*node, l, mid, ql, qr), query(2*node+1, mid+1, r, ql, qr)); } void init(int k, vector<int> r) { n = r.size(); newn = pow(2, ceil(log2(n))); r.insert(r.begin() + 0, -1); for (int i = 1; i <= n; i++) seg[newn+i-1].second = i; for (int i = 1; i <= n; i++) upd(1, 1, newn, i, i, r[i]); for (int height = n; height >= 1; height--) { //find zeroes int z = query(1, 1, newn, 1, n).second; while (true) { if (z-k+1 >= 1) { auto p = query(1, 1, newn, z-k+1, z-1); if (p.first > 0) break; else z = p.second; } else { auto p1 = query(1, 1, newn, z-k+1+n, n); if (p1.first == 0) z = p1.second; else { auto p2 = query(1, 1, newn, 1, z-1); if (p2.first == 0) z = p2.second; else break; } } } upd(1, 1, newn, z, z, 1e9); h[z] = height; if (z-k+1 >= 1) upd(1, 1, newn, z-k+1, z-1, -1); else { upd(1, 1, newn, z-k+1+n, n, -1); upd(1, 1, newn, 1, z-1, -1); } } return; } int compare_plants(int x, int y) { if (h[x+1] > h[y+1]) return 1; else return -1; return 0; }
#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...