답안 #441470

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
441470 2021-07-05T08:29:35 Z daniel920712 사탕 분배 (IOI21_candies) C++17
11 / 100
350 ms 33472 KB
#include "candies.h"

#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
using namespace std;
struct A
{
    long long l,r;
    long long big,small;
    long long add;
    A *nxl,*nxr;
    void build(long long ll,long long rr)
    {
        //printf("%lld %lld\n",ll,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)
    {
        //printf("%lld %lld %lld %lld\n",l,r,ll,rr);
        if(l==ll&&r==rr)
        {
            add+=con;
            return;
        }
        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);
        }
    }
    long long Find(long long where)
    {
        if(where==l&&where+1==r) return add;
        if(where<(l+r)/2) return add+nxl->Find(where);
        else return add+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,j;
    if(N<=2000&&M<=2000)
    {
        for(i=0;i<N;i++) ans.push_back(0);
        for(i=0;i<M;i++)
        {
            for(j=l[i];j<=r[i];j++)
            {
                ans[j]+=v[i];
                ans[j]=max(0,ans[j]);
                ans[j]=min(ans[j],c[j]);
            }

        }
        return ans;
    }
    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 1 ms 204 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 4 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 350 ms 33464 KB Output is correct
2 Correct 338 ms 33444 KB Output is correct
3 Correct 341 ms 33472 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Incorrect 115 ms 5588 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Incorrect 65 ms 5588 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 296 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 4 ms 332 KB Output is correct
6 Correct 350 ms 33464 KB Output is correct
7 Correct 338 ms 33444 KB Output is correct
8 Correct 341 ms 33472 KB Output is correct
9 Correct 1 ms 204 KB Output is correct
10 Incorrect 115 ms 5588 KB Output isn't correct
11 Halted 0 ms 0 KB -