Submission #64656


ソースコード

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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
#include <bits/stdc++.h>
#include <algorithm>
#ifdef _MSC_VER
#include <intrin.h>
#endif
namespace atcoder {
namespace internal {
int ceil_pow2(int n) {
int x = 0;
while ((1U << x) < (unsigned int)(n)) x++;
return x;
}
int bsf(unsigned int n) {
#ifdef _MSC_VER
unsigned long index;
_BitScanForward(&index, n);
return index;
#else
return __builtin_ctz(n);
#endif
}
} // namespace internal
} // namespace atcoder
#include <cassert>
#include <vector>
namespace atcoder {
template <class S, S (*op)(S, S), S (*e)()> struct segtree {
public:
segtree() : segtree(0) {}
segtree(int n) : segtree(std::vector<S>(n, e())) {}
segtree(const std::vector<S>& v) : _n(int(v.size())) {
log = internal::ceil_pow2(_n);
size = 1 << log;
d = std::vector<S>(2 * size, e());
for (int i = 0; i < _n; i++) d[size + i] = v[i];
for (int i = size - 1; i >= 1; i--) {
update(i);
}
}
void set(int p, S x) {
assert(0 <= p && p < _n);
p += size;
d[p] = x;
for (int i = 1; i <= log; i++) update(p >> i);
}
S get(int p) {
assert(0 <= p && p < _n);
return d[p + size];
}
S prod(int l, int r) {
assert(0 <= l && l <= r && r <= _n);
S sml = e(), smr = e();
l += size;
r += size;
while (l < r) {
if (l & 1) sml = op(sml, d[l++]);
if (r & 1) smr = op(d[--r], smr);
l >>= 1;
r >>= 1;
}
return op(sml, smr);
}
S all_prod() { return d[1]; }
template <bool (*f)(S)> int max_right(int l) {
return max_right(l, [](S x) { return f(x); });
}
template <class F> int max_right(int l, F f) {
assert(0 <= l && l <= _n);
assert(f(e()));
if (l == _n) return _n;
l += size;
S sm = e();
do {
while (l % 2 == 0) l >>= 1;
if (!f(op(sm, d[l]))) {
while (l < size) {
l = (2 * l);
if (f(op(sm, d[l]))) {
sm = op(sm, d[l]);
l++;
}
}
return l - size;
}
sm = op(sm, d[l]);
l++;
} while ((l & -l) != l);
return _n;
}
template <bool (*f)(S)> int min_left(int r) {
return min_left(r, [](S x) { return f(x); });
}
template <class F> int min_left(int r, F f) {
assert(0 <= r && r <= _n);
assert(f(e()));
if (r == 0) return 0;
r += size;
S sm = e();
do {
r--;
while (r > 1 && (r % 2)) r >>= 1;
if (!f(op(d[r], sm))) {
while (r < size) {
r = (2 * r + 1);
if (f(op(d[r], sm))) {
sm = op(d[r], sm);
r--;
}
}
return r + 1 - size;
}
sm = op(d[r], sm);
} while ((r & -r) != r);
return 0;
}
private:
int _n, size, log;
std::vector<S> d;
void update(int k) { d[k] = op(d[2 * k], d[2 * k + 1]); }
};
} // namespace atcoder
// header {{{
/**
* @brief all()マクロ
*/
#define all(x) std::begin(x), std::end(x)
#define rall(x) std::rbegin(x), std::rend(x)
/**
* @brief rep()マクロ
*/
#define rep(i, begin, end) for (std::make_signed_t<std::remove_cv_t<decltype(end)>> i = (begin), i##_end = (end); i < i##_end; ++i)
#define repc(i, begin, last) for (std::make_signed_t<std::remove_cv_t<decltype(last)>> i = (begin), i##_last = (last); i <= i##_last; ++i)
#define repr(i, begin, last) for (std::make_signed_t<std::remove_cv_t<decltype(begin)>> i = (begin), i##_last = (last); i >= i##_last; --i)
#define let const auto
/**
* @brief int-alias (整数型のエイリアス)
*/
using i64 = int64_t;
using u64 = uint64_t;
/**
* @brief int-infinity (整数のデカイ値)
* 2倍してもオーバーフローしない & memset()にも使える (需要ある?)
*/
constexpr int32_t INF = 0x3f3f3f3f;
constexpr int64_t LINF = 0x3f3f3f3f3f3f3f3fLL;
/**
* @brief read() (n個入力してContainerに格納して返す)
*/
template <class T = int, template <class, class...> class Container = std::vector>
Container<T> read(size_t n) {
Container<T> ret(n);
for (auto& e : ret) std::cin >> e;
return ret;
}
/**
* @brief std::ostreamによるコンテナの出力
*/
template <class Container, class = typename Container::value_type, std::enable_if_t<!std::is_same<Container, std::string>::value, std::nullptr_t> = nullptr>
std::ostream& operator<<(std::ostream& os, const Container& v) {
for (auto it = std::begin(v); it != std::end(v); ++it) os << &" "[it == std::begin(v)] << *it;
return os;
}
/**
* @brief 複数変数宣言をして同時に入力もするやつ
*/
template <class T>
std::istream& operator,(std::istream& is, T& rhs) {
return is >> rhs;
}
#define var(type, ...) \
type __VA_ARGS__; \
std::cin >> __VA_ARGS__
/**
* @brief println() (可変個の値を空白区切りで出力して改行する)
*/
inline void println() {
std::cout << '\n';
}
template <class Head, class... Tail>
inline void println(Head&& head, Tail&&... tail) {
std::cout << head << &" "[!sizeof...(tail)];
println(std::forward<Tail>(tail)...);
}
/**
* @brief chmin(), chmax()
*/
template <class T, class U>
inline bool chmin(T& a, const U& b) {
return b < a && (a = b, true);
}
template <class T, class U>
inline bool chmax(T& a, const U& b) {
return b > a && (a = b, true);
}
/**
* @brief makeVec() (多次元std::vectorの生成)
*/
template <class T>
inline std::vector<T> makeVec(size_t sz, const T& initValue) {
return std::vector<T>(sz, initValue);
}
template <class T, class... Args>
inline auto makeVec(size_t sz, Args... args) {
return std::vector<decltype(makeVec<T>(args...))>(sz, makeVec<T>(args...));
}
// }}}
using S = i64;
inline S op(S lhs, S rhs) { return std::max(lhs, rhs); }
inline S ident() { return 0; }
using SegTree = atcoder::segtree<S, op, ident>;
using namespace std;
int main() {
cin.tie(nullptr);
ios_base::sync_with_stdio(false);
using Tupl = std::tuple<int, int, int>;
var(int, H, W, N);
vector<Tupl> ps(N);
rep(i, 0, N) {
var(int, y, x, p);
ps[i] = {y, x, p};
}
sort(all(ps));
reverse(all(ps));
SegTree dp(W + 5);
for (let& [y, x, p] : ps) {
dp.set(x, dp.prod(x, W + 5) + p);
}
println(dp.all_prod());
return 0;
}

ステータス

項目 データ
問題 1436 - Simple Grid Problem
ユーザー名 syoribu
投稿日時 2020-11-08 01:15:06
言語 C++17
状態 Accepted
得点 6
ソースコード長 6940 Byte
最大実行時間 94 ms
最大メモリ使用量 8768 KB

セット

セット 得点 Cases
1 ALL 6 / 6 *

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
in01.txt AC 70 ms 2780 KB
1
in02.txt AC 39 ms 1244 KB
1
in03.txt AC 52 ms 1944 KB
1
in04.txt AC 83 ms 7408 KB
1
in05.txt AC 30 ms 5884 KB
1
in06.txt AC 94 ms 8516 KB
1
in07.txt AC 87 ms 8520 KB
1
in08.txt AC 91 ms 8656 KB
1
in09.txt AC 92 ms 8532 KB
1
in10.txt AC 89 ms 8544 KB
1
in11.txt AC 89 ms 8424 KB
1
in12.txt AC 88 ms 8560 KB
1
in13.txt AC 90 ms 8444 KB
1
in14.txt AC 83 ms 8456 KB
1
in15.txt AC 24 ms 6164 KB
1
in16.txt AC 27 ms 6220 KB
1
in17.txt AC 21 ms 6144 KB
1
in18.txt AC 79 ms 2996 KB
1
in19.txt AC 68 ms 3020 KB
1
in20.txt AC 75 ms 3048 KB
1
in21.txt AC 74 ms 2948 KB
1
in22.txt AC 86 ms 8740 KB
1
in23.txt AC 87 ms 8616 KB
1
in24.txt AC 90 ms 8624 KB
1
in25.txt AC 83 ms 8636 KB
1
in26.txt AC 80 ms 8768 KB
1
in27.txt AC 87 ms 8648 KB
1
in28.txt AC 86 ms 8656 KB
1
in29.txt AC 94 ms 8664 KB
1
in30.txt AC 78 ms 8544 KB
1
in31.txt AC 31 ms 6632 KB
1
in32.txt AC 63 ms 2688 KB
1
in33.txt AC 67 ms 3024 KB
1
in34.txt AC 17 ms 636 KB
1
in35.txt AC 86 ms 8652 KB
1
in36.txt AC 87 ms 8660 KB
1
in37.txt AC 86 ms 8668 KB
1
in38.txt AC 20 ms 732 KB
1
in39.txt AC 17 ms 688 KB
1
in40.txt AC 22 ms 772 KB
1
in41.txt AC 76 ms 8668 KB
1
in42.txt AC 89 ms 8676 KB
1
sample01.txt AC 20 ms 620 KB
1
sample02.txt AC 28 ms 704 KB
1