Submission #446207

# Submission time Handle Problem Language Result Execution time Memory
446207 2021-07-21T09:08:28 Z arnold518 Distributing Candies (IOI21_candies) C++17
0 / 100
187 ms 15316 KB
#include "candies.h"
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const int MAXN = 2e5;
const ll INF = 1e18;

struct Query
{
    int l, r, v;
};

int N, Q;
int A[MAXN+10];
Query B[MAXN+10];
int ans[MAXN+10];

vector<int> distribute_candies(vector<int> _C, vector<int> _L, vector<int> _R, vector<int> _V)
{
    N=_C.size(); Q=_L.size();
    for(int i=1; i<=N; i++) A[i]=_C[i-1];
    for(int i=1; i<=Q; i++) B[i]={_L[i-1]+1, _R[i-1]+1, _V[i-1]};

    vector<ll> V;
    for(int i=1; i<=Q; i++)
    {
        if(B[i].v>0)
        {
            ll x=0, y=0;
            while(!V.empty())
            {
                ll x2, y2;
                x2=V.back();
                if(V.size()%2) // /
                {
                    y2=x2-x+y;
                }
                else // --
                {
                    y2=y;
                }
                if(y2<x2-B[i].v)
                {
                    V.push_back(y2+B[i].v);
                    break;
                }
                else
                {
                    V.pop_back();
                }
                x=x2; y=y2;
            }
            if(V.empty())
            {
                V.push_back(y+B[i].v);
            }
        }
        else
        {
            ll x=0, y=0;
            while(!V.empty())
            {
                ll x2, y2;
                x2=V.back();
                if(V.size()%2) // /
                {
                    y2=x2-x+y;
                }
                else // --
                {
                    y2=y;
                }
                if(y2>-B[i].v)
                {
                    V.push_back(x2-y2-B[i].v);
                    break;
                }
                else
                {
                    V.pop_back();
                }
                x=x2; y=y2;
            }
        }
        for(auto it : V) printf("%lld ", it); printf("\n");
    }

    vector<pii> V2;
    for(int i=1; i<=N; i++) V2.push_back({A[i], i});
    sort(V2.begin(), V2.end());

    int pt=0;
    ll x=0, y=0;
    while(!V.empty())
    {
        ll x2, y2;
        x2=V.back();
        if(V.size()%2) // /
        {
            y2=x2-x+y;
        }
        else // --
        {
            y2=y;
        }

        for(; pt<V2.size() && V2[pt].first<=x2; pt++)
        {
            if(V.size()%2) // /
            {
                ans[V2[pt].second]=y2-x2+V2[pt].first;
            }   
            else // --
            {
                ans[V2[pt].second]=y2;
            }
        }

        V.pop_back();
        x=x2; y=y2;
    }
    for(; pt<V2.size(); pt++)
    {
        ans[V2[pt].second]=y;
    }
    return vector<int>(ans+1, ans+N+1);
}

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:89:9: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
   89 |         for(auto it : V) printf("%lld ", it); printf("\n");
      |         ^~~
candies.cpp:89:47: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
   89 |         for(auto it : V) printf("%lld ", it); printf("\n");
      |                                               ^~~~~~
candies.cpp:111:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  111 |         for(; pt<V2.size() && V2[pt].first<=x2; pt++)
      |               ~~^~~~~~~~~~
candies.cpp:126:13: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  126 |     for(; pt<V2.size(); pt++)
      |           ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 187 ms 15316 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 204 KB Output isn't correct
2 Halted 0 ms 0 KB -