結果

問題 No.1625 三角形の質問
ユーザー KudeKude
提出日時 2021-07-23 22:46:23
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 3,189 bytes
コンパイル時間 5,156 ms
コンパイル使用メモリ 288,424 KB
実行使用メモリ 10,180 KB
最終ジャッジ日時 2023-09-25 23:17:04
合計ジャッジ時間 22,256 ms
ジャッジサーバーID
(参考情報)
judge13 / judge14
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,376 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 WA -
testcase_06 WA -
testcase_07 WA -
testcase_08 WA -
testcase_09 WA -
testcase_10 WA -
testcase_11 WA -
testcase_12 WA -
testcase_13 WA -
testcase_14 WA -
testcase_15 WA -
testcase_16 AC 753 ms
4,836 KB
testcase_17 AC 99 ms
9,136 KB
testcase_18 AC 288 ms
5,516 KB
testcase_19 AC 122 ms
8,476 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#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);
    vector<char> is_ask_query(q);
    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 {
                is_ask_query[i] = true;
                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;
        mp[-1] = 3002003004005006007LL;
        mp[1001001001] = -1;
        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 (si <= it->second) continue;
                while(it != mp.begin()) {
                    it--;
                    if (it->second <= si) {
                        it = mp.erase(it);
                    } else {
                        break;
                    }
                }
                
                chmax(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) if (is_ask_query[i]) cout << ans[i] << '\n';
}
0