#define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; class SegmentTree { public: typedef long long T1; typedef long long T2; // データの初期値、以下の条件を満たすこと // uniteData(v, INIT_DATA) == v static const T1 INIT_DATA; // 2つの区間の計算結果v1,v2に対して、 // その2つの区間を統合した区間における計算結果を返す static T1 uniteData(T1 v1, T1 v2){ return max(v1, v2); } private: // 前回の値がprevである要素に対して、 // パラメータxを用いた更新処理を適用した後の計算結果を返す T1 updateData(T1 prev, T2 x){ return max(prev, x); } int n; vector data; void updateTree(int a, int k, int l, int r, T2 x){ if(r - l == 1 && a == l){ data[k] = updateData(data[k], x); } else if(l <= a && a < r){ updateTree(a, k*2+1, l, (l+r+1)/2, x); updateTree(a, k*2+2, (l+r+1)/2, r, x); data[k] = uniteData(data[k*2+1], data[k*2+2]); } } T1 getValue(int a, int b, int k, int l, int r){ if(a <= l && r <= b){ return data[k]; } else if(a < r && l < b){ T1 v1 = getValue(a, b, k*2+1, l, (l+r+1)/2); T1 v2 = getValue(a, b, k*2+2, (l+r+1)/2, r); return uniteData(v1, v2); } else{ return INIT_DATA; } } public: SegmentTree(int n0){ n = 1; while(n < n0) n *= 2; data.assign(2*n-1, INIT_DATA); } SegmentTree(const vector& v) : SegmentTree((int)v.size()){ for(unsigned i=0; i=0; --k) data[k] = uniteData(data[k*2+1], data[k*2+2]); } // a番目の要素にパラメータxによる更新処理を適用 void update(int a, T2 x){ updateTree(a, 0, 0, n, x); } // 区間[a,b)の計算結果を返す T1 get(int a, int b){ return getValue(a, b, 0, 0, n); } }; const SegmentTree::T1 SegmentTree::INIT_DATA = LLONG_MIN / 2; class Data { public: int l, r; long long p; bool operator<(const Data& other) const{ return l < other.l; } }; int main() { int n, m; long long a; cin >> n >> m >> a; vector v(m); for(int i=0; i> v[i].l >> v[i].r >> v[i].p; -- v[i].l; } sort(v.begin(), v.end()); SegmentTree st(n+1); st.update(0, 0); for(int i=0; i