1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
| #include <bits/stdc++.h>
#define debug(x) cerr << #x << " = " << x << endl
using namespace std; typedef long long LL;
template <class T> void read(T& x) { x = 0; T f = 1; char ch = getchar(); while (ch < '0' || ch > '9') f = (ch == '-' ? -1 : 1), ch = getchar(); while (ch >= '0' && ch <= '9') x = x * 10 + ch - 48, ch = getchar(); x *= f; }
template <class T, class... Args> void read(T& x, Args&... args) { read(x), read(args...); }
const int MAXN = 2E5 + 5; const int MOD = 1E9 + 7; int n, m, fa[MAXN];
vector<tuple<int, int, int>> v;
struct BIT { int lowbit(int x) { return x & (~x + 1); } BIT() { for (int i = 1; i <= n; i++) c[i] = 0; } void build() { for (int i = 1; i <= n; i++) { int j = i + lowbit(i); if (j <= n) c[j] += c[i]; } } void add(int x, LL val) { while (x <= n) c[x] += val, x += lowbit(x); } LL query(int x, LL res = 0) { while (x) res += c[x], x -= lowbit(x); return res; } array<LL, MAXN> c; } bit[3];
inline void add(int l, int r, LL val) { bit[1].add(l, val), bit[1].add(r + 1, -val); bit[2].add(l, val * l), bit[2].add(r + 1, -val * (r + 1)); }
inline LL query(int l, int r, LL res = 0) { res = bit[0].query(r) + bit[1].query(r) * (r + 1) - bit[2].query(r); res -= bit[0].query(l - 1) + bit[1].query(l - 1) * l - bit[2].query(l - 1); return res; }
int find(int x) { if (fa[x] != x) fa[x] = find(fa[x]); return fa[x]; }
signed main() { read(n, m); for (int i = 1; i <= n; i++) fa[i] = i; v.resize(m); for (auto& [r, l, x] : v) read(l, r, x); sort(v.begin(), v.end()); for (auto& [r, l, x] : v) { int v = query(l, r); if (v >= x) continue; x -= v; int p = r; while (x) { p = find(p); add(p, p, 1); fa[p] = p - 1; x--; } } for (int i = 1; i <= n; i++) printf("%d ", query(i, i)); return 0; }
|