Submission #64635
ソースコード
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 | #include <iostream> #include <vector> #include <algorithm> #include <tuple> using namespace std; // Range Maximum Query(Segment Tree) struct RMQ{ int n, siz; vector< long long > maxv; RMQ( int n) : n(n){ siz = 1; while (n > siz) siz <<= 1; maxv.resize(siz * 2 + 1, 0); } // maxv[p] = v void update( int p, long long v){ p += siz; maxv[p] = v; p >>= 1; while (p){ maxv[p] = max(maxv[p << 1], maxv[(p << 1) + 1]); p >>= 1; } } // [l, r) long long rmq( int l, int r){ l += siz; r += siz; long long res = 0; while (l < r){ if (l & 1){ res = max(res, maxv[l]); ++l; } if (r & 1){ --r; res = max(res, maxv[r]); } l >>= 1; r >>= 1; } return (res); } long long get( int k){ return (maxv[k + siz]); } }; signed main(){ int h, w, n; cin >> h >> w >> n; vector<tuple< int , int , int > > point; for ( int i = 0; i < n; ++i){ int y, x, p; cin >> y >> x >> p; point.emplace_back(y-1, x-1, p); } sort(point.begin(), point.end()); RMQ rmq(w); for (auto [y, x, p] : point){ rmq.update(x, max(rmq.get(x), rmq.rmq(0, x + 1) + p)); } cout << rmq.rmq(0, w) << '\n' ; return (0); } |
ステータス
項目 | データ |
---|---|
問題 | 1436 - Simple Grid Problem |
ユーザー名 | ei1903 |
投稿日時 | 2020-11-07 15:41:51 |
言語 | C++17 |
状態 | Accepted |
得点 | 6 |
ソースコード長 | 1539 Byte |
最大実行時間 | 183 ms |
最大メモリ使用量 | 7732 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 6 / 6 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
in01.txt | AC | 140 ms | 5072 KB |
1
|
in02.txt | AC | 58 ms | 1600 KB |
1
|
in03.txt | AC | 98 ms | 2204 KB |
1
|
in04.txt | AC | 133 ms | 7692 KB |
1
|
in05.txt | AC | 31 ms | 4932 KB |
1
|
in06.txt | AC | 182 ms | 7188 KB |
1
|
in07.txt | AC | 173 ms | 7092 KB |
1
|
in08.txt | AC | 173 ms | 7264 KB |
1
|
in09.txt | AC | 183 ms | 7044 KB |
1
|
in10.txt | AC | 173 ms | 7212 KB |
1
|
in11.txt | AC | 175 ms | 7044 KB |
1
|
in12.txt | AC | 180 ms | 7208 KB |
1
|
in13.txt | AC | 150 ms | 6988 KB |
1
|
in14.txt | AC | 148 ms | 7028 KB |
1
|
in15.txt | AC | 23 ms | 4552 KB |
1
|
in16.txt | AC | 21 ms | 4648 KB |
1
|
in17.txt | AC | 22 ms | 4744 KB |
1
|
in18.txt | AC | 137 ms | 4832 KB |
1
|
in19.txt | AC | 147 ms | 3752 KB |
1
|
in20.txt | AC | 141 ms | 3792 KB |
1
|
in21.txt | AC | 142 ms | 3832 KB |
1
|
in22.txt | AC | 171 ms | 7196 KB |
1
|
in23.txt | AC | 164 ms | 7584 KB |
1
|
in24.txt | AC | 176 ms | 7220 KB |
1
|
in25.txt | AC | 174 ms | 7128 KB |
1
|
in26.txt | AC | 167 ms | 7296 KB |
1
|
in27.txt | AC | 161 ms | 7284 KB |
1
|
in28.txt | AC | 173 ms | 7200 KB |
1
|
in29.txt | AC | 172 ms | 7240 KB |
1
|
in30.txt | AC | 162 ms | 7148 KB |
1
|
in31.txt | AC | 48 ms | 5276 KB |
1
|
in32.txt | AC | 121 ms | 3792 KB |
1
|
in33.txt | AC | 132 ms | 4260 KB |
1
|
in34.txt | AC | 24 ms | 604 KB |
1
|
in35.txt | AC | 166 ms | 7340 KB |
1
|
in36.txt | AC | 164 ms | 7228 KB |
1
|
in37.txt | AC | 182 ms | 7260 KB |
1
|
in38.txt | AC | 21 ms | 660 KB |
1
|
in39.txt | AC | 24 ms | 628 KB |
1
|
in40.txt | AC | 25 ms | 604 KB |
1
|
in41.txt | AC | 165 ms | 7732 KB |
1
|
in42.txt | AC | 171 ms | 7480 KB |
1
|
sample01.txt | AC | 23 ms | 756 KB |
1
|
sample02.txt | AC | 21 ms | 732 KB |
1
|