답안 #446436

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
446436 2021-07-21T22:49:41 Z luciocf 사탕 분배 (IOI21_candies) C++17
0 / 100
100 ms 13020 KB
#include <bits/stdc++.h>
#include "candies.h"

using namespace std;

struct Range
{
    int l, r, v;

    bool operator < (const Range &o) const
    {
        l < o.l;
    }
};

set<Range> range;

int C;

int value(int v, int add)
{
    if (add + v > C) return C;
    if (add + v < 0) return 0;
    return add+v;
}

vector<int> distribute_candies(vector<int> c, vector<int> L, vector<int> R, vector<int> V)
{
    C = c[0];
    int n = c.size(), q = L.size();

    range.insert({1, n, 0});

    for (int i = 0; i < q; i++)
    {
        int l = L[i]+1, r = R[i]+1, v = V[i];

        auto it = range.upper_bound({l, n+1, n+1});
        it--;

        if (it->l != l) range.insert({it->l, l-1, it->v});
        range.insert({l, it->r, value(it->v, v)});
        range.erase(it);

        for (auto it = range.upper_bound({l, n+1, n+1}); it != range.end() && it->r <= r; )
        {
            Range k = {it->l, it->r, value(it->v, v)};
            it = range.erase(it);
            range.insert(k);
        }

        it = range.upper_bound({r, n+1, n+1});
        it--;

        range.insert({it->l, r, value(it->v, v)});
        if (r != it->r) range.insert({r+1, it->r, it->v});
        range.erase(it);
    }

    vector<int> ans;

    for (int i = 1; i <= n; i++)
    {
        auto it = range.upper_bound({i, n+1, n+1});
        it--;

        ans.push_back(it->v);
    }

    return ans;
}

Compilation message

candies.cpp: In member function 'bool Range::operator<(const Range&) const':
candies.cpp:12:11: warning: statement has no effect [-Wunused-value]
   12 |         l < o.l;
      |         ~~^~~~~
candies.cpp:13:5: warning: no return statement in function returning non-void [-Wreturn-type]
   13 |     }
      |     ^
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 332 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 100 ms 13020 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 332 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 332 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 332 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -