Submission #64659
ソースコード
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 | #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); } }; 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, rmq.rmq(0, x + 1) + p); } cout << rmq.rmq(0, w) << '\n' ; return (0); } |
ステータス
項目 | データ |
---|---|
問題 | 1436 - Simple Grid Problem |
ユーザー名 | ei1903 |
投稿日時 | 2020-11-08 01:27:17 |
言語 | C++17 |
状態 | Accepted |
得点 | 6 |
ソースコード長 | 1479 Byte |
最大実行時間 | 186 ms |
最大メモリ使用量 | 7744 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 6 / 6 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
in01.txt | AC | 139 ms | 5072 KB |
1
|
in02.txt | AC | 68 ms | 1604 KB |
1
|
in03.txt | AC | 110 ms | 2208 KB |
1
|
in04.txt | AC | 142 ms | 6672 KB |
1
|
in05.txt | AC | 28 ms | 4936 KB |
1
|
in06.txt | AC | 177 ms | 7192 KB |
1
|
in07.txt | AC | 172 ms | 7744 KB |
1
|
in08.txt | AC | 174 ms | 6888 KB |
1
|
in09.txt | AC | 170 ms | 7056 KB |
1
|
in10.txt | AC | 169 ms | 7096 KB |
1
|
in11.txt | AC | 186 ms | 7132 KB |
1
|
in12.txt | AC | 174 ms | 7300 KB |
1
|
in13.txt | AC | 148 ms | 7212 KB |
1
|
in14.txt | AC | 143 ms | 7384 KB |
1
|
in15.txt | AC | 21 ms | 4756 KB |
1
|
in16.txt | AC | 21 ms | 4600 KB |
1
|
in17.txt | AC | 19 ms | 4692 KB |
1
|
in18.txt | AC | 147 ms | 4392 KB |
1
|
in19.txt | AC | 140 ms | 3796 KB |
1
|
in20.txt | AC | 140 ms | 4480 KB |
1
|
in21.txt | AC | 144 ms | 5160 KB |
1
|
in22.txt | AC | 161 ms | 7168 KB |
1
|
in23.txt | AC | 168 ms | 7080 KB |
1
|
in24.txt | AC | 164 ms | 7248 KB |
1
|
in25.txt | AC | 167 ms | 7160 KB |
1
|
in26.txt | AC | 167 ms | 7712 KB |
1
|
in27.txt | AC | 161 ms | 7664 KB |
1
|
in28.txt | AC | 162 ms | 7196 KB |
1
|
in29.txt | AC | 169 ms | 7228 KB |
1
|
in30.txt | AC | 160 ms | 7392 KB |
1
|
in31.txt | AC | 44 ms | 5304 KB |
1
|
in32.txt | AC | 119 ms | 3692 KB |
1
|
in33.txt | AC | 136 ms | 4416 KB |
1
|
in34.txt | AC | 21 ms | 632 KB |
1
|
in35.txt | AC | 166 ms | 7120 KB |
1
|
in36.txt | AC | 168 ms | 7288 KB |
1
|
in37.txt | AC | 180 ms | 7712 KB |
1
|
in38.txt | AC | 22 ms | 672 KB |
1
|
in39.txt | AC | 23 ms | 772 KB |
1
|
in40.txt | AC | 26 ms | 740 KB |
1
|
in41.txt | AC | 168 ms | 7352 KB |
1
|
in42.txt | AC | 172 ms | 7132 KB |
1
|
sample01.txt | AC | 19 ms | 660 KB |
1
|
sample02.txt | AC | 26 ms | 760 KB |
1
|