Submission #81815

#TimeUsernameProblemLanguageResultExecution timeMemory
81815mra2322001Trading (IZhO13_trading)C++14
100 / 100
383 ms6844 KiB
#include <bits/stdc++.h> #define f0(i, n) for(int i(0); i < (n); i++) #define f1(i, n) for(int i(1); i <= n; i++) using namespace std; typedef long long ll; const int N = 300002; int n, m, t[4*N]; void push(int k, int l, int r){ int mid = (l + r)/2; if(l==r) return ; t[k*2] = max(t[2*k], t[k]); if(t[k]) t[k*2 + 1] = max(t[k*2 + 1], t[k] + mid - l + 1); } void up(int k, int l, int r, int i, int j, int x){ push(k, l, r); if(r < i || l > j) return ; if(l >= i && r <= j){ int now = x + l - i; t[k] = max(t[k], now); push(k, l, r); return ; } int mid = (l + r)/2; up(k*2, l, mid, i, j, x); up(k*2 + 1, mid + 1, r, i, j, x); } int get1(int k, int l, int r, int i){ push(k, l, r); if(l==r) return t[k]; int mid = (l + r)/2; if(i <= mid) return get1(k*2, l, mid, i); return get1(k*2 + 1, mid + 1, r, i); } int main(){ ios_base::sync_with_stdio(0); cin >> n >> m; while(m--){ int l, r, x; cin >> l >> r >> x; up(1, 1, n, l, r, x); } f1(i, n) cout << get1(1, 1, n, i) << " "; }
#Verdict Execution timeMemoryGrader output
Fetching results...