#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define pb push_back
#define lb lower_bound
#define gibon ios::sync_with_stdio(false); cin.tie(0);
#define fi first
#define se second
#define pii pair<int, int>
#define pll pair<ll, ll>
typedef long long ll;
using namespace std;
const int mxN=500005;
const int mxM=2200005;
const int mxK=61;
const int MOD=1e9+7;
const ll INF=1e18;
int N, Q;
int A[mxN];
int qry[mxN][3];
int F[mxN];
/*
void input(){
cin >> N >> Q;
A[0]=-1e9, A[1]=1e9;
for(int i=2;i<=N+1;i++) cin >> A[i];
A[N+2]=1e9, A[N+3]=-1e9;
for(int i=1;i<=Q;i++){
int l, r, d;
cin >> l >> r >> d;
qry[i][0]=l;
qry[i][1]=r;
qry[i][2]=d;
}
}
*/
void make_F(){
stack <int> stk;
stk.push(1);
for(int i=2;i<=N+1;i++){
while(A[stk.top()]<A[i]) stk.pop();
if(A[i]<A[i-1] || A[i]<A[i+1]) continue;
int mini=1e9;
for(int j=stk.top()+1;j<i;j++) mini=min(mini, A[j]);
F[i]=A[i]-mini;
stk.push(i);
}
while(stk.size()) stk.pop();
stk.push(N+2);
for(int i=N+1;i>=2;i--){
while(A[stk.top()]<A[i]) stk.pop();
if(A[i]<A[i-1] || A[i]<A[i+1]) continue;
int mini=1e9;
for(int j=i+1;j<stk.top();j++) mini=min(mini, A[j]);
F[i]=min(F[i], A[i]-mini);
stk.push(i);
}
while(stk.size()) stk.pop();
stk.push(0);
for(int i=2;i<=N+1;i++){
while(A[stk.top()]>A[i]) stk.pop();
if(A[i]>A[i-1] || A[i]>A[i+1]) continue;
int maxi=-1e9;
for(int j=stk.top()+1;j<i;j++) maxi=max(maxi, A[j]);
F[i]=maxi-A[i];
stk.push(i);
}
stk.push(N+3);
for(int i=N+1;i>=2;i--){
while(A[stk.top()]>A[i]) stk.pop();
if(A[i]>A[i-1] || A[i]>A[i+1]) continue;
int maxi=-1e9;
for(int j=i+1;j<stk.top();j++) maxi=max(maxi, A[j]);
F[i]=min(F[i], maxi-A[i]);
F[i]*=-1;
stk.push(i);
}
//for(int i=1;i<=N;i++) printf("F[%d]=%d\n", i, F[i+1]);
}
void init(int n, vector <int> v){
N=n;
A[0]=-1e9, A[1]=1e9;
for(int i=2;i<=N+1;i++) A[i]=v[i-2];
A[N+2]=1e9, A[N+3]=-1e9;
}
int max_towers(int l, int r, int d){
l+=2, r+=2;
int lp=N+3, lm=N+3, rp=0, rm=0, mcnt=0, pcnt=0;
for(int i=l;i<=r;i++){
if(F[i]>=d) pcnt++, rp=max(rp, i), lp=min(lp, i);
if(F[i]<=-d) mcnt++, rm=max(rm, i), lm=min(lm, i);
}
if(rp!=0 && rp>=rm){
bool ok=false;
for(int i=rp+1;i<=r;i++) if(A[i]<=A[rp]-d) ok=true;
if(ok) mcnt++;
}
if(lp!=N+3 && lp<=lm){
bool ok=false;
for(int i=l;i<lp;i++) if(A[i]<=A[lp]-d) ok=true;
if(ok) mcnt++;
}
return (mcnt<=1 ? 1 : mcnt);
}
/*
int main()
{
gibon
input();
make_F();
for(int i=1;i<=Q;i++){
printf("%d\n", max_towers(qry[i][0], qry[i][1], qry[i][2]));
}
}
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1312 ms |
1112 KB |
12th lines differ - on the 1st token, expected: '2', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '13', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '13', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
3061 ms |
1624 KB |
1st lines differ - on the 1st token, expected: '11903', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
961 ms |
600 KB |
1st lines differ - on the 1st token, expected: '7197', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
344 KB |
1st lines differ - on the 1st token, expected: '13', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1312 ms |
1112 KB |
12th lines differ - on the 1st token, expected: '2', found: '1' |
2 |
Halted |
0 ms |
0 KB |
- |