Submission #971280

#TimeUsernameProblemLanguageResultExecution timeMemory
971280ind1vTrading (IZhO13_trading)C++11
100 / 100
202 ms22700 KiB
#include <bits/stdc++.h>

using namespace std;

const int N = 3e5 + 5;

int n, m;
multiset<int> mts;
int a[N];
vector<array<int, 3>> e;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= m; i++) {
    int l, r, x;
    cin >> l >> r >> x;
    e.push_back(array<int, 3>{l, x - l, 0});
    e.push_back(array<int, 3>{r + 1, x - l, 1});
  }
  memset(a, -0x3f, sizeof(a));
  sort(e.begin(), e.end());
  for (int i = 1, j = 0; i <= n; i++) {
    while (j < (int) e.size() && e[j][0] <= i) {
      if (e[j][2] == 0) {
        mts.insert(e[j][1]);
      } else {
        mts.erase(mts.find(e[j][1]));
      }
      j++;
    }
    if (mts.empty()) {
      cout << 0 << ' ';
    } else {
      cout << *mts.rbegin() + i << ' ';
    }
  }
  return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...