This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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++;
}
return ans;
}
# | 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... |