이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// 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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |