Submission #439992

# Submission time Handle Problem Language Result Execution time Memory
439992 2021-07-01T11:12:31 Z tutis Distributing Candies (IOI21_candies) C++17
0 / 100
146 ms 51120 KB
#include "candies.h"

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
struct ST
{
    int l, r;
    int lazy = 0;
    ST *left, *right;
    int mn1;
    int mn2;
    ST(int l, int r, const vector<int>&c): l(l), r(r)
    {
        if (l < r)
        {
            left = new ST(l, (l + r) / 2, c);
            right = new ST((l + r) / 2 + 1, r, c);
            mn1 = min(left->mn1, right->mn1);
            mn2 = min(left->mn2, right->mn2);
        }
        else
        {
            mn1 = 0;
            mn2 = c[l];
        }
    }
    void fix()
    {
        mn1 += lazy;
        mn2 -= lazy;
        if (lazy != 0 && l < r)
        {
            left->lazy += lazy;
            right->lazy += lazy;
        }
        lazy = 0;
    }
    void upd(int x, int y, int del)
    {
        fix();
        if (x <= l && r <= y)
        {
            if (del > 0)
            {
                if (mn2 >= del)
                {
                    lazy += del;
                    return fix();
                }
                else
                {
                    left->upd(x, y, del);
                    right->upd(x, y, del);
                    mn1 = min(left->mn1, right->mn1);
                    mn2 = min(left->mn2, right->mn2);
                }
            }
            if (del < 0)
            {
                if (mn1 >= -del)
                {
                    lazy += del;
                    return fix();
                }
                else
                {
                    left->upd(x, y, del);
                    right->upd(x, y, del);
                    mn1 = min(left->mn1, right->mn1);
                    mn2 = min(left->mn2, right->mn2);
                }
            }
        }
        else if (r < x || y < l)
            return;
        else
        {
            left->upd(x, y, del);
            right->upd(x, y, del);
            mn1 = min(left->mn1, right->mn1);
            mn2 = min(left->mn2, right->mn2);
        }
    }
    void get(vector<int>&c)
    {
        fix();
        if (l < r)
        {
            left->get(c);
            right->get(c);
        }
        else
            c[l] = mn1;
    }
};
vector<int> distribute_candies(vector<int> c, vector<int> l,
                               vector<int> r, vector<int> v) {
    int n = c.size();
    ST med(0, n - 1, c);
    for (int i = 0; i < l.size(); i++)
    {
        med.upd(l[i], r[i], v[i]);
    }
    med.get(c);
    return c;
}

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:101:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  101 |     for (int i = 0; i < l.size(); i++)
      |                     ~~^~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 332 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 146 ms 51120 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 588 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 332 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 1 ms 332 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -