結果

問題 No.1625 三角形の質問
ユーザー tokusakuraitokusakurai
提出日時 2021-08-11 14:46:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2,253 ms / 6,000 ms
コード長 7,549 bytes
コンパイル時間 2,753 ms
コンパイル使用メモリ 224,780 KB
実行使用メモリ 209,076 KB
最終ジャッジ日時 2023-10-25 06:13:19
合計ジャッジ時間 36,503 ms
ジャッジサーバーID
(参考情報)
judge12 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,348 KB
testcase_01 AC 82 ms
15,124 KB
testcase_02 AC 711 ms
65,100 KB
testcase_03 AC 861 ms
93,992 KB
testcase_04 AC 521 ms
57,600 KB
testcase_05 AC 1,300 ms
119,692 KB
testcase_06 AC 2,253 ms
202,008 KB
testcase_07 AC 2,161 ms
202,484 KB
testcase_08 AC 2,156 ms
199,340 KB
testcase_09 AC 2,150 ms
204,572 KB
testcase_10 AC 2,145 ms
196,560 KB
testcase_11 AC 2,179 ms
202,708 KB
testcase_12 AC 2,186 ms
204,852 KB
testcase_13 AC 2,200 ms
201,744 KB
testcase_14 AC 2,120 ms
201,016 KB
testcase_15 AC 2,160 ms
193,028 KB
testcase_16 AC 274 ms
59,180 KB
testcase_17 AC 759 ms
181,560 KB
testcase_18 AC 88 ms
8,404 KB
testcase_19 AC 919 ms
209,076 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define each(e, v) for(auto &e: v)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) (int)x.size()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int MOD = 1000000007;
//const int MOD = 998244353;
const int inf = (1<<30)-1;
const ll INF = (1LL<<60)-1;
template<typename T> bool chmax(T &x, const T &y) {return (x < y)? (x = y, true) : false;};
template<typename T> bool chmin(T &x, const T &y) {return (x > y)? (x = y, true) : false;};

struct io_setup{
    io_setup(){
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout << fixed << setprecision(15);
    }
} io_setup;

template<typename Monoid>
struct Segment_Tree{
    using F = function<Monoid(Monoid, Monoid)>;
    int n;
    vector<Monoid> seg;
    const F f;
    const Monoid e1;
    
    Segment_Tree(const vector<Monoid> &v, const F &f, const Monoid &e1) : f(f), e1(e1){
        int m = v.size();
        n = 1;
        while(n < m) n <<= 1;
        seg.assign(2*n, e1);
        copy(begin(v), end(v), begin(seg)+n);
        for(int i = n-1; i > 0; i--) seg[i] = f(seg[2*i], seg[2*i+1]);
    }

    Segment_Tree(int m, const Monoid &x, const F &f, const Monoid &e1) : f(f), e1(e1){
        n = 1;
        while(n < m) n <<= 1;
        seg.assign(2*n, e1);
        vector<Monoid> v(m, x);
        copy(begin(v), end(v), begin(seg)+n);
        for(int i = n-1; i > 0; i--) seg[i] = f(seg[2*i], seg[2*i+1]);
    }
    
    void change(int i, const Monoid &x, bool update = true){
        if(update) seg[i+n] = x;
        else seg[i+n] = f(seg[i+n], x);
        i += n;
        while(i >>= 1){
            seg[i] = f(seg[2*i], seg[2*i+1]);
        }
    }

    Monoid query(int l, int r) const{
        Monoid L = e1, R = e1;
        l += n, r += n;
        while(l < r){
            if(l&1) L = f(L, seg[l++]);
            if(r&1) R = f(seg[--r], R);
            l >>= 1, r >>= 1;
        }
        return f(L, R);
    }
 
    Monoid operator [] (int i) const {return seg[n+i];}
 
    template<typename C>
    int find_subtree(int i, const C &check, const Monoid &x, Monoid &M, bool type) const{
        while(i < n){
            Monoid nxt = type? f(seg[2*i+type], M) : f(M, seg[2*i+type]);
            if(check(nxt, x)) i = 2*i+type;
            else M = nxt, i = 2*i+(type^1);
        }
        return i-n;
    }
 
    template<typename C>
    int find_first(int l, const C &check, const Monoid &x) const{
        Monoid L = e1;
        int a = l+n, b = n+n;
        while(a < b){
            if(a&1){
                Monoid nxt = f(L, seg[a]);
                if(check(nxt, x)) return find_subtree(a, check, x, L, false);
                L = nxt, a++;
            }
            a >>= 1, b >>= 1;
        }
        return n;
    }
 
    template<typename C>
    int find_last(int r, const C &check, const Monoid &x) const{
        Monoid R = e1;
        int a = n, b = r+n;
        while(a < b){
            if(b&1 || a == 1){
                Monoid nxt = f(seg[--b], R);
                if(check(nxt, x)) return find_subtree(b, check, x, R, true);
                R = nxt;
            }
            a >>= 1, b >>= 1;
        }
        return -1;
    }
};

template<typename T>
struct Segment_Tree_2D{
    using F = function<T(T, T)>;
    int n;
    vector<vector<int>> ids;
    vector<Segment_Tree<T>> segs;
    const F f;
    const T e;
    
    Segment_Tree_2D(int m, const F &f, const T &e) : f(f), e(e){
        n = 1;
        while(n < m) n <<= 1;
        ids.resize(2*n);
    }

    void insert(int x, int y){
        x += n;
        while(x){
            ids[x].push_back(y);
            x >>= 1;
        }
    }

    void build(){
        for(int i = 0; i < 2*n; i++){
            sort(begin(ids[i]), end(ids[i]));
            ids[i].erase(unique(begin(ids[i]), end(ids[i])), end(ids[i]));
            segs.emplace_back((int)ids[i].size(), e, f, e);
        }
    }

    void change(int x, int y, const T &a, bool update = true){
        x += n;
        while(x){
            segs[x].change(lower_bound(begin(ids[x]), end(ids[x]), y)-begin(ids[x]), a, update);
            x >>= 1;
        }
    }

    T query(int lx, int rx, int ly, int ry) const{
        T L = e, R = e;
        lx += n, rx += n;
        while(lx < rx){
            if(lx&1){
                int l = lower_bound(begin(ids[lx]), end(ids[lx]), ly)-begin(ids[lx]);
                int r = lower_bound(begin(ids[lx]), end(ids[lx]), ry)-begin(ids[lx]);
                L = f(L, segs[lx].query(l, r));
                lx++;
            }
            if(rx&1){
                rx--;
                int l = lower_bound(begin(ids[rx]), end(ids[rx]), ly)-begin(ids[rx]);
                int r = lower_bound(begin(ids[rx]), end(ids[rx]), ry)-begin(ids[rx]);
                R = f(segs[rx].query(l, r), R);
            }
            lx >>= 1, rx >>= 1;
        }
        return f(L, R);
    }
};

template<typename T>
void print(const vector<T> &v, T x = 0){
    int n = v.size();
    for(int i = 0; i < n; i++) cout << v[i]+x << (i == n-1? '\n' : ' ');
}

template<typename T>
void printn(const vector<T> &v, T x = 0){
    int n = v.size();
    for(int i = 0; i < n; i++) cout << v[i]+x << '\n';
}

template<typename T>
void unique(vector<T> &v){
    sort(begin(v), end(v));
    v.erase(unique(begin(v), end(v)), end(v));
}

template<typename T>
vector<int> iota(const vector<T>&v, bool greater = false){
    int n = v.size();
    vector<int> ret(n);
    iota(begin(ret), end(ret), 0);
    sort(begin(ret), end(ret), [&](int i, int j){
        return greater? v[i] > v[j] : v[i] < v[j];
    });
    return ret;
}

int main(){
    int N, Q; cin >> N >> Q;

    vector<int> l1(N), r1(N), t(Q), l2(Q), r2(Q);
    vector<ll> s1(N), s2(Q);
    vector<int> ls, rs;

    rep(i, N){
        vector<ll> x(3), y(3);
        rep(j, 3) cin >> x[j] >> y[j];

        l1[i] = *min_element(all(x)), r1[i] = *max_element(all(x));
        ls.eb(l1[i]), rs.eb(r1[i]);

        s1[i] = abs((x[1]-x[0])*(y[2]-y[0])-(x[2]-x[0])*(y[1]-y[0]));
    }

    rep(i, Q){
        cin >> t[i];

        if(t[i] == 1){
            vector<ll> x(3), y(3);
            rep(j, 3) cin >> x[j] >> y[j];

            l2[i] = *min_element(all(x)), r2[i] = *max_element(all(x));
            ls.eb(l2[i]), rs.eb(r2[i]);

            s2[i] = abs((x[1]-x[0])*(y[2]-y[0])-(x[2]-x[0])*(y[1]-y[0]));
        }
        else{
            cin >> l2[i] >> r2[i];
            r2[i]++;
        }
    }

    unique(ls), unique(rs);

    int K = sz(ls);
    auto f = [](ll a, ll b) {return max(a, b);};
    Segment_Tree_2D<ll> seg(K, f, -1);

    rep(i, N){
        l1[i] = lower_bound(all(ls), l1[i])-begin(ls);
        r1[i] = lower_bound(all(rs), r1[i])-begin(rs);
        seg.insert(l1[i], r1[i]);
    }
    rep(i, Q){
        l2[i] = lower_bound(all(ls), l2[i])-begin(ls);
        r2[i] = lower_bound(all(rs), r2[i])-begin(rs);

        if(t[i] == 1){
            seg.insert(l2[i], r2[i]);
        }
    }

    seg.build();
    rep(i, N){
        seg.change(l1[i], r1[i], s1[i], false);
    }

    rep(i, Q){
        if(t[i] == 1){
            seg.change(l2[i], r2[i], s2[i], false);
        }
        else{
            cout << seg.query(l2[i], K, 0, r2[i]) << '\n';
        }
    }
}
0