#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
struct segtree{
int k = 1;
vector<int> v;
segtree(int n){
while(k < n) k*=2;
v.assign(2*k, 0);
}
void update(int i, int x){
i+=k;
v[i] = x;
i/=2;
while(i){
v[i] = max(v[2*i], v[2*i+1]);
i/=2;
}
}
int get(int l, int r, int nd, int a, int b){
if(a > r || b < l) return 0;
if(a >= l && b <= r) return v[nd];
int md = (a+b)/2;
return max(get(l, r, 2*nd, a, md), get(l, r, 2*nd+1, md+1, b));
}
int get(int l, int r){
if(l > r) return 0;
return get(l, r, 1, 0, k-1);
}
};
int n;
vector<int> h;
segtree seg(0);
vector<int> DL, DR, DLR;
vector<int> dc, dcr;
void init(int _n, vector<int> _h){
swap(n, _n);
swap(h, _h);
seg = segtree(n);
DR.assign(n, 1e9);
DL.assign(n, 1e9);
DLR.assign(n, 1e9);
dc.resize(n);
dcr.resize(n);
for(int i = 0; i < n; i++) seg.update(i, h[i]);
for(int i = n-1; i >= 0; i--){
dc[i] = i;
if(i+1 < n && h[i] > h[i+1]) dc[i] = dc[i+1];
}
for(int i = 0; i < n; i++){
dcr[i] = i;
if(i && h[i] > h[i-1]) dcr[i] = dcr[i-1];
}
stack<int> st;
for(int i = n-1; i >= 0; i--){
while(!st.empty() && h[i] < h[st.top()]){
DL[st.top()] = max(0, seg.get(i, st.top())-h[st.top()]);
st.pop();
}
st.push(i);
}
while(!st.empty()) st.pop();
for(int i = 0; i < n; i++){
while(!st.empty() && h[i] < h[st.top()]){
DR[st.top()] = max(0, seg.get(st.top(), i)-h[st.top()]);
st.pop();
}
st.push(i);
}
while(!st.empty()) st.pop();
for(int i = 0; i < n; i++) DLR[i] = min(DL[i], DR[i]);
}
int max_towers(int L, int R, int D){
if(dc[L] >= dcr[R]) return 1;
int ans = 0;
for(int i = L; i <= dc[L]; i++) if(DR[i] >= D) ans++;
for(int i = dcr[R]; i <= R; i++) if(DL[i] >= D) ans++;
for(int i = dc[L]+1; i <= dcr[R]-1; i++) if(DLR[i] >= D) ans++;
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
753 ms |
2668 KB |
18th lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Incorrect |
1 ms |
336 KB |
1st lines differ - on the 1st token, expected: '34', found: '33' |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Incorrect |
1 ms |
336 KB |
1st lines differ - on the 1st token, expected: '34', found: '33' |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
4042 ms |
4016 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1845 ms |
1104 KB |
Output is correct |
2 |
Execution timed out |
4046 ms |
4172 KB |
Time limit exceeded |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
208 KB |
Output is correct |
2 |
Correct |
1 ms |
336 KB |
Output is correct |
3 |
Correct |
1 ms |
336 KB |
Output is correct |
4 |
Correct |
1 ms |
336 KB |
Output is correct |
5 |
Correct |
1 ms |
336 KB |
Output is correct |
6 |
Correct |
1 ms |
336 KB |
Output is correct |
7 |
Incorrect |
1 ms |
336 KB |
1st lines differ - on the 1st token, expected: '34', found: '33' |
8 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
753 ms |
2668 KB |
18th lines differ - on the 1st token, expected: '1', found: '0' |
2 |
Halted |
0 ms |
0 KB |
- |