답안 #441421

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
441421 2021-07-05T07:19:17 Z daniel920712 사탕 분배 (IOI21_candies) C++17
0 / 100
379 ms 33244 KB
#include "candies.h"

#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
long long tt;
struct A
{
    long long l,r;
    long long big,small;
    long long add;
    A *nxl,*nxr;
    void UPD()
    {
        nxl->add+=add;
        nxl->big+=add;
        nxl->small+=add;
        nxl->big=min(nxl->big,tt);
        nxl->small=max(nxl->small,(long long) 0);

        nxr->add+=add;
        nxr->big+=add;
        nxr->small+=add;
        nxr->big=min(nxr->big,tt);
        nxr->small=max(nxr->small,(long long) 0);

        add=0;
    }
    void build(long long ll,long long rr)
    {
        l=ll;
        r=rr;
        add=0;
        if(rr==ll+1) return;
        nxl=(A*) malloc(sizeof(A));
        nxr=(A*) malloc(sizeof(A));
        nxl->build(ll,(ll+rr)/2);
        nxr->build((ll+rr)/2,rr);
    }
    void cha(long long ll,long long rr,long long con)
    {
        if(l==ll&&r==rr)
        {
            add+=con;
            big+=con;
            small+=con;
            big=min(big,tt);
            small=max(small,(long long) 0);
            return;
        }
        UPD();
        if(rr<=(l+r)/2) nxl->cha(ll,rr,con);
        else if(ll>=(l+r)/2) nxr->cha(ll,rr,con);
        else
        {
            nxl->cha(ll,(l+r)/2,con);
            nxr->cha((l+r)/2,rr,con);
        }
        big=max(nxl->big,nxr->big);
        small=min(nxl->small,nxr->small);
    }
    long long Find(long long where)
    {
        if(where==l&&where+1==r) return big;
        UPD();
        if(where<(l+r)/2) return nxl->Find(where);
        else return nxr->Find(where);
    }
};
vector < int > ans;
vector < int > distribute_candies(vector < int > c, vector < int > l,vector < int > r, vector < int > v)
{
    long long N=(long long) c.size(),M=(long long) l.size(),i;
    tt=c[0];
    A* root=(A*) malloc(sizeof(A));
    root->build(0,N);
    for(i=0;i<M;i++) root->cha(l[i],r[i]+1,v[i]);
    //printf("aa\n");
    for(i=0;i<N;i++) ans.push_back((int) min((long long)c[i],root->Find(i)));
    return ans;
}
/*
5
1 2 3 4 5
2
0 2 1
1 4 5
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 379 ms 33244 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -