Submission #1049902

#TimeUsernameProblemLanguageResultExecution timeMemory
1049902fuad27Comparing Plants (IOI20_plants)C++17
14 / 100
4080 ms10580 KiB
#include "plants.h" #include <bits/stdc++.h> using namespace std; struct lazy_segtree { vector<int> v; lazy_segtree(vector<int> &a) { v=a; } void update(int l, int r, int add) { for(int i = l;i<=r;i++)v[i]+=add; } pair<int,int> query(int l, int r){ if(r < l)return pair{1e9, 1e9}; pair<int,int> p = {v[l], l}; for(int i = l;i<=r;i++)p=min(p, pair{v[i], i}); return p; } }; vector<int> H; void init(int k, std::vector<int> r) { int n = r.size(); lazy_segtree ls(r); int cnt = n; H.resize(n, -1); auto dfs = [&](int at, auto &&dfs) -> void { if(at >= k-1) { pair<int,int> val = ls.query(at-k+1, at-1); while(val.first == 0) { dfs(val.second, dfs); val = ls.query(at-k+1, at-1); } H[at] = cnt--; ls.update(at-k+1, at-1, -1); ls.update(at, at, 1e9); } else { pair<int,int> val = min(ls.query(0, at-1), ls.query(n-k+at+1, n-1)); while(val.first == 0) { dfs(val.second, dfs); val = min(ls.query(0, at-1), ls.query(n-k+at+1, n-1)); } H[at] = cnt--; ls.update(0, at-1, -1), ls.update(n-k+at+1, n-1, -1); ls.update(at, at, 1e9); } }; while(ls.query(0, n-1).first == 0) { dfs(ls.query(0, n-1).second, dfs); } return; } int compare_plants(int x, int y) { if(H[x] < H[y])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...