Submission #64658
ソースコード
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:20:54 |
言語 | C++17 |
状態 | Accepted |
得点 | 6 |
ソースコード長 | 1466 Byte |
最大実行時間 | 191 ms |
最大メモリ使用量 | 7716 KB |
セット
セット | 得点 | Cases | |
---|---|---|---|
1 | ALL | 6 / 6 | * |
テストケース
ファイル名 | 状態 | 実行時間 | メモリ使用量 | # |
---|---|---|---|---|
in01.txt | AC | 136 ms | 5072 KB |
1
|
in02.txt | AC | 57 ms | 1484 KB |
1
|
in03.txt | AC | 118 ms | 2340 KB |
1
|
in04.txt | AC | 136 ms | 7448 KB |
1
|
in05.txt | AC | 26 ms | 5052 KB |
1
|
in06.txt | AC | 174 ms | 7048 KB |
1
|
in07.txt | AC | 172 ms | 7212 KB |
1
|
in08.txt | AC | 172 ms | 7696 KB |
1
|
in09.txt | AC | 168 ms | 7084 KB |
1
|
in10.txt | AC | 173 ms | 7124 KB |
1
|
in11.txt | AC | 178 ms | 7160 KB |
1
|
in12.txt | AC | 186 ms | 7704 KB |
1
|
in13.txt | AC | 148 ms | 7080 KB |
1
|
in14.txt | AC | 155 ms | 7120 KB |
1
|
in15.txt | AC | 26 ms | 4744 KB |
1
|
in16.txt | AC | 20 ms | 4584 KB |
1
|
in17.txt | AC | 20 ms | 4676 KB |
1
|
in18.txt | AC | 151 ms | 3864 KB |
1
|
in19.txt | AC | 144 ms | 3780 KB |
1
|
in20.txt | AC | 150 ms | 3824 KB |
1
|
in21.txt | AC | 158 ms | 4504 KB |
1
|
in22.txt | AC | 157 ms | 7360 KB |
1
|
in23.txt | AC | 161 ms | 7140 KB |
1
|
in24.txt | AC | 166 ms | 7180 KB |
1
|
in25.txt | AC | 169 ms | 7092 KB |
1
|
in26.txt | AC | 182 ms | 7000 KB |
1
|
in27.txt | AC | 171 ms | 7164 KB |
1
|
in28.txt | AC | 191 ms | 7716 KB |
1
|
in29.txt | AC | 177 ms | 7140 KB |
1
|
in30.txt | AC | 163 ms | 7176 KB |
1
|
in31.txt | AC | 52 ms | 5300 KB |
1
|
in32.txt | AC | 127 ms | 4588 KB |
1
|
in33.txt | AC | 143 ms | 4928 KB |
1
|
in34.txt | AC | 15 ms | 644 KB |
1
|
in35.txt | AC | 165 ms | 7128 KB |
1
|
in36.txt | AC | 163 ms | 7296 KB |
1
|
in37.txt | AC | 175 ms | 7464 KB |
1
|
in38.txt | AC | 20 ms | 600 KB |
1
|
in39.txt | AC | 27 ms | 700 KB |
1
|
in40.txt | AC | 19 ms | 672 KB |
1
|
in41.txt | AC | 169 ms | 7284 KB |
1
|
in42.txt | AC | 186 ms | 7324 KB |
1
|
sample01.txt | AC | 17 ms | 724 KB |
1
|
sample02.txt | AC | 18 ms | 572 KB |
1
|