#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') ;
}
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 |
Execution timed out |
1076 ms |
376 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1075 ms |
256 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1086 ms |
256 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1079 ms |
256 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1076 ms |
256 KB |
Time limit exceeded |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1055 ms |
376 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1075 ms |
256 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1074 ms |
256 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1064 ms |
256 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1082 ms |
256 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Execution timed out |
1082 ms |
256 KB |
Time limit exceeded |
2 |
Halted |
0 ms |
0 KB |
- |