結果
| 問題 |
No.1625 三角形の質問
|
| コンテスト | |
| ユーザー |
Kude
|
| 提出日時 | 2021-07-23 22:34:11 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
| 結果 |
WA
|
| 実行時間 | - |
| コード長 | 3,079 bytes |
| コンパイル時間 | 4,518 ms |
| コンパイル使用メモリ | 275,920 KB |
| 最終ジャッジ日時 | 2025-01-23 08:19:14 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge3 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | WA * 1 |
| other | AC * 2 WA * 17 |
ソースコード
#include<bits/stdc++.h>
#include<atcoder/all>
using namespace std;
using namespace atcoder;
#define rep(i,n)for (int i = 0; i < int(n); ++i)
#define rrep(i,n)for (int i = int(n)-1; i >= 0; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
template<class T> void chmax(T& a, const T& b) {a = max(a, b);}
template<class T> void chmin(T& a, const T& b) {a = min(a, b);}
using ll = long long;
using P = pair<int,int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
constexpr int SQ = 500;
using TR = tuple<int, int, ll>;
TR get_triangle() {
int a, b, c, d, e, f;
cin >> a >> b >> c >> d >> e >> f;
int l = min({a, c, e});
int r = max({a, c, e}) + 1;
ll dx1 = c - a, dy1 = d - b;
ll dx2 = e - a, dy2 = f - b;
ll s = abs(dx1 * dy2 - dx2 * dy1);
return {l, r, s};
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int n, q;
cin >> n >> q;
vector<TR> triangles;
rep(_, n) {
auto t = get_triangle();
triangles.push_back(t);
}
auto mycmp = [&](const TR& x, const TR& y) {
return get<1>(x) < get<1>(y);
};
sort(all(triangles), mycmp);
VL ans(q, -1);
for(int b = 0; b < q; b += SQ) {
int nb = min(b + SQ, q);
vector<TR> new_triangles;
vector<tuple<int, int, int>> ask_queries;
for(int i = b; i < nb; i++) {
int type;
cin >> type;
if (type == 1) {
auto t = get_triangle();
new_triangles.push_back(t);
} else {
int l, r;
cin >> l >> r;
r++;
ask_queries.emplace_back(i, l, r);
for(auto [li, ri, si]: new_triangles) if (li <= l && r <= ri) {
chmax(ans[i], si);
}
}
}
sort(all(ask_queries), [&](auto& x, auto& y) {return get<2>(x) < get<2>(y);});
auto nxt = triangles.begin();
map<int, ll> mp;
for(auto [i, l, r]: ask_queries) {
while(nxt != triangles.end() && get<1>(*nxt) <= r) {
auto [li, ri, si] = *nxt;
nxt++;
auto it = mp.upper_bound(li);
if (it != mp.end()) {
if (si <= it->second) continue;
}
while(it != mp.begin()) {
it--;
if (it->second <= si) {
it = mp.erase(it);
} else {
break;
}
}
mp[li] = si;
}
auto it = mp.lower_bound(l);
if (it != mp.end()) chmax(ans[i], it->second);
}
sort(all(new_triangles), mycmp);
int old_sz = triangles.size();
for(auto t: new_triangles) triangles.push_back(t);
inplace_merge(triangles.begin(), triangles.begin() + old_sz, triangles.end(), mycmp);
}
rep(i, q) cout << ans[i] << '\n';
}
Kude