Submission #942740

#TimeUsernameProblemLanguageResultExecution timeMemory
942740KG07Comparing Plants (IOI20_plants)C++14
0 / 100
4066 ms6592 KiB
#include "plants.h" #include <bits/stdc++.h> using namespace std; struct segment_tree{ int hmin[800008], lazy[800008]; vector<int> m, H; int n, h, k; void init(int K, vector<int> M){ n = M.size(); h = n-1; k = K; m.clear(); for(int i = 0; i < 800008; i++){ hmin[i] = 0; lazy[i] = 0; } for(int i = 0; i < M.size(); i++){ m.push_back(M[i]); H.push_back(-1); } init_heights(1, 1, n); } void lazy_update(int N){ lazy[2*N] += lazy[N]; lazy[2*N+1] += lazy[N]; hmin[2*N] += lazy[N]; hmin[2*N+1] += lazy[N]; lazy[N] = 0; } void update(int N, int l, int r, int s, int t){ if(l > t || r < s)return; if(l <= s && r >= t){ lazy[N]--; hmin[N]--; return; } lazy_update(N); update(2*N, l, r, s, (s+t)/2); update(2*N+1, l, r, (s+t)/2+1, t); } void init_heights(int N, int l, int r){ if(l == r){ hmin[N] = m[r-1]; return; } init_heights(2*N, l, (l+r)/2); init_heights(2*N+1, (l+r)/2+1, r); hmin[N] = min(hmin[2*N], hmin[2*N+1]); } int get_min(int N, int l, int r, int s, int t){ if(l > t || r < s)return 1000000000; if(l <= s && r >= t)return hmin[N]; lazy_update(N); return min(get_min(2*N, l, r, s, (s+t)/2), get_min(2*N+1, l, r, (s+t)/2+1, t)); } int right_zero(int N, int l, int r, int s, int t){ if(l > t || r < s)return -1; if(s == t)return hmin[N] == 0 ? t : -1; lazy_update(N); int z = right_zero(2*N, l, r, s, (s+t)/2); return z == -1 ? right_zero(2*N+1, l, r, (s+t)/2+1, t) : z; } void extract(int N, int M, int l, int r){ if(l > M || r < M)return; if(l == r){ if(M < n && right_zero(1, M+1, min(M+k, n), 1, n) != -1){ extract(1, right_zero(1, M+1, min(M+k, n), 1, n), 1, n); } else if(M+k > n && right_zero(1, 1, M+k-n, 1, n) != -1){ extract(1, right_zero(1, 1, M+k-n, 1, n), 1, n); } hmin[N] = 1000000; if(M < n)update(1, M+1, min(M+k, n), 1, n); if(M+k > n)update(1, 1, M+k-n, 1, n); H[M-1] = h--; return; } lazy_update(N); extract(2*N, M, l, (l+r)/2); extract(2*N+1, M, (l+r)/2+1, r); } } A; void init(int k, vector<int> r) { A.init(k-1, r); int n = r.size(); while(A.h >= 0){ A.extract(1, A.right_zero(1, 1, n, 1, n), 1, n); } return; } int compare_plants(int x, int y) { return A.H[x] > A.H[y] ? 1 : -1; }

Compilation message (stderr)

plants.cpp: In member function 'void segment_tree::init(int, std::vector<int>)':
plants.cpp:18:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   18 |         for(int i = 0; i < M.size(); i++){
      |                        ~~^~~~~~~~~~
#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...