답안 #721000

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
721000 2023-04-10T02:40:46 Z n0sk1ll 사탕 분배 (IOI21_candies) C++17
3 / 100
104 ms 7648 KB
#include <bits/stdc++.h>

#define FAST ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0)
#define mp make_pair
#define xx first
#define yy second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(x) x.begin(),x.end()
#define ff(i,a,b) for (int i = a; i < b; i++)
#define fff(i,a,b) for (int i = a; i <= b; i++)
#define bff(i,a,b) for (int i = b-1; i >= a; i--)
#define bfff(i,a,b) for (int i = b; i >= a; i--)

using namespace std;
long double typedef ld;
unsigned int typedef ui;
long long int typedef li;
pair<int,int> typedef pii;
pair<li,li> typedef pli;
pair<ld,ld> typedef pld;
vector<vector<int>> typedef graph;
unsigned long long int typedef ull;
//const int mod = 998244353;
//const int mod = 1000000007;







//Note to self: Check for overflow

const li mod=1e18;

struct node
{
    li mx1,mx2;
    li mn1,mn2;

    node operator+ (node X)
    {
        node ret;

        if (X.mx1==mx1) ret.mx1=mx1,ret.mx2=max(mx2,X.mx2);
        else if (X.mx1<mx2) ret.mx1=mx1,ret.mx2=mx2;
        else if (mx1<X.mx2) ret.mx1=X.mx1,ret.mx2=X.mx2;
        else if (mx1>X.mx1) ret.mx1=mx1,ret.mx2=X.mx1;
        else ret.mx1=X.mx1,ret.mx2=mx1;

        if (X.mn1==mn1) ret.mn1=mn1,ret.mn2=max(mn2,X.mn2);
        else if (X.mn1>mn2) ret.mn1=mn1,ret.mn2=mn2;
        else if (mn1>X.mn2) ret.mn1=X.mn1,ret.mn2=X.mn2;
        else if (mn1<X.mn1) ret.mn1=mn1,ret.mn2=X.mn1;
        else ret.mn1=X.mn1,ret.mn2=mn1;

        return ret;
    }
} val[550001];
int l[550001],r[550001];
li upd[550001],add[550001];
int k=1;

void Build(int n)
{
    while (k<n) k*=2;
    ff(i,0,k) l[i+k]=i,r[i+k]=i;
    bff(i,1,k) l[i]=l[2*i],r[i]=r[2*i+1];
    ff(i,1,2*k) upd[i]=-1;
    ff(i,1,2*k) val[i]={0,-mod,0,mod};
}

void Upd(int p)
{
    if (upd[p]!=-1)
    {
        val[p]={upd[p],-mod,upd[p],mod};
        if (p<k) upd[2*p]=upd[p],upd[2*p+1]=upd[p];
        upd[p]=-1;
    }

    val[p].mn1+=add[p],val[p].mn2+=add[p],val[p].mx1+=add[p],val[p].mx2+=add[p];
    if (p<k) add[2*p]+=add[p],add[2*p+1]+=add[p];
    add[p]=0;
}

void Add(int p, int ll, int rr, int x)
{
    if (ll>r[p] || rr<l[p]) Upd(p);
    else if (ll<=l[p] && rr>=r[p]) add[p]+=x,Upd(p);
    else Upd(p),Add(2*p,ll,rr,x),Add(2*p+1,ll,rr,x),val[p]=val[2*p]+val[2*p+1];
}

void BeatDown(int p, int ll, int rr, int x)
{
    if (ll>r[p] || rr<l[p]) Upd(p);
    else if (ll<=l[p] && rr>=r[p] && x>=val[p].mx2) add[p]=0,upd[p]=x,Upd(p);
    else Upd(p),BeatDown(2*p,ll,rr,x),BeatDown(2*p+1,ll,rr,x),val[p]=val[2*p]+val[2*p+1];
}

void BeatUp(int p, int ll, int rr, int x)
{
    if (ll>r[p] || rr<l[p]) Upd(p);
    else if (ll<=l[p] && rr>=r[p] && x<=val[p].mn2) add[p]=0,upd[p]=x,Upd(p);
    else Upd(p),BeatUp(2*p,ll,rr,x),BeatUp(2*p+1,ll,rr,x),val[p]=val[2*p]+val[2*p+1];
}

vector<int> distribute_candies(vector<int> c, vector<int> l, vector<int> r, vector<int> v)
{
    int n=(int)c.size();
    int q=(int)v.size();

    if (n<=3000 && q<=3000)
    {
        vector<int> stored(n,0);
        ff(qq,0,q)
        {
            fff(i,l[qq],r[qq]) stored[i]+=v[qq];
            fff(i,l[qq],r[qq]) stored[i]=max(stored[i],0);
            fff(i,l[qq],r[qq]) stored[i]=min(stored[i],c[i]);
        }
        return stored;
    }
    else
    {
        int cap=c[0];
        ff(i,0,q)
        {
            Add(1,l[i],r[i],v[i]);
            if (v[i]>0) BeatDown(1,0,n-1,cap);
            else BeatUp(1,0,n-1,0);
        }
        ff(i,1,2*k) Upd(i);
        vector<int> ans;
        ff(i,0,n) ans.pb(val[i+k].mn1);
        return ans;
    }
}

/*int main()
{
    vector<int> c,l,r,v;
    int n; cin>>n;
    ff(i,0,n)
    {
        int x; cin>>x;
        c.pb(x);
    }

    int q; cin>>q;
    while (q--)
    {
        int ll,rr,vv; cin>>ll>>rr>>vv;
        l.pb(ll),r.pb(rr),v.pb(vv);
    }

    vector<int> ans=distribute_candies(c,l,r,v);
    for (auto it : ans) cout<<it<<" "; cout<<endl;
}*/

//Note to self: Check for overflow
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 220 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 4 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 104 ms 7648 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 212 KB Output is correct
2 Incorrect 48 ms 4984 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Incorrect 51 ms 4976 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 220 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 4 ms 340 KB Output is correct
6 Incorrect 104 ms 7648 KB Output isn't correct
7 Halted 0 ms 0 KB -