結果
問題 | No.1826 Fruits Collecting |
ユーザー | pockyny |
提出日時 | 2022-01-28 22:57:40 |
言語 | C++17 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 1,253 ms / 2,000 ms |
コード長 | 6,246 bytes |
コンパイル時間 | 3,195 ms |
コンパイル使用メモリ | 234,692 KB |
実行使用メモリ | 152,124 KB |
最終ジャッジ日時 | 2024-06-09 16:29:37 |
合計ジャッジ時間 | 26,840 ms |
ジャッジサーバーID (参考情報) |
judge1 / judge3 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 3 ms
6,816 KB |
testcase_01 | AC | 5 ms
6,940 KB |
testcase_02 | AC | 5 ms
6,940 KB |
testcase_03 | AC | 7 ms
6,940 KB |
testcase_04 | AC | 3 ms
6,940 KB |
testcase_05 | AC | 396 ms
67,048 KB |
testcase_06 | AC | 781 ms
118,372 KB |
testcase_07 | AC | 477 ms
75,128 KB |
testcase_08 | AC | 36 ms
12,768 KB |
testcase_09 | AC | 677 ms
90,228 KB |
testcase_10 | AC | 432 ms
71,380 KB |
testcase_11 | AC | 440 ms
71,488 KB |
testcase_12 | AC | 155 ms
33,388 KB |
testcase_13 | AC | 65 ms
18,916 KB |
testcase_14 | AC | 106 ms
23,264 KB |
testcase_15 | AC | 1,217 ms
151,908 KB |
testcase_16 | AC | 1,187 ms
151,952 KB |
testcase_17 | AC | 1,198 ms
151,932 KB |
testcase_18 | AC | 1,186 ms
151,920 KB |
testcase_19 | AC | 1,239 ms
151,980 KB |
testcase_20 | AC | 1,210 ms
152,008 KB |
testcase_21 | AC | 1,220 ms
152,124 KB |
testcase_22 | AC | 1,214 ms
151,904 KB |
testcase_23 | AC | 1,237 ms
151,944 KB |
testcase_24 | AC | 1,192 ms
151,980 KB |
testcase_25 | AC | 2 ms
6,944 KB |
testcase_26 | AC | 2 ms
6,940 KB |
testcase_27 | AC | 2 ms
6,944 KB |
testcase_28 | AC | 2 ms
6,940 KB |
testcase_29 | AC | 3 ms
6,940 KB |
testcase_30 | AC | 144 ms
37,760 KB |
testcase_31 | AC | 324 ms
70,888 KB |
testcase_32 | AC | 274 ms
36,556 KB |
testcase_33 | AC | 1,253 ms
120,352 KB |
testcase_34 | AC | 988 ms
84,928 KB |
testcase_35 | AC | 163 ms
23,644 KB |
testcase_36 | AC | 1,236 ms
118,972 KB |
testcase_37 | AC | 419 ms
80,540 KB |
testcase_38 | AC | 296 ms
65,888 KB |
testcase_39 | AC | 510 ms
104,668 KB |
testcase_40 | AC | 633 ms
119,232 KB |
testcase_41 | AC | 124 ms
30,284 KB |
testcase_42 | AC | 17 ms
8,412 KB |
testcase_43 | AC | 2 ms
6,940 KB |
testcase_44 | AC | 3 ms
7,644 KB |
testcase_45 | AC | 2 ms
6,940 KB |
ソースコード
#include<bits/stdc++.h> #define rep(i,a,b) for(int i=a;i<b;i++) #define rrep(i,a,b) for(int i=a;i>=b;i--) #define fore(i,a) for(auto &i:a) #pragma GCC optimize ("-O3") using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); } //--------------------------------------------------------------------------------------------------- typedef long long ll; #define def 0 using V = ll; V comp(V& l, V& r) { return max(l,r); }; struct SegTree { //[l,r) int NV; vector<V> val; void init(int n) { NV = 1; while (NV < n) NV *= 2; val = vector<V>(NV * 2, def); } V get(int x, int y, int l, int r, int k) { if (r <= x || y <= l) return def; if (x <= l&&r <= y)return val[k]; auto a = get(x, y, l, (l + r) / 2, k * 2); auto b = get(x, y, (l + r) / 2, r, k * 2 + 1); return comp(a, b); } V get(int x, int y) { return get(x, y, 0, NV, 1); } void update(int i, V v) { i += NV; val[i] = v; while (i>1)i >>= 1, val[i] = comp(val[i * 2], val[i * 2 + 1]); } void add(int i, V v) { update(i, val[i + NV] + v); } V operator[](int x) { return get(x, x + 1); } }; struct Healthy2DSegTree { int NV; vector<SegTree> st; vector<vector<int>> index; void init(vector<vector<int>> &v) { int n = v.size(); NV = 1; while (NV < n) NV *= 2; index.resize(2 * NV); rep(i, 0, n) fore(j, v[i]) index[i + NV].push_back(j); rrep(i, NV * 2 - 1, 1) { sort(index[i].begin(), index[i].end()); index[i].erase(unique(index[i].begin(), index[i].end()), index[i].end()); fore(j, index[i]) index[i / 2].push_back(j); } st.resize(2 * NV); rep(i, 1, NV * 2) st[i].init(index[i].size()); } void update(int x, int y, V v) { assert(x < NV); x += NV; while (x) { int yy = lower_bound(index[x].begin(), index[x].end(), y) - index[x].begin(); assert(yy != index[x].size()); assert(y == index[x][yy]); st[x].update(yy, v); x >>= 1; } } void add(int x, int y, V v) { assert(x < NV); x += NV; while (x) { int yy = lower_bound(index[x].begin(), index[x].end(), y) - index[x].begin(); assert(yy != index[x].size()); assert(y == index[x][yy]); st[x].add(yy, v); x >>= 1; } } V get(int sx, int tx, int sy, int ty, int k, int l, int r) { assert(k < NV * 2); assert(l < r); if (r <= sx or tx <= l) return def; if (sx <= l and r <= tx) { int syy = lower_bound(index[k].begin(), index[k].end(), sy) - index[k].begin(); int tyy = lower_bound(index[k].begin(), index[k].end(), ty) - index[k].begin(); return st[k].get(syy, tyy); } int md = (l + r) / 2; V le = get(sx, tx, sy, ty, k * 2, l, md); V ri = get(sx, tx, sy, ty, k * 2 + 1, md, r); return comp(le, ri); } V get(int sx, int tx, int sy, int ty) { return get(sx, tx, sy, ty, 1, 0, NV); } }; /*--------------------------------------------------------------------------------------------------- ∧_∧ ∧_∧ (´<_` ) Welcome to My Coding Space! ( ´_ゝ`) / ⌒i / \ | | / / ̄ ̄ ̄ ̄/ | __(__ニつ/ _/ .| .|____ \/____/ (u ⊃ ---------------------------------------------------------------------------------------------------*/ //int H, W, Q; //vector<vector<int>> query; //--------------------------------------------------------------------------------------------------- ll t[200010],x[200010],v[200010]; void _main(){ int i,n; cin >> n; for(i=0;i<n;i++) cin >> t[i] >> x[i] >> v[i]; vector<ll> a(n),b(n); for(i=0;i<n;i++){ a[i] = t[i] + x[i]; b[i] = t[i] - x[i]; } sort(a.begin(),a.end()); sort(b.begin(),b.end()); vector<pair<ll,pair<ll,ll>>> w(n); vector<vector<int>> index(n); for(i=0;i<n;i++){ w[i] = {t[i],{x[i],v[i]}}; int xx = lower_bound(a.begin(),a.end(),t[i] + x[i]) - a.begin(); int yy = lower_bound(b.begin(),b.end(),t[i] - x[i]) - b.begin(); index[xx].push_back(yy); } //index[0].push_back(0); sort(w.begin(),w.end()); Healthy2DSegTree st; st.init(index); //ll inf = 1000000000000000; //st.update(0,0,inf); for(i=0;i<n;i++){ if(w[i].first<abs(w[i].second.first)) continue; ll aa = w[i].first + w[i].second.first,bb = w[i].first - w[i].second.first; ll xx = lower_bound(a.begin(),a.end(),aa) - a.begin(); ll yy = lower_bound(b.begin(),b.end(),bb) - b.begin(); ll mx = st.get(0,xx + 1,0,yy + 1) + w[i].second.second; ll mx2 = st.get(xx,xx + 1,yy,yy + 1); if(mx2<=mx){ //cout << mx << " " << mx2 << endl; //st.add(xx,yy,-mx2); st.update(xx,yy,mx); } } cout << st.get(0,n,0,n) << endl; } /*void _main() { cin >> H >> W >> Q; rep(i, 0, Q) { int t; cin >> t; if (t == 1) { int x, y, v; cin >> x >> y >> v; query.push_back({ t, x, y, v }); } else { int sx, sy, tx, ty; cin >> sx >> sy >> tx >> ty; query.push_back({ t, sx, sy, tx, ty }); } } Healthy2DSegTree st; vector<vector<int>> index(W); rep(i, 0, Q) { if (query[i][0] == 1) { int x = query[i][1]; int y = query[i][2]; index[x].push_back(y); } } st.init(index); rep(i, 0, Q) { if (query[i][0] == 1) { int x = query[i][1]; int y = query[i][2]; int v = query[i][3]; st.add(x, y, v); } else { int sx = query[i][1]; int sy = query[i][2]; int tx = query[i][3]; int ty = query[i][4]; ll ans = st.get(sx, tx + 1, sy, ty + 1); printf("%lld\n", ans); } } }*/