Submission #1036601

#TimeUsernameProblemLanguageResultExecution timeMemory
1036601Dan4LifeComparing Plants (IOI20_plants)C++17
0 / 100
39 ms12880 KiB
#include "plants.h" #include <bits/stdc++.h> using namespace std; #define pb push_back #define sz(a) (int)a.size() #define all(a) begin(a), end(a) using ar2 = array<int,2>; const int mxN = (int)2e5+10; const int INF = (int)1e9; int n, comp[mxN], COMP; vector<int> adj[mxN]; int deg[mxN], ord[mxN]; int h[mxN]; template<class T, int SZ> struct SegTree{ T seg[SZ], lzy[SZ]; void init(){ for(int i = 0; i < SZ; i++) seg[i]=0, lzy[i]=0; } void prop(int p, int l, int r){ if(!lzy[p] or l==r) return; int mid = (l+r)/2; int rp = p+2*(mid-l+1); seg[p+1]+=lzy[p]; seg[rp]+=lzy[p]; lzy[p+1]+=lzy[p]; lzy[rp]+=lzy[p]; lzy[p]=0; } void upd(int i, int j, int v, int p=0, int l=0, int r=n-1){ if(i>r or j<l or i>j) return; prop(p,l,r); if(i<=l and r<=j){ seg[p]+=v; lzy[p]+=v; return; } int mid = (l+r)/2; int rp = p+2*(mid-l+1); if(i<=mid) upd(i,j,v,p+1,l,mid); if(j>mid) upd(i,j,v,rp,mid+1,r); seg[p] = min(seg[p+1],seg[rp]); } int findFirstMin(int i, int j, int p=0, int l=0, int r=n-1){ if(i>r or j<l or i>j) return -1; prop(p,l,r); if(l==r) return l; int mid = (l+r)/2; int rp = p+2*(mid-l+1); prop(p+1,l,mid); if(seg[p+1]==seg[p]) return findFirstMin(i,j,p+1,l,mid); return findFirstMin(i,j,rp,mid+1,r); } T query(int i, int p=0, int l=0, int r=n-1){ if(i<l or i>r) return INF; prop(p,l,r); if(l==r) return seg[p]; int mid = (l+r)/2; int rp = p+2*(mid-l+1); if(i<=mid) return query(i,p+1,l,mid); return query(i,rp,mid+1,r); } }; const int mxSeg = 2*mxN; SegTree<int,mxSeg> segTree; void init(int k, vector<int> r) { n = sz(r); k--; segTree.init(); int xd = n; for(int i = 0; i < n; i++) segTree.upd(i,i,r[i]); while(1){ int i = segTree.findFirstMin(0,n-1); if(i==-1 or segTree.query(i)) break; int i1 = segTree.findFirstMin(n-k+i,n-1); if(i1!=-1 and !segTree.query(i1)) i = i1; if(i>=k){ if(segTree.query(segTree.findFirstMin(i-k,i-1))==0) break; segTree.upd(i-k,i-1,-1); } else{ if(segTree.query(segTree.findFirstMin(0,i-1))==0) break; if(segTree.query(segTree.findFirstMin(n-k+i,n-1))==0) break; segTree.upd(0,i-1,-1), segTree.upd(n-k+i,n-1,-1); } segTree.upd(i,i,mxN); h[i]=xd; xd--; } } int compare_plants(int x, int y) { return h[x]>h[y]?1:-1; }

Compilation message (stderr)

plants.cpp: In member function 'void SegTree<T, SZ>::upd(int, int, int, int, int, int)':
plants.cpp:33:3: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   33 |   if(i>r or j<l or i>j) return; prop(p,l,r);
      |   ^~
plants.cpp:33:33: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   33 |   if(i>r or j<l or i>j) return; prop(p,l,r);
      |                                 ^~~~
plants.cpp: In member function 'int SegTree<T, SZ>::findFirstMin(int, int, int, int, int)':
plants.cpp:42:3: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   42 |   if(i>r or j<l or i>j) return -1; prop(p,l,r);
      |   ^~
plants.cpp:42:36: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   42 |   if(i>r or j<l or i>j) return -1; prop(p,l,r);
      |                                    ^~~~
plants.cpp: In member function 'T SegTree<T, SZ>::query(int, int, int, int)':
plants.cpp:51:3: warning: this 'if' clause does not guard... [-Wmisleading-indentation]
   51 |   if(i<l or i>r) return INF; prop(p,l,r);
      |   ^~
plants.cpp:51:30: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'if'
   51 |   if(i<l or i>r) return INF; prop(p,l,r);
      |                              ^~~~
#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...