#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define foru(i, l, r) for(int i = l; i <= r; i++)
#define ford(i, r, l) for(int i = r; i >= l; i--)
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef pair<ii, ii> iiii;
const int N = 1e5 + 5;
const int oo = 1e9 + 7, mod = 1e9 + 7;
int n, a[N];
int ind_mx = 1;
bool sub1 = 0;
void init(int _n, vector<int> _a){
n = _n;
for(int i = 0; i < n; i++) a[i + 1] = _a[i];
for(int i = 2; i <= n; i++) if(a[i] > a[ind_mx]) ind_mx = i;
sub1 = 1;
for(int i = 1; i < ind_mx; i++) sub1 &= (a[i + 1] > a[i]);
for(int i = ind_mx; i < n; i++) sub1 &= (a[i] > a[i + 1]);
}
int dp[N], lstl[N], lstr[N];
int mx[N][20], lg2[20];
int maxi(int l, int r){
if(l > r) return 0;
int k = lg2[r - l + 1];
return max(mx[l][k], mx[r - (1LL << k) + 1][k]);
}
int IT[N << 2];
void upd(int id, int l, int r, int pos, int val){
IT[id] = max(IT[id], val);
if(l == r){
return;
}
int mid = (l + r) >> 1;
if(pos <= mid) upd(id << 1, l, mid, pos, val);
else upd(id << 1 | 1, mid + 1, r, pos, val);
}
int get(int id, int l, int r, int L, int R){
if(l > R || r < L || L > R) return 0;
if(l >= L && r <= R) return IT[id];
int mid = (l + r) >> 1;
return max(get(id << 1, l, mid, L, R), get(id << 1 | 1, mid + 1, r, L, R));
}
int max_towers(int l, int r, int d){
l++, r++;
if(sub1){
if(r <= ind_mx || l >= ind_mx) return 1;
else if(max(a[l], a[r]) > (a[ind_mx] - d)) return 1;
else return 2;
}
else if(n <= 000){
for(int i = l; i <= r; i++){
lstl[i] = -oo, lstr[i] = oo;
for(int j = i + 1; j <= r; j++){
if(a[j] >= (a[i] + d)){
lstr[i] = j;
break;
}
}
for(int j = i - 1; j >= l; j--){
if(a[j] >= (a[i] + d)){
lstl[i] = j;
break;
}
}
//cout << lstl[i] << " " << lstr[i] << "\n";
}
int mx = -1;
for(int i = l; i <= r; i++){
dp[i] = 0;
for(int j = l; j <= i - 1; j++){
if(lstl[i] < lstr[j]) continue;
//cout << i << " " << j << "\n";
dp[i] = max(dp[i], dp[j]);
}
dp[i]++;
mx = max(mx, dp[i]);
}
return mx;
}
else{
for(int i = l; i <= r; i++) mx[i][0] = a[i];
for(int i = 1; i <= 19; i++){
for(int j = l; j <= (r - (1LL << i) + 1); j++){
mx[j][i] = max(mx[j][i - 1], mx[j + (1LL << (i - 1))][i - 1]);
}
}
for(int i = l; i <= r; i++){
if(maxi(i + 1, r) < (a[i] + d)) lstr[i] = oo;
else{
lstr[i] = i;
for(int j = 19; j >= 0; j--){
if(lstr[i] + (1LL << j) > r) continue;
if(mx[lstr[i]][j] < (a[i] + d)){
lstr[i] += (1LL << j);
//cout << i << " " << j << "\n";
}
}
//lstr[i]++;
}
if(maxi(l, i - 1) < (a[i] + d)) lstl[i] = -oo;
else{
lstl[i] = i;
for(int j = 19; j >= 0; j--){
if(lstl[i] - (1LL << j) < l) continue;
if(mx[lstl[i] - (1LL << j) + 1][j] < (a[i] + d)) lstl[i] -= (1LL << j);
}
//lstl[i]--;
}
//cout << i << " " << lstl[i] << " " << lstr[i] << "\n";
}
int mx = -1;
for(int i = 1; i <= (n << 2); i++) IT[i] = 0;
for(int i = l; i <= r; i++){
dp[i] = get(1, 1, n + 1, l, max(lstl[i], l - 1)) + 1;
upd(1, 1, n + 1, min(r + 1, lstr[i]), dp[i]);
mx = max(mx, dp[i]);
//cout << i << " " << dp[i] << "\n";
}
return mx;
}
}
/*
void process(){
int n, q;
vector<int> a;
cin >> n >> q;
for(int i = 0; i < n; i++){
int x;
cin >> x;
a.pb(x);
}
init(n, a);
while(q--){
int l, r, d;
cin >> l >> r >> d;
cout << max_towers(l, r, d) << "\n";
}
}
signed main(){
ios_base::sync_with_stdio(0);
process();
}
*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
407 ms |
944 KB |
Output is correct |
2 |
Correct |
794 ms |
1352 KB |
Output is correct |
3 |
Correct |
641 ms |
1444 KB |
Output is correct |
4 |
Correct |
561 ms |
1372 KB |
Output is correct |
5 |
Correct |
797 ms |
1456 KB |
Output is correct |
6 |
Correct |
710 ms |
1448 KB |
Output is correct |
7 |
Correct |
861 ms |
1340 KB |
Output is correct |
8 |
Correct |
1 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Incorrect |
1 ms |
464 KB |
1st lines differ - on the 1st token, expected: '292', found: '291' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Incorrect |
1 ms |
464 KB |
1st lines differ - on the 1st token, expected: '292', found: '291' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
97 ms |
19604 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
6 ms |
4768 KB |
Execution killed with signal 11 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
336 KB |
Output is correct |
2 |
Incorrect |
1 ms |
464 KB |
1st lines differ - on the 1st token, expected: '292', found: '291' |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
407 ms |
944 KB |
Output is correct |
2 |
Correct |
794 ms |
1352 KB |
Output is correct |
3 |
Correct |
641 ms |
1444 KB |
Output is correct |
4 |
Correct |
561 ms |
1372 KB |
Output is correct |
5 |
Correct |
797 ms |
1456 KB |
Output is correct |
6 |
Correct |
710 ms |
1448 KB |
Output is correct |
7 |
Correct |
861 ms |
1340 KB |
Output is correct |
8 |
Correct |
1 ms |
208 KB |
Output is correct |
9 |
Correct |
1 ms |
208 KB |
Output is correct |
10 |
Correct |
1 ms |
336 KB |
Output is correct |
11 |
Correct |
1 ms |
336 KB |
Output is correct |
12 |
Incorrect |
1 ms |
464 KB |
1st lines differ - on the 1st token, expected: '292', found: '291' |
13 |
Halted |
0 ms |
0 KB |
- |