#include<bits/stdc++.h>
#include "towers.h"
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()
struct segtree{
vector<int>d;
void init(int n){
d.resize(4*n);
build(1,0,n-1);
}
void build(int v,int l,int r){
if(l==r){
d[v]=0;
return;
}
int mid=(l+r)>>1;
build(v*2,l,mid);
build(v*2+1,mid+1,r);
d[v]=d[v*2]+d[v*2+1];
}
int query(int v,int l,int r,int L,int R){
if(R<L||r<L||R<l) return 0;
if(L<=l&&r<=R){
return d[v];
}
int mid=(l+r)>>1;
return query(v*2,l,mid,L,R)+query(v*2+1,mid+1,r,L,R);
}
void update(int v,int l,int r,int pos,int val){
if(r<pos||pos<l) return;
if(l==r){
d[v]=val;
return;
}
int mid=(l+r)>>1;
update(v*2,l,mid,pos,val);
update(v*2+1,mid+1,r,pos,val);
d[v]=d[v*2]+d[v*2+1];
}
};
segtree sg;
int n;
vector<int>h;
vector<pair<int,int>>v;
vector<bool>used;
void init(int N,vector<int>H){
n=N; h=H;
used.resize(n);
sg.init(n);
for(int i=1;i<n-1;i++){
if(h[i]<h[i-1]&&h[i]<h[i+1]){
sg.update(1,0,n-1,i,1);
}
}
}
int max_towers(int L,int R,int D){
int ans=sg.query(1,0,n-1,L+1,R-1);
if(L<R){
if(h[L]<h[L+1]) ans++;
if(h[R]<h[R-1]) ans++;
}
ans=max(ans,1);
return ans;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
308 ms |
1880 KB |
2nd lines differ - on the 1st token, expected: '1', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '13', found: '16' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '13', found: '16' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
484 ms |
3160 KB |
Output is correct |
2 |
Correct |
629 ms |
3160 KB |
Output is correct |
3 |
Correct |
616 ms |
3160 KB |
Output is correct |
4 |
Correct |
650 ms |
3160 KB |
Output is correct |
5 |
Correct |
653 ms |
2988 KB |
Output is correct |
6 |
Correct |
608 ms |
3160 KB |
Output is correct |
7 |
Correct |
644 ms |
3160 KB |
Output is correct |
8 |
Correct |
635 ms |
3160 KB |
Output is correct |
9 |
Correct |
652 ms |
3160 KB |
Output is correct |
10 |
Correct |
687 ms |
3160 KB |
Output is correct |
11 |
Correct |
615 ms |
3160 KB |
Output is correct |
12 |
Correct |
611 ms |
3160 KB |
Output is correct |
13 |
Correct |
642 ms |
3160 KB |
Output is correct |
14 |
Correct |
0 ms |
344 KB |
Output is correct |
15 |
Correct |
1 ms |
344 KB |
Output is correct |
16 |
Correct |
0 ms |
344 KB |
Output is correct |
17 |
Correct |
12 ms |
3136 KB |
Output is correct |
18 |
Correct |
12 ms |
3160 KB |
Output is correct |
19 |
Correct |
12 ms |
3132 KB |
Output is correct |
20 |
Correct |
9 ms |
3160 KB |
Output is correct |
21 |
Correct |
9 ms |
2984 KB |
Output is correct |
22 |
Correct |
11 ms |
3160 KB |
Output is correct |
23 |
Correct |
12 ms |
2984 KB |
Output is correct |
24 |
Correct |
13 ms |
3160 KB |
Output is correct |
25 |
Correct |
9 ms |
3160 KB |
Output is correct |
26 |
Correct |
9 ms |
3160 KB |
Output is correct |
27 |
Correct |
0 ms |
344 KB |
Output is correct |
28 |
Correct |
0 ms |
344 KB |
Output is correct |
29 |
Correct |
1 ms |
344 KB |
Output is correct |
30 |
Correct |
0 ms |
344 KB |
Output is correct |
31 |
Correct |
1 ms |
344 KB |
Output is correct |
32 |
Correct |
1 ms |
344 KB |
Output is correct |
33 |
Correct |
1 ms |
344 KB |
Output is correct |
34 |
Correct |
0 ms |
344 KB |
Output is correct |
35 |
Correct |
0 ms |
344 KB |
Output is correct |
36 |
Correct |
1 ms |
440 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
187 ms |
1084 KB |
1st lines differ - on the 1st token, expected: '7197', found: '8004' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '13', found: '16' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
308 ms |
1880 KB |
2nd lines differ - on the 1st token, expected: '1', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |