#include "towers.h"
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const ll INF=1e18+7;
const int LIM=1e5+7;
ll T[LIM], jaki[LIM], n;
set<pair<ll,ll>>S, P;
vector<pair<ll,ll>>ans;
void dodaj(int x) {
auto it=S.lower_bound({x, -1}); ++it;
auto a=*it;
P.insert({abs(T[x]-T[a.st]), x});
}
void usun(int x) {
auto it=S.lower_bound({x, -1}); ++it;
auto a=*it;
P.erase({abs(T[x]-T[a.st]), x});
}
void init(int _n, vector<int>_H) {
n=_n;
rep(i, n) T[i+1]=_H[i];
T[0]=T[n+1]=INF;
int akt=2;
jaki[0]=jaki[n+1]=1;
rep(i, n) if((T[i]<T[i+1] && T[i+1]>T[i+2]) || (T[i]>T[i+1] && T[i+1]<T[i+2])) {
jaki[i+1]=akt;
akt^=3;
}
rep(i, n+2) if(jaki[i]) S.insert({i, jaki[i]});
auto it=S.begin();
while(true) {
auto it2=it; ++it2;
if(it2==S.end()) break;
auto a=*it;
dodaj(a.st);
++it;
}
ans.pb({0, S.size()/2});
while(P.size()>2) {
auto a=*P.begin();
usun(a.nd);
auto it=S.lower_bound({a.nd, -1});
++it;
auto b=*it;
usun(b.st);
--it; --it;
b=*it;
usun(b.st);
++it;
S.erase(it);
it=S.lower_bound({a.nd, -1});
S.erase(it);
it=S.lower_bound({a.nd, -1});
--it;
b=*it;
dodaj(b.st);
ans.pb({a.st, S.size()/2});
}
}
int max_towers(int l, int r, int d) {
int po=0, ko=ans.size()-1;
while(po<ko) {
int sr=(po+ko+1)/2;
if(ans[sr].st<=d) po=sr; else ko=sr-1;
}
return ans[po].nd;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
298 ms |
1368 KB |
1st lines differ - on the 1st token, expected: '1', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
1st lines differ - on the 1st token, expected: '13', found: '131' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
1st lines differ - on the 1st token, expected: '13', found: '131' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
620 ms |
11984 KB |
1st lines differ - on the 1st token, expected: '11903', found: '33010' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
213 ms |
3176 KB |
Output is correct |
2 |
Correct |
749 ms |
12232 KB |
Output is correct |
3 |
Incorrect |
754 ms |
12280 KB |
66712th lines differ - on the 1st token, expected: '21557', found: '21556' |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
344 KB |
1st lines differ - on the 1st token, expected: '13', found: '131' |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
298 ms |
1368 KB |
1st lines differ - on the 1st token, expected: '1', found: '2' |
2 |
Halted |
0 ms |
0 KB |
- |