Submission #823270

#TimeUsernameProblemLanguageResultExecution timeMemory
823270fatemetmhrComparing Plants (IOI20_plants)C++17
11 / 100
303 ms83588 KiB
// vaghan ide i nadaram chi benevisam dige :/ #include "plants.h" #include <bits/stdc++.h> using namespace std; #define all(x) x.begin(), x.end() #define fi first #define se second #define mp make_pair #define pb push_back typedef long long ll; const int maxn5 = 2e5 + 10; const int maxnt = 1e6 + 10; const int maxn3 = 310; const int mod = 1e9 + 10; int n, ind[maxn5]; vector <int> av, adj[maxn5]; bool mark[maxn5], rch[maxn3][maxn3]; void dfs(int v){ mark[v] = true; for(auto u : adj[v]) if(!mark[u]) dfs(u); } struct seg{ ll lazy[maxnt]; pair <ll, int> mn[maxnt]; void upd(int l, int r, int id, int val, int v){ if(r - l == 1){ lazy[v] = 0; mn[v] = {val, l}; return; } int mid = (l + r) >> 1; if(id < mid) upd(l, mid, id, val, v * 2); else upd(mid, r, id, val, v * 2 + 1); mn[v] = min(mn[v * 2], mn[v * 2 + 1]); mn[v].fi += lazy[v]; } void add(int l, int r, int lq, int rq, int val, int v){ if(rq <= l || r <= lq) return; if(lq <= l && r <= rq){ lazy[v] += val; mn[v].fi += val; return; } int mid = (l + r) >> 1; add(l, mid, lq, rq, val, v * 2); add(mid, r, lq, rq, val, v * 2 + 1); mn[v] = min(mn[v * 2], mn[v * 2 + 1]); mn[v].fi += lazy[v]; } } seg1, seg2; void init(int k, vector<int> r) { n = r.size(); for(int i = 0; i < n; i++){ seg1.upd(0, n, i, r[i], 1); seg2.upd(0, n, i, r[i], 1); } bool con = true; while(con){ con = false; while(seg1.mn[1].fi == 0){ con = true; int v = seg1.mn[1].se; //cout << "ok seg1 " << v << endl; seg1.upd(0, n, v, mod / 2, 1); if(v < n - 1) seg2.add(0, n, v + 1, min(n, v + k), 1, 1); if(v + k > n) seg2.add(0, n, 0, v + k - n, 1, 1); } if(seg2.mn[1].fi == 0){ con = true; int v = seg2.mn[1].se; //cout << "ok seg2 " << v << ' ' << k << ' ' << (v - (k - 1)) << endl; av.pb(v); seg2.upd(0, n, v, mod / 2, 1); if(v < n - 1) seg2.add(0, n, v + 1, min(n, v + k), -1, 1); if(v + k > n) seg2.add(0, n, 0, v + k - n, -1, 1); if(v){ seg1.add(0, n, max(0, v - (k - 1)), v, -1, 1); seg2.add(0, n, max(0, v - (k - 1)), v, -1, 1); } if(v - (k - 1) < 0){ seg1.add(0, n, v - (k - 1) + n, n, -1, 1); seg2.add(0, n, v - (k - 1) + n, n, -1, 1); } } } //cout << av.size() << endl; reverse(all(av)); for(int i = 0; i < n; i++) ind[av[i]] = i; for(int i = 0; i < n; i++){ int len = k - 1, v = i; while(len--){ v = (v + 1) % n; if(ind[v] < ind[i]) adj[i].pb(v); } len = k - 1; v = i; while(len--){ v = (v - 1 + n) % n; if(ind[v] < ind[i]) adj[i].pb(v); } } for(int i = 0; i < n; i++){ memset(mark, false, sizeof mark); dfs(i); for(int j = 0; j < n; j++) rch[i][j] = mark[j]; } return; } int compare_plants(int x, int y) { if(rch[x][y]) return 1; if(rch[y][x]) 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...