Submission #1064066

#TimeUsernameProblemLanguageResultExecution timeMemory
1064066n1kComparing Plants (IOI20_plants)C++17
0 / 100
38 ms5616 KiB
#include "plants.h" #include <bits/stdc++.h> using namespace std; using ll = long long; struct E { ll x = 1e15, lz=0; E(){}; E(ll xx){x=xx;}; friend E operator+(E a, E b){ return min(a.x, b.x); } void aply(ll add){ x+=add; lz+=add; } }; struct node{ int lb, rb; E x; node *l=nullptr, *r=nullptr; bool ext(){ if(lb<rb and not l){ int mb = (lb + rb) / 2; l = new node{lb, mb}, r = new node{mb+1, rb}; } // push if(l){ l->x.aply(x.lz); r->x.aply(x.lz); x.lz=0; } return l; } E qry(int lo, int hi){ if(hi<lb or rb<lo) return E(); if(lo<=lb and rb<=hi) return x; if(ext()) { E y = l->qry(lo, hi) + r->qry(lo, hi); return y; } return E(); } void upd(int lo, int hi, ll add){ if(hi<lb or rb<lo) return; if(lo<=lb and rb<=hi) { x.aply(add); return; } if(ext()) { l->upd(lo, hi, add), r->upd(lo, hi, add); x = l->x + r->x; } } void bld(vector<int> &v){ if(lb==rb) x.x = v[lb]; if(ext()) { l->bld(v), r->bld(v); x = l->x + r->x; } } }; vector<int> h; void init(int k, std::vector<int> r) { int n = r.size(), t=n; node seg{0, n-1}; seg.bld(r); h.assign(n, 0); auto find = [&](int lb, int rb){ while(lb<rb){ int mb = (lb+rb)/2; if(seg.qry(lb, mb).x==0){ rb=mb; }else{ lb = mb+1; } } return seg.qry(lb, lb).x==0 ? lb : int(-1e9); }; function<void(int)> get = [&](int id){ // find 0 in range (id-k+1, id-1) // if (id-k+1)<0 int lb = id - k + 1, rb = id-1; int nid = -1e9; if(rb>=0){ nid = max(nid, find(max(lb, 0), rb)); }if(lb<0){ nid=max(nid, find((lb+n)%n, n-1)); } if(nid>=0) get(nid); if(rb>=0){ seg.upd(max(lb, 0), rb, -1); }if(lb<0){ seg.upd((lb+n)%n, n-1, -1); } seg.upd(id, id, 1e9); h[id]=t--; }; while(find(0, n-1)>=0){ get(find(0, n-1)); } } int compare_plants(int x, int y) { return h[x]>h[y] ? 1 : -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...