이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "fish.h"
#include<bits/stdc++.h>
using namespace std;
#define int long long int
vector<vector<int>> ind;
vector<vector<pair<int, int>>> pref;
int query(int i, int j) {
    pair<int, int> c = {j, INT64_MAX};
    auto ind1 = upper_bound(pref[i].begin(), pref[i].end(), c);
    ind1--;
    c = *ind1;
    return c.second;
}
int max_weights(int32_t N, int32_t M, vector<int32_t> X, vector<int32_t> Y, vector<int32_t> W) {
    int n = N, m = M;
    pref.resize(n+5, vector<pair<int, int>>(1, {INT64_MIN, 0}));
    ind.resize(n+5);
    for (int i = 0; i < m; i++) {
        pref[X[i]+1].push_back({Y[i], W[i]});
    }
    for (int i = 1; i <= n; i++) {
        sort(pref[i].begin(), pref[i].end());
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j < pref[i].size(); i++) {
            pref[i][j].second += pref[i][j-1].second;
        }
    }
    ind[0].push_back(-1);
    ind[n+1].push_back(-1);
    for (int i = 1; i <= n; i++) {
        for (auto [a, b] : pref[i-1]) {
            ind[i].push_back(a);
        }
        for (auto [a, b] : pref[i+1]) {
            ind[i].push_back(a);
        }
        sort(ind[i].begin(), ind[i].end());
        ind[i].erase(unique(ind[i].begin(), ind[i].end()), ind[i].end());
    }
    vector<vector<int>> dp(2, vector<int>(1, 0)); // 0 is increasing, 1 is decreasing, increasing can go to decreasing, decreasing cant go to increasing if next to eachother
    for (int i = 1; i <= n+1; i++) {
        vector<vector<int>> tdp(2, vector<int>(ind[i].size()+5, 0));
        int v = 0, k = 0;
        for (int j = 0; j < ind[i].size(); j++) {
            while(k < ind[i-1].size() && ind[i-1][k] <= ind[i][j]) {
                v = max(v, dp[0][k]-query(i-1, ind[i-1][k]));
                k++;
            }
            tdp[0][j] = max(v+query(i-1, ind[i][j]), dp[1][0]);
        }
        v = 0, k = ind[i-1].size();
        for (int j = ind[i].size()-1; j >= 0; j--) {
            while(k > 0 && ind[i-1][k-1] >= ind[i][j]) {
                k--;
                v = max(v, max(dp[0][k], dp[1][k])+query(i, ind[i-1][k]));
            }
            tdp[1][j] = v-query(i, ind[i][j]);
        }
        swap(dp[0], tdp[0]);
        swap(dp[1], tdp[1]);
    }
    int ans = max(dp[0][0], dp[1][0]);
    return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
fish.cpp: In function 'long long int max_weights(int32_t, int32_t, std::vector<int>, std::vector<int>, std::vector<int>)':
fish.cpp:25:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |         for (int j = 1; j < pref[i].size(); i++) {
      |                         ~~^~~~~~~~~~~~~~~~
fish.cpp:45:27: 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]
   45 |         for (int j = 0; j < ind[i].size(); j++) {
      |                         ~~^~~~~~~~~~~~~~~
fish.cpp:46:21: 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]
   46 |             while(k < ind[i-1].size() && ind[i-1][k] <= ind[i][j]) {
      |                   ~~^~~~~~~~~~~~~~~~~| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... | 
| # | Verdict | Execution time | Memory | Grader output | 
|---|
| Fetching results... |