답안 #362720

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
362720 2021-02-04T08:06:47 Z hoaphat1 Fire (JOI20_ho_t5) C++17
컴파일 오류
0 ms 0 KB
#include<bits/stdc++.h>
 
using namespace std;

long long findMaxAttraction(int n, int s, int d, int a[]) {
	long long ans = 0;
	long long now = 0;
  int L = 0, R = -1;
  vector<int> kt(n, 0);
  priority_queue<pair<int, int>, vector<pair<int,int>> , greater<pair<int, int>>> pq;
  priority_queue<pair<int, int>> smaller;
  int sz = 0;
  auto make_true = [&](int m) {
  	while (sz > m && !pq.empty()) {
  		auto x = pq.top();
  		pq.pop();
  		if (kt[x.second] != 1) continue;
  		kt[x.second] = 2;
  		now -= x.first;
  		smaller.push(x);
  		--sz;
		}
		while (sz < m && !smaller.empty()) {
			auto x = smaller.top(); smaller.pop();
			if (kt[x.second] != 2) continue;
			kt[x.second] = 1;
			now += x.first;
			pq.push(x);
			++sz;
		}
	};
  auto add = [&](int id) {
  	int v = a[id];
  	pq.emplace(v, id);
  	now += v;
  	kt[id] = 1;
  	++sz;
	};
	auto del = [&](int id) {
		int v = a[id];
		if (kt[id] == 2) {
			kt[id] = 0;
			return ;
		}
		kt[id] = 0;
		now -= v;
		sz--;
	};
  auto moveL = [&](int l) {
  	while (L < l) del(L++);
  	while (L > l) add(--L);
	};
	auto moveR = [&](int r) {
		while (R < r) add(++R);
		while (R > r) del(R--);
	};
	function<void(int, int, int, int)> solve = [&](int l, int r, int L, int R) {
		if (l > r) return ;
		int mid = l + r >> 1;
		int pos = -1;
		moveR(L);
		moveL(mid);
		long long val = -1;
		for (int i = L; i <= R; i++) {
			moveR(i);
			int lim = d - min(s - mid, i - s) - (i - mid);
			make_true(lim);
			if (val < now) {
				val = now;
				pos = i;
			}
		}
		ans = max(ans, val);
		solve(l, mid - 1, L, pos);
		solve(mid + 1, r, pos, R);
	};
	function<void(int, int, int, int)> solve1 = [&](int l, int r, int L, int R) {
		if (l > r) return ;
		int mid = l + r >> 1;
		int pos = -1;
		moveR(L);
		moveL(mid);
		long long val = -1;
		for (int i = L; i <= R; i++) {
			moveR(i);
			int lim = d - min(s - mid, i - s) - (i - mid);
			make_true(lim);
			if (val < now) {
				val = now;
				pos = i;
			}
		}
		ans = max(ans, val);
		solve1(mid + 1, r, pos, R);
		solve1(l, mid - 1, L, pos);
	};
	solve(max(0, s - d), s, s, min(n - 1, s + d));
	solve1(max(0, s - d), s, s, min(n - 1, s + d));
	return ans;
}

Compilation message

ho_t5.cpp: In lambda function:
ho_t5.cpp:59:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   59 |   int mid = l + r >> 1;
      |             ~~^~~
ho_t5.cpp: In lambda function:
ho_t5.cpp:79:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   79 |   int mid = l + r >> 1;
      |             ~~^~~
/usr/lib/gcc/x86_64-linux-gnu/9/../../../x86_64-linux-gnu/crt1.o: In function `_start':
(.text+0x20): undefined reference to `main'
collect2: error: ld returned 1 exit status