Submission #467046

# Submission time Handle Problem Language Result Execution time Memory
467046 2021-08-21T12:29:10 Z JvThunder Distributing Candies (IOI21_candies) C++17
29 / 100
455 ms 35056 KB
#include <bits/stdc++.h>
#define pb push_back
typedef long long ll;
using namespace std;
 
const ll INF = (ll)(1e18);

struct segtree
{
    vector<ll> smx, smn, sum; 
    int N;
    segtree()
    {
        N = 1<<18;
        smx.assign(2*N,0);
        smn.assign(2*N,0);
        sum.assign(2*N,0);
    }

    void upd(int i, int s, int e, int t, ll v) 
    {
	    if(s==e) 
        {
            smx[i] = max(0LL, v);
            smn[i] = min(0LL, v);
            sum[i] = v;
            return;
        }
 
        int m=(s+e)/2;
        if(t<=m) upd(2*i, s, m, t, v);
        else upd(2*i+1, m+1, e, t, v);
        
        sum[i] = sum[2*i]+sum[2*i+1];
        smx[i] = max(smx[2*i],sum[2*i]+smx[2*i+1]);
        smn[i] = min(smn[2*i],sum[2*i]+smn[2*i+1]);
        return;
    }
 
    ll get(int i, int s, int e, ll c) 
    {
        if(s==e) return min(max(sum[i], 0LL), c);
    
        int m = (s+e)/2;
        if(smx[2*i+1]-smn[2*i+1]>c) return get(2*i+1, m+1, e, c);
    
        ll r = get(2*i,s,m,c);
        if(r+smx[2*i+1]>c) return c-(smx[2*i+1]-sum[2*i+1]);
        if(r+smn[2*i+1]<0) return sum[2*i+1]-smn[2*i+1];
        return r+sum[2*i+1];
    }

} st;
 
vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v) 
{
	int N=c.size(), Q=l.size();
	vector<int> final_A;
	vector<vector<int>> q(N+1);

	for (int i=0; i<Q; i++) q[l[i]].pb(i), q[r[i]+1].pb(-i);
	for (int i=0; i<N; i++) 
    {
		for (auto j:q[i]) 
        {
			if (j>=0) st.upd(1, 0, Q-1, j, v[j]);
			else st.upd(1, 0, Q-1, -j, 0);
		}
		final_A.pb(st.get(1, 0, Q-1, c[i]));
	}

	return final_A;
}
# Verdict Execution time Memory Grader output
1 Correct 7 ms 12560 KB Output is correct
2 Incorrect 7 ms 12620 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 455 ms 35056 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 8 ms 12620 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 8 ms 12624 KB Output is correct
2 Correct 7 ms 12628 KB Output is correct
3 Correct 129 ms 21724 KB Output is correct
4 Correct 76 ms 21188 KB Output is correct
5 Correct 215 ms 30172 KB Output is correct
6 Correct 211 ms 30776 KB Output is correct
7 Correct 205 ms 31400 KB Output is correct
8 Correct 203 ms 30060 KB Output is correct
9 Correct 209 ms 31568 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 7 ms 12560 KB Output is correct
2 Incorrect 7 ms 12620 KB Output isn't correct
3 Halted 0 ms 0 KB -