結果
問題 | No.1625 三角形の質問 |
ユーザー | SSRS |
提出日時 | 2021-07-23 21:58:31 |
言語 | C++14 (gcc 12.3.0 + boost 1.83.0) |
結果 |
AC
|
実行時間 | 2,361 ms / 6,000 ms |
コード長 | 4,472 bytes |
コンパイル時間 | 2,266 ms |
コンパイル使用メモリ | 186,016 KB |
実行使用メモリ | 172,476 KB |
最終ジャッジ日時 | 2024-07-18 17:41:00 |
合計ジャッジ時間 | 34,783 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge4 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 2 ms
5,248 KB |
testcase_01 | AC | 108 ms
14,592 KB |
testcase_02 | AC | 792 ms
55,224 KB |
testcase_03 | AC | 896 ms
86,884 KB |
testcase_04 | AC | 597 ms
50,412 KB |
testcase_05 | AC | 1,382 ms
99,832 KB |
testcase_06 | AC | 2,269 ms
171,572 KB |
testcase_07 | AC | 2,298 ms
171,460 KB |
testcase_08 | AC | 2,344 ms
172,476 KB |
testcase_09 | AC | 2,340 ms
171,832 KB |
testcase_10 | AC | 2,287 ms
171,952 KB |
testcase_11 | AC | 2,347 ms
171,348 KB |
testcase_12 | AC | 2,326 ms
172,228 KB |
testcase_13 | AC | 2,361 ms
171,176 KB |
testcase_14 | AC | 2,338 ms
172,252 KB |
testcase_15 | AC | 2,349 ms
171,200 KB |
testcase_16 | AC | 495 ms
41,636 KB |
testcase_17 | AC | 748 ms
117,204 KB |
testcase_18 | AC | 358 ms
12,736 KB |
testcase_19 | AC | 923 ms
133,572 KB |
ソースコード
#include <bits/stdc++.h> using namespace std; struct segment_tree{ int N; vector<long long> ST; segment_tree(){ } segment_tree(int N2){ N = 1; while (N < N2){ N *= 2; } ST = vector<long long>(N * 2 - 1, -1); } void update(int i, long long x){ i += N - 1; ST[i] = max(ST[i], x); while (i > 0){ i = (i - 1) / 2; ST[i] = max(ST[i], x); } } long long range_max(int L, int R, int i, int l, int r){ if (r <= L || R <= l){ return -1; } else if (L <= l && r <= R){ return ST[i]; } else { int m = (l + r) / 2; return max(range_max(L, R, i * 2 + 1, l, m), range_max(L, R, i * 2 + 2, m, r)); } } long long range_max(int L, int R){ return range_max(L, R, 0, 0, N); } }; struct segment_tree_2d{ int N; vector<vector<int>> pos; vector<segment_tree> ST; segment_tree_2d(int N2){ N = 1; while (N < N2){ N *= 2; } pos = vector<vector<int>>(N * 2 - 1); ST = vector<segment_tree>(N * 2 - 1); } void insert(int X, int Y){ X += N - 1; pos[X].push_back(Y); while (X > 0){ X = (X - 1) / 2; pos[X].push_back(Y); } } void build(){ for (int i = 0; i < N * 2 - 1; i++){ sort(pos[i].begin(), pos[i].end()); pos[i].erase(unique(pos[i].begin(), pos[i].end()), pos[i].end()); int cnt = pos[i].size(); ST[i] = segment_tree(cnt); } } void update(int X, int Y, long long x){ X += N - 1; ST[X].update(lower_bound(pos[X].begin(), pos[X].end(), Y) - pos[X].begin(), x); while (X > 0){ X = (X - 1) / 2; ST[X].update(lower_bound(pos[X].begin(), pos[X].end(), Y) - pos[X].begin(), x); } } long long rectangle_max(int L, int R, int U, int D, int i, int l, int r){ if (r <= L || R <= l){ return -1; } else if (L <= l && r <= R){ int U2 = lower_bound(pos[i].begin(), pos[i].end(), U) - pos[i].begin(); int D2 = lower_bound(pos[i].begin(), pos[i].end(), D) - pos[i].begin(); return ST[i].range_max(U2, D2); } else { int m = (l + r) / 2; return max(rectangle_max(L, R, U, D, i * 2 + 1, l, m), rectangle_max(L, R, U, D, i * 2 + 2, m, r)); } } long long rectangle_max(int L, int R, int U, int D){ return rectangle_max(L, R, U, D, 0, 0, N); } }; int main(){ int n, q; cin >> n >> q; vector<int> a(n), b(n), c(n), d(n), e(n), f(n); for (int i = 0; i < n; i++){ cin >> a[i] >> b[i] >> c[i] >> d[i] >> e[i] >> f[i]; } vector<int> t(q); vector<int> a2(q), b2(q), c2(q), d2(q), e2(q), f2(q); vector<int> l(q), r(q); for (int i = 0; i < q; i++){ cin >> t[i]; if (t[i] == 1){ cin >> a2[i] >> b2[i] >> c2[i] >> d2[i] >> e2[i] >> f2[i]; } if (t[i] == 2){ cin >> l[i] >> r[i]; } } vector<int> x; for (int i = 0; i < n; i++){ x.push_back(min({a[i], c[i], e[i]})); x.push_back(max({a[i], c[i], e[i]})); } for (int i = 0; i < q; i++){ if (t[i] == 1){ x.push_back(min({a2[i], c2[i], e2[i]})); x.push_back(max({a2[i], c2[i], e2[i]})); } } sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end()); int cnt = x.size(); vector<int> X(n), Y(n); for (int i = 0; i < n; i++){ X[i] = lower_bound(x.begin(), x.end(), min({a[i], c[i], e[i]})) - x.begin(); Y[i] = lower_bound(x.begin(), x.end(), max({a[i], c[i], e[i]})) - x.begin(); } vector<int> X2(q), Y2(q); for (int i = 0; i < q; i++){ if (t[i] == 1){ X2[i] = lower_bound(x.begin(), x.end(), min({a2[i], c2[i], e2[i]})) - x.begin(); Y2[i] = lower_bound(x.begin(), x.end(), max({a2[i], c2[i], e2[i]})) - x.begin(); } } segment_tree_2d ST(cnt); for (int i = 0; i < n; i++){ ST.insert(X[i], Y[i]); } for (int i = 0; i < q; i++){ if (t[i] == 1){ ST.insert(X2[i], Y2[i]); } } ST.build(); for (int i = 0; i < n; i++){ long long S = abs((long long) (c[i] - a[i]) * (f[i] - b[i]) - (long long) (e[i] - a[i]) * (d[i] - b[i])); ST.update(X[i], Y[i], S); } for (int i = 0; i < q; i++){ if (t[i] == 1){ long long S = abs((long long) (c2[i] - a2[i]) * (f2[i] - b2[i]) - (long long) (e2[i] - a2[i]) * (d2[i] - b2[i])); ST.update(X2[i], Y2[i], S); } if (t[i] == 2){ int l2 = lower_bound(x.begin(), x.end(), l[i]) - x.begin(); int r2 = upper_bound(x.begin(), x.end(), r[i]) - x.begin(); cout << ST.rectangle_max(l2, cnt, 0, r2) << endl; } } }