답안 #436896

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
436896 2021-06-25T07:58:35 Z maomao90 사탕 분배 (IOI21_candies) C++17
컴파일 오류
0 ms 0 KB
#include "candies.h"
#include <bits/stdc++.h>
using namespace std;

#define int ll

#define REP(i, j, k) for (int i = j; i < k; i++)
#define RREP(i, j, k) for (int i = j; i >= k; i--)

template <class T>
inline bool mnto(T& a, T b) {return a > b ? a = b, 1 : 0;}
template <class T>
inline bool mxto(T& a, T b) {return a < b ? a = b, 1 : 0;}


typedef long long ll;
#define MP make_pair
#define FI first
#define SE second
typedef pair<int, int> ii;
#define MT make_tuple
typedef tuple<int, int, int> iii;
#define ALL(x) x.begin(), x.end()
#define pb emplace_back
typedef vector<int> vi;
typedef vector<ii> vii;

#ifdef DEBUG
#define debug(args...) _debug(args)
void _debug(const char* format, ...) {
	va_list args;
	va_start(args, format);
	vprintf(format, args);
	va_end(args);
}
#else
#define debug(args...)
#endif

#define INF 1000000005
#define LINF 1000000000000000005
#define MAXN 200005

int n, q;
vi c;
vi ans;
vi qs[MAXN], qe[MAXN];

#define MLR int mid = lo + hi >> 1; int lc = u * 2, rc = u * 2 + 1
ll mx[MAXN * 4], mn[MAXN * 4], lazy[MAXN * 4];
void propo(int u, int lo, int hi) {
	if (lazy[u] == 0 || lo == hi) return;
	MLR;
	mx[lc] += lazy[u];
	mn[lc] += lazy[u];
	mx[rc] += lazy[u];
	mn[rc] += lazy[u];
	lazy[lc] += lazy[u];
	lazy[rc] += lazy[u];
	lazy[u] = 0;
}
void incre(int s, int e, int x, int u, int lo, int hi) {
	if (lo >= s && hi <= e) {
		lazy[u] += x;
		mn[u] += x;
		mx[u] += x;
		return;
	}
	propo(u, lo, hi);
	MLR;
	if (s <= mid) incre(s, e, x, lc, lo, mid);
	if (e > mid) incre(s, e, x, rc, mid + 1, hi);
	mn[u] = min(mn[lc], mn[rc]);
	mx[u] = max(mx[lc], mx[rc]);
}
void incre(int s, int e, int x) {
	incre(s, e, x, 1, 0, q);
}
ll getmax(int s, int e, int u, int lo, int hi) {
	if (lo >= s && hi <= e) {
		return mx[u];
	}
	propo(u, lo, hi);
	MLR;
	if (e <= mid) return getmax(s, e, lc, lo, mid);
	else if (s > mid) return getmax(s, e, rc, mid + 1, hi);
	else return max(getmax(s, e, lc, lo, mid), getmax(s, e, rc, mid + 1, hi));
}
ll getmax(int s, int e) {
	return getmax(s, e, 1, 0, q);
}
ll getmin(int s, int e, int u, int lo, int hi) {
	if (lo >= s && hi <= e) {
		return mn[u];
	}
	propo(u, lo, hi);
	MLR;
	if (e <= mid) return getmin(s, e, lc, lo, mid);
	else if (s > mid) return getmin(s, e, rc, mid + 1, hi);
	else return min(getmin(s, e, lc, lo, mid), getmin(s, e, rc, mid + 1, hi));

}
ll getmin(int s, int e) {
	return getmin(s, e, 1, 0, q);
}
int upper(int x, ll pmn, ll pmx, int u, int lo, int hi) {
	if (lo == hi) {
		return lo;
	}
	propo(u, lo, hi);
	MLR;
	int npmn = min(pmn, mn[rc]), npmx = max(pmx, mx[rc]);
	if (npmx - npmn > x) {
		return upper(x, pmn, pmx, rc, mid + 1, hi);
	} else {
		return upper(x, npmn, npmx, lc, lo, mid);
	}
}
int upper(int s, ll pmn, ll pmx) {
	return upper(s, pmn, pmx, 1, 0, q);
}

vi distribute_candies(vi c, vi l, vi r, vi v) {
	::c = c;
	n = c.size(); q = l.size();
	l.insert(l.begin(), 0);
	r.insert(r.begin(), 0);
	v.insert(v.begin(), 0);
	REP (i, 1, q + 1) {
		qs[l[i]].pb(i);
		qe[r[i]].pb(i);
	}
	ans.resize(n);
	REP (i, 0, n) {
		for (int &j : qs[i]) {
			incre(j, q, v[j]);
			debug(" incre %d %d: %d\n", j, q, v[j]);
		}
		ll sum = getmax(q, q);
		debug("%lld %lld %lld\n", sum, mx[1], mn[1]);
		if (mx[1] - mn[1] <= c[i]) {
			ans[i] = sum - mn[1];
		} else {
			int id = upper(c[i], LINF, -LINF);
			ll cur = getmax(id, id);
			ll mn = getmin(id + 1, q);
			ll mx = getmax(id + 1, q);
			debug(" %d %lld %lld %lld\n", id, cur, mn, mx);
			if (cur < mn) {
				ans[i] = sum - (mx - c[i]);
			} else {
				ans[i] = sum - mn;
			}
		}
		for (int &j : qe[i]) {
			incre(j, q, -v[j]);
			debug(" decre %d %d: %d\n", j, q, -v[j]);
		}
	}
	return ans;
}

Compilation message

candies.cpp: In function 'void propo(ll, ll, ll)':
candies.cpp:49:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   49 | #define MLR int mid = lo + hi >> 1; int lc = u * 2, rc = u * 2 + 1
      |                       ~~~^~~~
candies.cpp:53:2: note: in expansion of macro 'MLR'
   53 |  MLR;
      |  ^~~
candies.cpp:49:17: warning: unused variable 'mid' [-Wunused-variable]
   49 | #define MLR int mid = lo + hi >> 1; int lc = u * 2, rc = u * 2 + 1
      |                 ^~~
candies.cpp:53:2: note: in expansion of macro 'MLR'
   53 |  MLR;
      |  ^~~
candies.cpp: In function 'void incre(ll, ll, ll, ll, ll, ll)':
candies.cpp:49:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   49 | #define MLR int mid = lo + hi >> 1; int lc = u * 2, rc = u * 2 + 1
      |                       ~~~^~~~
candies.cpp:70:2: note: in expansion of macro 'MLR'
   70 |  MLR;
      |  ^~~
candies.cpp: In function 'll getmax(ll, ll, ll, ll, ll)':
candies.cpp:49:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   49 | #define MLR int mid = lo + hi >> 1; int lc = u * 2, rc = u * 2 + 1
      |                       ~~~^~~~
candies.cpp:84:2: note: in expansion of macro 'MLR'
   84 |  MLR;
      |  ^~~
candies.cpp: In function 'll getmin(ll, ll, ll, ll, ll)':
candies.cpp:49:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   49 | #define MLR int mid = lo + hi >> 1; int lc = u * 2, rc = u * 2 + 1
      |                       ~~~^~~~
candies.cpp:97:2: note: in expansion of macro 'MLR'
   97 |  MLR;
      |  ^~~
candies.cpp: In function 'll upper(ll, ll, ll, ll, ll, ll)':
candies.cpp:49:26: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   49 | #define MLR int mid = lo + hi >> 1; int lc = u * 2, rc = u * 2 + 1
      |                       ~~~^~~~
candies.cpp:111:2: note: in expansion of macro 'MLR'
  111 |  MLR;
      |  ^~~
/usr/bin/ld: /tmp/ccPrdT59.o: in function `main':
grader.cpp:(.text.startup+0x30e): undefined reference to `distribute_candies(std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status