Submission #1067255

#TimeUsernameProblemLanguageResultExecution timeMemory
1067255TrinhKhanhDungTrading (IZhO13_trading)C++14
100 / 100
146 ms17236 KiB
#include <bits/stdc++.h> #define ll long long #define fi first #define se second #define sz(x) (int)x.size() #define ALL(v) v.begin(),v.end() #define MASK(k) (1LL << (k)) #define BIT(x, i) (((x) >> (i)) & 1) #define oo (ll)1e18 #define INF (ll)1e9 #define MOD (ll)(1e9 + 19972207) using namespace std; template<class T1, class T2> bool maximize(T1 &a, T2 b){if(a < b){a = b; return true;} return false;} template<class T1, class T2> bool minimize(T1 &a, T2 b){if(a > b){a = b; return true;} return false;} template<class T1, class T2> void add(T1 &a, T2 b){a += b; if(a >= MOD) a -= MOD;} template<class T1, class T2> void sub(T1 &a, T2 b){a -= b; if(a < 0) a += MOD;} template<class T> void cps(T &v){sort(ALL(v)); v.resize(unique(ALL(v)) - v.begin());} struct SegmentTree{ vector<int> val, laz; int n; SegmentTree(int _n = 0){ n = _n; val.resize(4 * n + 3, -1); } void push(int i){ if(val[i] == -1) return; val[i * 2] = val[i * 2 + 1] = val[i]; val[i] = -1; } void upd(int i, int l, int r, int u, int v, int c){ if(r < u || v < l) return; if(u <= l && r <= v){ val[i] = c; return; } push(i); int m = (l + r) >> 1; upd(i * 2, l, m, u, v, c); upd(i * 2 + 1, m + 1, r, u, v, c); } void upd(int u, int v, int c){ upd(1, 1, n, u, v, c); } int get(int p){ int i = 1, l = 1, r = n; while(l < r){ push(i); int m = (l + r) >> 1; if(p <= m){ i = i * 2; r = m; } else{ i = i * 2 + 1; l = m + 1; } } return val[i]; } }; void solve(){ int n, m; cin >> n >> m; vector<int> L(m), R(m), X(m), p(m); for(int i=0; i<m; i++){ cin >> L[i] >> R[i] >> X[i]; p[i] = i; } sort(ALL(p), [&](int i, int j){return X[i] - L[i] < X[j] - L[j];}); SegmentTree it(n); for(int i=0; i<m; i++){ it.upd(L[p[i]], R[p[i]], p[i]); } for(int i=1; i<=n; i++){ int id = it.get(i); if(id == -1){ cout << 0 << ' '; } else{ cout << X[id] + i - L[id] << ' '; } } } int main(){ ios_base::sync_with_stdio(0); cin.tie(0); // freopen("mmgraph.inp", "r", stdin); // freopen("mmgraph.out", "w", stdout); int t = 1; // cin >> t; while(t--){ solve(); } return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...