Submission #972062

# Submission time Handle Problem Language Result Execution time Memory
972062 2024-04-30T01:35:39 Z penguin133 Distributing Candies (IOI21_candies) C++17
8 / 100
513 ms 59148 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]);
      	assert(ans[i] >= 0 && ans[i] <= c[i]);
	}
	return ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 1 ms 5132 KB Output is correct
3 Incorrect 3 ms 5404 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 513 ms 59148 KB Output is correct
2 Correct 500 ms 59028 KB Output is correct
3 Correct 505 ms 58960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Incorrect 351 ms 53312 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4956 KB Output is correct
2 Correct 1 ms 4956 KB Output is correct
3 Correct 133 ms 52048 KB Output is correct
4 Correct 72 ms 8768 KB Output is correct
5 Incorrect 220 ms 54960 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 4956 KB Output is correct
2 Correct 1 ms 5132 KB Output is correct
3 Incorrect 3 ms 5404 KB Output isn't correct
4 Halted 0 ms 0 KB -