Submission #951835

# Submission time Handle Problem Language Result Execution time Memory
951835 2024-03-22T18:50:47 Z simona1230 Distributing Candies (IOI21_candies) C++17
8 / 100
267 ms 37552 KB
#include <bits/stdc++.h>
#include "candies.h"
using namespace std;


vector<pair<long long,long long> > pt;

bool cmp(pair<long long,long long> p1,pair<long long,long long> p2)
{
    if(p1.first==p2.first)return p1.second<p2.second;
    return p1.first<p2.first;
}

vector<pair<long long,long long> > s;

long long lz[800001],ans[200001];
long long c[200001];
void push_lazy(long long i,long long l,long long r)
{
    if(l==r)
    {
        ans[l]=lz[i];
        return;
    }
    if(lz[i]>0)
    {
        lz[i*2]=lz[i]+lz[i*2];
        lz[i*2+1]=lz[i]+lz[i*2+1];
    }
    if(lz[i]<0)
    {
        lz[i*2]=max(lz[i]+lz[i*2],1LL*0);
        lz[i*2+1]=max(lz[i]+lz[i*2+1],1LL*0);
    }
    lz[i]=0;
}
void update(long long i,long long lf,long long rt,long long ql,long long qr,long long val)
{
    push_lazy(i,lf,rt);
    if(ql>qr)return;
    if(ql<=lf&&rt<=qr)
    {
        lz[i]+=val;
        push_lazy(i,lf,rt);
        return;
    }
    long long m=(lf+rt)/2;
    update(i*2,lf,m,ql,min(qr,m),val);
    update(i*2+1,m+1,rt,max(ql,m+1),qr,val);
}
long long n,q,l[200001],r[200001],v[200001];
vector<int> distribute_candies(vector<int> C, vector<int> L, vector<int> R, vector<int> V)
{
    vector<int> res;
    n = C.size();
    for(long long i=1;i<=n;i++)
        c[i]=C[i-1];
    q = V.size();
    for(long long i=1;i<=q;i++)
        l[i]=L[i-1]+1,r[i]=R[i-1]+1,v[i]=V[i-1];

    for(long long i=1;i<=q;i++)
    {
        pt.push_back({l[i],0});
        pt.push_back({r[i],1});
    }

    sort(pt.begin(),pt.end(),cmp);

    for(long long i=1;i<pt.size();i++)
    {
        long long l=pt[i-1].first,r=pt[i].first;
        if(pt[i-1].second==1)l++;
        if(pt[i].second==0)r--;
        if(l>r)continue;
        //cout<<l<<" "<<r<<endl;
        s.push_back({l,r});
    }

    for(long long i=1;i<=q;i++)
    {
        update(1,1,n,l[i],r[i],v[i]);
    }

    for(long long i=1;i<=n;i++)
        update(1,1,n,i,i,0);
    for(long long i=1;i<=n;i++)
        res.push_back(min(c[i],ans[i]));
    return res;
}
/*
3
10 10 10
2
0 2 20
0 1 -11
*/

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:70:24: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |     for(long long i=1;i<pt.size();i++)
      |                       ~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Incorrect 1 ms 6492 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 247 ms 33820 KB Output is correct
2 Correct 244 ms 37304 KB Output is correct
3 Correct 267 ms 37552 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 6492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 6492 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 6488 KB Output is correct
2 Incorrect 1 ms 6492 KB Output isn't correct
3 Halted 0 ms 0 KB -