제출 #123567

#제출 시각아이디문제언어결과실행 시간메모리
123567MohamedAhmed04Lightning Conductor (POI11_pio)C++14
63 / 100
1076 ms23308 KiB
#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 ;
}

컴파일 시 표준 에러 (stderr) 메시지

pio.cpp:3:0: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
 #pragma GCC optimization ("unroll-loops")
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...