답안 #439996

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
439996 2021-07-01T11:17:39 Z tutis 사탕 분배 (IOI21_candies) C++17
3 / 100
5000 ms 31948 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)
        {
            if (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 (l == r)
            {
                del = max(del, -mn1);
                del = min(del, mn2);
                lazy += del;
                fix();
            }
            else 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);
                }
            }
            else 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:111:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  111 |     for (int i = 0; i < l.size(); i++)
      |                     ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 23 ms 588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5056 ms 25272 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 178 ms 8136 KB Output is correct
3 Correct 194 ms 24740 KB Output is correct
4 Correct 1236 ms 31272 KB Output is correct
5 Correct 2568 ms 31660 KB Output is correct
6 Execution timed out 5082 ms 31948 KB Time limit exceeded
7 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Execution timed out 5082 ms 7748 KB Time limit exceeded
4 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 Correct 1 ms 332 KB Output is correct
4 Correct 2 ms 332 KB Output is correct
5 Correct 23 ms 588 KB Output is correct
6 Execution timed out 5056 ms 25272 KB Time limit exceeded
7 Halted 0 ms 0 KB -