답안 #883512

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
883512 2023-12-05T11:33:26 Z nguyentunglam 사탕 분배 (IOI21_candies) C++17
컴파일 오류
0 ms 0 KB
#include<bits/stdc++.h>
#define fi first
#define se second
#define endl "\n"
#define ii pair<int, int>
#define int long long
using namespace std;

const int N = 1e5 + 10;
vector<int> event[N];

vector<long long> distribute_candies (vector<int> c, vector<int> l, vector<int> r, vector<int> v) {
    vector<long long> p;

    int n = c.size();

    for(int i = 0; i < n; i++) {
      event[i].push_back(1e9);
      event[i].push_back(-1e9);
    }

    for(int i = 0; i < v.size(); i++)
    {
        for(int j = l[i]; j <= r[i]; j++)
        {
            event[j].push_back(v[i]);
        }
    }

    for(int i = 0; i < n; i++)
    {
        long long sum = 0, border = 0;

        vector<long long> pref;

        for(int &j : event[i]) {
            sum += j;

            pref.push_back(sum);
        }

        long long mx = -1e18, mn = 1e18;

        for(int j = pref.size() - 1; j >= 0; j--)
        {
            if (pref[j] < mn && mx - pref[j] > c[i]) {
              border = mx - c[i];
              break;
            }

            if (pref[j] > mx && pref[j] - mn > c[i]) {
              border = mn;
              break;
            }

            mn = min(mn, pref[j]);

            mx = max(mx, pref[j]);
        }

        p.push_back(sum - border);
    }

    return p;
}

#ifdef ngu
int32_t main() {

    freopen ("task.inp", "r", stdin);
    freopen ("task.out", "w", stdout);

    int n, q; cin >> n >> q;

    vector<int> c(n), l(q), r(q), v(q);

    for(int i = 0; i < n; i++) cin >> c[i];

    for(int i = 0; i < q; i++) cin >> l[i] >> r[i] >> v[i];

    vector<long long> ans = distribute_candies(c, l, r, v);

    for(long long &j : ans) cout << j << " ";
}
#endif // ngu

Compilation message

candies.cpp: In function 'std::vector<long long int> distribute_candies(std::vector<long long int>, std::vector<long long int>, std::vector<long long int>, std::vector<long long int>)':
candies.cpp:22:22: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |     for(int i = 0; i < v.size(); i++)
      |                    ~~^~~~~~~~~~
/usr/bin/ld: /tmp/cc1f9D7i.o: in function `main':
grader.cpp:(.text.startup+0x30e): undefined reference to `distribute_candies(std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status