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 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136
| #include <iostream> #include <iterator> #include <numeric> #include <stack> #include <cmath> #include <map> #include <fstream> #include <queue> #include <utility> #include <vector> #include <string> #include <algorithm> #include <set> #include <cstring> #include <iomanip> #include <unordered_map> #include <limits> #define ll long long #define lt __int128 #define ull unsigned long long #define ld long double #define vcmp vector<vector<ll> > #define vec vector<ll> using namespace std; ll n, m, q; ll k; const ll maxn = 2e6+5, maxm = 2e6+5; const ll mod = 1e9+7;
const ll inf = 1e18; const ll N = 1e7+100;
struct Node{ ll data; ll l, r; ll lazy; } t[maxn << 2];
void build(ll p, ll l, ll r){ t[p].l = l; t[p].r = r; t[p].lazy = 0; if(l == r){ t[p].data = 0; return; }
ll mid = (l + r) >> 1; build(p << 1, l, mid); build(p << 1 | 1, mid + 1, r); t[p].data = min(t[p << 1].data, t[p << 1 | 1].data); }
void pushdown(ll p){ if(t[p].lazy == 0) return; t[p<<1].lazy += t[p].lazy; t[p<<1|1].lazy += t[p].lazy; t[p<<1].data += t[p].lazy; t[p<<1|1].data += t[p].lazy; t[p].lazy = 0; }
void add_interval(ll p, ll l, ll r, ll k){ if(l <= t[p].l && t[p].r <= r){ t[p].data += k; t[p].lazy += k; return; }
pushdown(p); ll mid = (t[p].l + t[p].r) >> 1; if(l <= mid) add_interval(p << 1, l, r, k); if(r > mid) add_interval(p << 1 | 1, l, r, k); t[p].data = min(t[p << 1].data, t[p << 1 | 1].data); }
ll query(ll p, ll l, ll r){ if(l <= t[p].l && t[p].r <= r) return t[p].data; pushdown(p); ll mid = (t[p].l + t[p].r) >> 1; ll ans = numeric_limits<ll>::max(); if(l <= mid) ans = min(ans, query(p << 1, l, r)); if(r > mid) ans = min(ans, query(p << 1 | 1, l, r)); return ans; }
void solve() { cin >> n >> m; vec a; vec l(m + 1), r(m + 1), c(m + 1); for (ll i = 1; i <= m; i++) { cin >> l[i] >> r[i] >> c[i]; a.push_back(l[i]); a.push_back(r[i]); } a.push_back(1); a.push_back(n); sort(a.begin(), a.end()); ll x = unique(a.begin(), a.end()) - a.begin();
build(1, 0, x-1);
for (ll i = 1; i <= m; i++) { if(l[i] == r[i]) continue; ll tl = lower_bound(a.begin(), a.begin()+x, l[i]) - a.begin(); ll tr = lower_bound(a.begin(), a.begin()+x, r[i]) - a.begin(); add_interval(1, tl, tr-1, c[i]); } cout << query(1, 0, x - 2) << "\n"; }
int main(){ ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll t = 1; cin >> t; while(t--){ solve(); } return 0; }
|