답안 #480889

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
480889 2021-10-18T15:12:44 Z rumen_m 사탕 분배 (IOI21_candies) C++17
0 / 100
5000 ms 15964 KB
#include "candies.h"
#include <bits/stdc++.h>
#include <vector>
using namespace std;
const int MAXN = 2e6+2;
int c[MAXN];
vector <int> ans;
struct Segment
{
    int minel[MAXN],maxel[MAXN], lazy[MAXN];
    void update_lazy(int v, int from, int to)
    {
        if(lazy[v]==0)return ;
        minel[2*v]+=lazy[v];
        maxel[2*v]+=lazy[v];
        minel[2*v+1]+=lazy[v];
        maxel[2*v+1]+=lazy[v];
        lazy[2*v]+=lazy[v];
        lazy[2*v+1]+=lazy[v];
        lazy[v] = 0;
    }
    void update(int v,int from, int to, int l, int r, int delta)
    {
           // cout<<"UPDATE:: "<<v<<" "<<from<<" "<<to<<" "<<l<<" "<<r<<" "<<delta<<endl;
        if(from==to)
        {
            minel[v] = max(0, min(c[from],minel[v]+delta));
            maxel[v] = max(0, min(c[from],maxel[v]+delta));
          //  cout<<v<<" "<<minel[v]<<" "<<maxel[v]<<endl;
            return ;
        }
         update_lazy(v,from,to);
         int mid = (from+to)/2;
        if(l<=from&&to<=r)
        {
            minel[v]+=delta;
            maxel[v]+=delta;
            if(minel[v]<0||maxel[v]>c[0])
            {
                update(2*v,from,mid,l,r,delta);
                update(2*v+1,mid+1,to,l,r,delta);
                minel[v] = min(minel[2*v],minel[2*v+1]);
                maxel[v] = max(maxel[2*v],maxel[2*v+1]);
            }
            else
                lazy[v]+=delta;
            return ;
        }
        update(2*v,from,mid,l,r,delta);
        update(2*v+1,mid+1,to,l,r,delta);
        minel[v] = min(minel[2*v],minel[2*v+1]);
                maxel[v] = max(maxel[2*v],maxel[2*v+1]);
               // cout<<v<<" "<<minel[v]<<" "<<maxel[v]<<endl;
    }
    void query(int v, int from, int to)
    {
        if(from==to)
        {
            ans[from] =  minel[v];
            return ;
        }
        int mid = (from+to)/2;
        update_lazy(v,from,to);
        query(2*v,from,mid);
        query(2*v+1,mid+1,to);
    }
};
Segment S;
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();
    int i,j;
    for(i = 0; i<n;i++)
        c[i] = _c[i];
    for(i=0;i<l.size();i++)
    {
        S.update(1,0,n-1,l[i],r[i],v[i]);
    }
    ans.resize(n);

    return ans;
}

Compilation message

candies.cpp: In function 'std::vector<int> distribute_candies(std::vector<int>, std::vector<int>, std::vector<int>, std::vector<int>)':
candies.cpp:74:14: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   74 |     for(i=0;i<l.size();i++)
      |             ~^~~~~~~~~
candies.cpp:71:11: warning: unused variable 'j' [-Wunused-variable]
   71 |     int i,j;
      |           ^
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5048 ms 15964 KB Time limit exceeded
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 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -