Submission #1056525

#TimeUsernameProblemLanguageResultExecution timeMemory
1056525parsadox2Radio Towers (IOI22_towers)C++17
0 / 100
4026 ms15704 KiB
#include <bits/stdc++.h> #include "towers.h" using namespace std; const int N = 1e5 + 10 , inf = 1e9 , Lg = 17; int n , a[N] , rmxq[N][Lg] , rmnq[N][Lg] , lg2[N]; int val[N] , psum[N]; int mn_pos(int aa , int bb) { if(a[aa] < a[bb]) return aa; return bb; } int mx_pos(int aa , int bb) { if(a[aa] > a[bb]) return aa; return bb; } void Build() { lg2[1] = 0; for(int i = 2 ; i < N ; i++) lg2[i] = lg2[i / 2] + 1; for(int i = 0 ; i < n ; i++) rmnq[i][0] = rmxq[i][0] = i; for(int j = 1 ; j < Lg ; j++) { int len = (1 << j); for(int i = 0 ; i + len <= n ; i++) { rmnq[i][j] = mn_pos(rmnq[i][j - 1] , rmnq[i + len / 2][j - 1]); rmxq[i][j] = mx_pos(rmxq[i][j - 1] , rmxq[i + len / 2][j - 1]); } } } int Get_mx(int l , int r) { r++; int sz = (r - l); sz = lg2[sz]; return mx_pos(rmxq[l][sz] , rmxq[r - (1 << sz)][sz]); } int Get_mn(int l , int r) { r++; int sz = (r - l); sz = lg2[sz]; return mn_pos(rmnq[l][sz] , rmnq[r - (1 << sz)][sz]); } void init(int nn , vector <int> vec) { n = nn; for(int i = 0 ; i < n ; i++) a[i] = vec[i]; Build(); } int Solve(int l , int r , int d , int val) { int res = 1; for(int i = l + 1 ; i + 1 <= r ; i++) { if(a[i] - d >= a[i - 1] && a[i] - d >= a[i + 1]) res++; } return res; } int max_towers(int l , int r , int d) { return Solve(l , r , d , inf); }
#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...