답안 #1017070

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1017070 2024-07-08T20:15:19 Z aykhn 사탕 분배 (IOI21_candies) C++17
0 / 100
838 ms 85004 KB
#include "candies.h"
#include <bits/stdc++.h>

using namespace std;

#define inf 0x3F3F3F3F

const int MXN = 2e5 + 5;

array<long long, 2> st[MXN << 2];
long long lz[MXN << 2];
vector<array<long long, 2>> add[MXN], del[MXN];

array<long long, 2> combine(array<long long, 2> x, array<long long, 2> y)
{
	return {min(x[0], y[0]), max(x[1], y[1])};
}
void relax(int l, int r, int x)
{
	if (!lz[x]) return;
	st[x][0] += lz[x], st[x][1] += lz[x];
	if (l == r)
	{
		lz[x] = 0;
		return;
	}
	lz[2*x] += lz[x], lz[2*x + 1] += lz[x];
	lz[x] = 0;
}
void upd(int l, int r, int x, int lx, int rx, int val)
{
	relax(l, r, x);
	if (l > rx || r < lx) return;
	if (l >= lx && r <= rx)
	{
		lz[x] += val;
		relax(l, r, x);
		return;
	}
	int mid = (l + r) >> 1;
	upd(l, mid, 2*x, lx, rx, val);
	upd(mid + 1, r, 2*x + 1, lx, rx, val);
	st[x] = combine(st[2*x], st[2*x + 1]);
}
array<long long, 2> get(int l, int r, int x, int lx, int rx)
{
	if (l > rx || r < lx) return {inf, -inf};
	relax(l, r, x);
	if (l >= lx && r <= rx) return st[x];
	int mid = (l + r) >> 1;
	return combine(get(l, mid, 2*x, lx, rx), get(mid + 1, r, 2*x + 1, lx, rx));
}

vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v) 
{
	int n = c.size(), q = l.size();
	for (int i = 0; i < q; i++)
	{
		add[l[i]].push_back({i + 1, v[i]});
		del[r[i]].push_back({i + 1, v[i]});
	}
	vector<int> res(n);
	for (int i = 0; i < n; i++)
	{
		for (array<long long, 2> &x : add[i]) upd(0, q, 1, x[0], q, x[1]);
		array<long long, 2> a = get(0, q, 1, 0, q);
		long long val = get(0, q, 1, q, q)[0];
		if (a[1] - a[0] <= c[i])
		{
			res[i] = val - a[0];
			continue;
		}
		int l = 0, r = q;
		while (l < r)
		{
			int mid = (l + r + 1) >> 1;
			array<long long, 2> x = get(0, q, 1, mid, q);
			if (x[1] - x[0] > c[i]) l = mid;
			else r = mid - 1;
		}
		array<long long, 2> f = get(0, q, 1, l, l);
		array<long long, 2> p = get(0, q, 1, l, q);
		if (f[0] == p[0]) res[i] = (val - (p[1] - c[i]));
		else if (f[0] == p[1]) res[i] = (val - p[0]);
		else assert(0);
		for (array<long long, 2> &x : del[i]) upd(0, q, 1, x[0], q, -x[1]);
	}
	return res;
}
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 12892 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 838 ms 42548 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 10844 KB Output is correct
2 Runtime error 75 ms 85004 KB Execution killed with signal 6
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 12892 KB Output is correct
2 Correct 3 ms 12928 KB Output is correct
3 Correct 123 ms 39104 KB Output is correct
4 Correct 207 ms 16612 KB Output is correct
5 Correct 580 ms 42668 KB Output is correct
6 Correct 612 ms 42908 KB Output is correct
7 Incorrect 678 ms 43648 KB Output isn't correct
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 2 ms 12892 KB Output isn't correct
2 Halted 0 ms 0 KB -