#include <bits/stdc++.h>
#pragma GCC optimize ("O3")
#pragma GCC optimization ("unroll-loops")
using namespace std ;
const int MAX = 3e5 + 5 ;
int arr[MAX] , st[MAX][23] , lg[MAX];
int n ;
void sparse_table()
{
lg[1] = 0 ;
for(int i = 2 ; i < MAX ; ++i)
lg[i] = lg[i / 2] + 1 ;
for(int i = 0 ; i < n ; ++i)
st[i][0] = arr[i] ;
for(int j = 1 ; j <= lg[n] ; ++j)
{
for(int i = 0 ; i + (1 << j) <= n ; ++i)
{
st[i][j] = max(st[i][j-1] , st[i + (1 << (j-1))][j-1]) ;
}
}
return ;
}
int RMQ(int l , int r)
{
int j = lg[r-l+1] ;
return max(st[l][j] , st[r - (1 << j) + 1][j]) ;
}
int readint()
{
char c = getchar() ;
while(true)
{
if(c >= '0' && c <= '9')
break ;
c = getchar() ;
}
int x = (c - '0') ;
c = getchar() ;
while(true)
{
if(c < '0' || c > '9')
break ;
x = x * 10 + (c - '0') ;
c = getchar() ;
}
return x ;
}
int main()
{
n = readint() ;
for(int i = 0 ; i < n ; ++i)
arr[i] = readint() ;
sparse_table() ;
for(int i = 0 ; i < n ; ++i)
{
int ans = 0 ;
for(int j = 1 ; j < n ; ++j)
{
int l = i + (j-1) * (j-1) + 1 ;
int r = i + (j+1) * (j+1) - 1 ;
r = min(r , n-1) ;
if(l >= n)
break ;
ans = max(ans , RMQ(l , r) - arr[i] + j) ;
}
for(int j = 1 ; j < n ; ++j)
{
int r = i - (j-1) * (j-1) - 1 ;
int l = i - (j+1) * (j+1) + 1 ;
l = max(l , 0) ;
if(r < 0)
break ;
ans = max(ans , RMQ(l , r) - arr[i] + j) ;
}
printf("%d\n" , ans) ;
}
return 0 ;
}
Compilation message
pio.cpp:3:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
#pragma GCC optimization ("unroll-loops")
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1528 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
94 ms |
4640 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
186 ms |
6684 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
274 ms |
7980 KB |
Output is correct |
2 |
Correct |
272 ms |
7800 KB |
Output is correct |
3 |
Correct |
271 ms |
8180 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
530 ms |
11156 KB |
Output is correct |
2 |
Correct |
529 ms |
11100 KB |
Output is correct |
3 |
Correct |
517 ms |
11708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1076 ms |
23308 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
48 ms |
1528 KB |
Time limit exceeded (wall clock) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
48 ms |
1488 KB |
Time limit exceeded (wall clock) |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
48 ms |
1528 KB |
Time limit exceeded (wall clock) |
2 |
Halted |
0 ms |
0 KB |
- |