답안 #972053

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
972053 2024-04-30T01:26:08 Z penguin133 사탕 분배 (IOI21_candies) C++17
8 / 100
546 ms 56908 KB
#include <bits/stdc++.h>
using namespace std;
#include "candies.h"
//#define int long long
typedef long long ll;
#define pi pair<int, int>
#define pii pair<int, pi>
#define fi first
#define se second
#ifdef _WIN32
#define getchar_unlocked _getchar_nolock
#endif
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

struct dat{
	ll sm, mx, mn, mxpre, mnpre, mxsuf, mnsuf;
};

dat comb(dat a, dat b){
	dat ans;
	ans.sm = a.sm + b.sm;
	ans.mx = max({a.mx, b.mx, a.mxsuf + b.mxpre});
	ans.mn = min({a.mn, b.mn, a.mnsuf + b.mnpre});
	ans.mxpre = max(a.mxpre, a.sm + b.mxpre);
	ans.mnpre = min(a.mnpre, a.sm + b.mnpre);
	ans.mxsuf = max(b.mxsuf, b.sm + a.mxsuf);
	ans.mnsuf = min(b.mnsuf, b.sm + a.mnsuf);
	return ans;
}

struct node{
	int s, e, m;
	dat val;
	node *l, *r;
	node(int _s, int _e){
		s = _s, e = _e, m = (s + e) >> 1;
		if(s != e)l = new node(s, m), r = new node(m + 1, e);
		val.sm = val.mx = val.mn = val.mxpre = val.mnpre = val.mxsuf = val.mnsuf = 0;
	}
	
	void upd(int p, int v){
		if(s == e){
			val.sm = val.mx = val.mn = val.mxpre = val.mnpre = val.mxsuf = val.mnsuf = v;
		}
		else{
			if(p <= m)l->upd(p, v);
			else r->upd(p, v);
			val = comb(l->val, r->val);
		}
	}
	
	ll fd(ll cap){
		if(s == e)return (val.sm > cap ? cap : (val.sm < 0 ? 0 : val.sm));
		if(r->val.mx > cap || r->val.mn < -cap)return r->fd(cap);
		else if(l->val.mxsuf + r->val.mxpre > cap)return r->val.sm - r->val.mxpre + cap;
		else if(l->val.mnsuf + r->val.mnpre < -cap)return r->val.sm - r->val.mnpre;
		else return l->fd(cap) + r->val.sm;
	}
}*root;

vector <pi> Q[200005];
std::vector<int> distribute_candies(std::vector<int> c, std::vector<int> l,
                                    std::vector<int> r, std::vector<int> v) {
    int n = c.size(), q = (int)l.size();
    for(int i = 0; i < q; i++){
		Q[l[i]].push_back({i + 1, v[i]});
		Q[r[i] + 1].push_back({i + 1, 0});
	}
	root = new node(0, q);
	vector <int> ans(n);
	for(int i = 0; i < n; i++){
		for(auto [a, b] : Q[i]){
			root->upd(a, b);
		}
		root->upd(0, -c[i]);
		ans[i] = root->fd(c[i]);
	}
	return ans;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Incorrect 3 ms 5412 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 546 ms 56828 KB Output is correct
2 Correct 523 ms 56788 KB Output is correct
3 Correct 526 ms 56908 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 5152 KB Output is correct
2 Incorrect 415 ms 54532 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 5208 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Correct 135 ms 50692 KB Output is correct
4 Correct 76 ms 9152 KB Output is correct
5 Incorrect 221 ms 56420 KB Output isn't correct
6 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 4952 KB Output is correct
2 Correct 2 ms 4956 KB Output is correct
3 Incorrect 3 ms 5412 KB Output isn't correct
4 Halted 0 ms 0 KB -