답안 #824997

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
824997 2023-08-14T13:01:37 Z QwertyPi Hacker (BOI15_hac) C++14
컴파일 오류
0 ms 0 KB
#include <bits/stdc++.h>
using namespace std;

const int MAXN = 5e5 + 11;
const int LGN = 21;
unsigned int a[MAXN], s[MAXN * 3], b[MAXN * 2];

struct SparseTable{
	int st[LGN][MAXN * 2];
	void init(int n, int* a, int (*g)(int, int)){
		f = g;
		for(int i = 0; i < n; i++) st[0][i] = a[i];
		for(int j = 1; j < LGN; j++){
			for(int i = 0; i <= n - (1 << j); i++){
				st[j][i] = f(st[j - 1][i], st[j - 1][i + (1 << j - 1)]);
			}
		}
	}

	int qry(int l, int r){
		int d = __lg(r - l + 1);
		return f(st[d][l], st[d][r - (1 << d) + 1]);
	}
	int (*f)(int, int);
} ST;

int32_t main(){
	int n; cin >> n;
	for(int i = 0; i < n; i++) cin >> a[i];
	for(int i = 0; i < n; i++) a[i + n * 2] = a[i + n] = a[i];
	for(int i = 0; i < n * 3; i++) s[i + 1] = s[i] + a[i];
	for(int i = 0; i < n * 2; i++) b[i] = s[i + (n + 1) / 2] - s[i];
	ST.init(n * 2, b, [](int a, int b){ return min(a, b); });
	int ans = 0;
	for(int i = 0; i < n; i++){
		ans = max(ans, ST.qry(i, i + (n + 1) / 2 - 1));
	}
	cout << ans << endl;
}

Compilation message

hac.cpp: In member function 'void SparseTable::init(int, int*, int (*)(int, int))':
hac.cpp:15:54: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   15 |     st[j][i] = f(st[j - 1][i], st[j - 1][i + (1 << j - 1)]);
      |                                                    ~~^~~
hac.cpp: In function 'int32_t main()':
hac.cpp:33:17: error: invalid conversion from 'unsigned int*' to 'int*' [-fpermissive]
   33 |  ST.init(n * 2, b, [](int a, int b){ return min(a, b); });
      |                 ^
      |                 |
      |                 unsigned int*
hac.cpp:10:24: note:   initializing argument 2 of 'void SparseTable::init(int, int*, int (*)(int, int))'
   10 |  void init(int n, int* a, int (*g)(int, int)){
      |                   ~~~~~^