Submission #966632

#TimeUsernameProblemLanguageResultExecution timeMemory
966632vjudge1Trading (IZhO13_trading)C++17
100 / 100
133 ms14040 KiB
#include <iostream>
#include <queue>
#include <algorithm>

using namespace std;
using pii = pair<int, int>;
const int N = 3e5+2;

priority_queue<pii> pq;

struct line{
    int l, r, v, w;
    bool operator < (const line &o) const {
        if (l != o.l) return l < o.l;
        return r < o.r;
    }
}a[N];

int main()
{
    int n, m; scanf("%d %d", &n, &m);
    for (int i = 1;i <= m;i++){
        int l, r, v; scanf("%d %d %d", &l, &r, &v);
        a[i] = {l, r, v, v-l};
    }
    sort(a+1, a+m+1);
    int j = 1;
    for (int i = 1;i <= n;i++){
        while (a[j].l == i) pq.push({a[j].w, a[j].r}), j++;
        while (!pq.empty() && pq.top().second < i) pq.pop();
        if (pq.empty()) printf("0 ");
        else printf("%d ", pq.top().first+i);
    }
}

Compilation message (stderr)

trading.cpp: In function 'int main()':
trading.cpp:21:20: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |     int n, m; scanf("%d %d", &n, &m);
      |               ~~~~~^~~~~~~~~~~~~~~~~
trading.cpp:23:27: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   23 |         int l, r, v; scanf("%d %d %d", &l, &r, &v);
      |                      ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...