제출 #832513

#제출 시각아이디문제언어결과실행 시간메모리
832513fatemetmhrRadio Towers (IOI22_towers)C++17
0 / 100
685 ms18208 KiB
// komak! #include "towers.h" #include <bits/stdc++.h> using namespace std; #define debug(x) cerr << "(" << (#x) << "): " << (x) << endl; #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 ll mod = 1e9 + 7; const int maxn5 = 1e5 + 10; const int lg = 20; int mxid, h[maxn5]; int n, dp[maxn5], dp2[maxn5]; pair <int, int> mx[lg][maxn5]; int nolef[maxn5], norig[maxn5], ps[maxn5]; int get_max(int l, int r){ int k = 31 - __builtin_clz(r - l + 1); return max(mx[k][l], mx[k][r - (1 << k) + 1]).se; } void solve(int l, int r){ if(r <= l) return; int mid = get_max(l, r - 1); solve(l, mid); solve(mid + 1, r); if(r - l == 1) ps[l] = 1; if(l == mid) norig[mid] = true; if(r - 1 == mid) nolef[mid] = true; } void init(int N, std::vector<int> H) { mxid = 0; n = N; for(int i = 0; i < n; i++){ h[i] = H[i]; if(h[i] > h[mxid]) mxid = i; mx[0][i] = {h[i], i}; } for(int i = 1; i < lg; i++) for(int j = 0; j < n; j++) mx[i][j] = max(mx[i - 1][j], (j + (1 << (i - 1)) < n ? mx[i - 1][j + (1 << (i - 1))] : mp(0, 0))); solve(0, n); for(int i = 1; i < n; i++) ps[i] += ps[i - 1]; } int max_towers(int l, int r, int d) { return ps[r] - (l ? ps[l - 1] : 0) + (norig[l] && !nolef[l]) + (!norig[r] + nolef[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...