結果

問題 No.1074 増殖
ユーザー carrot46carrot46
提出日時 2020-06-05 22:59:15
言語 C++14
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 126 ms / 2,000 ms
コード長 1,676 bytes
コンパイル時間 2,172 ms
コンパイル使用メモリ 179,292 KB
実行使用メモリ 6,372 KB
最終ジャッジ日時 2023-08-22 17:00:56
合計ジャッジ時間 3,708 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ(β)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 1 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 103 ms
6,220 KB
testcase_07 AC 102 ms
6,372 KB
testcase_08 AC 99 ms
6,204 KB
testcase_09 AC 113 ms
6,272 KB
testcase_10 AC 102 ms
6,268 KB
testcase_11 AC 101 ms
6,248 KB
testcase_12 AC 101 ms
6,328 KB
testcase_13 AC 126 ms
6,308 KB
testcase_14 AC 125 ms
6,072 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
#define ALL(a) a.begin(), a.end()
#define fi first
#define se second
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;

ll N,M,H,W,Q,K,A,B;
string S;
const ll MOD = 998244353;
//const ll MOD = (1e+9) + 7;
typedef pair<ll, ll> P;
const ll INF = (1LL<<62);

void solve(vec &res, vec x, vec y){
    const int max_x = 20005;
    set<P> pts;
    pts.emplace(0, N);
    pts.emplace(max_x, N + 1);
    x.push_back(0);
    x.push_back(max_x);
    y.push_back(max_x);
    y.push_back(0);
    rep(i,N){
        auto ite = pts.lower_bound(P(x[i] + 1, -1));
        if(y[ite->se] >= y[i]) continue;
        bool flag = false, one = true;
        while(y[ite->se] <= y[i]){
            ll last_id = ite->se;
            --ite;
            if(x[ite->se] == x[i] && y[ite->se] >= y[i]) {
                flag = true;
                break;
            }
            res[i] += (min(x[i], x[last_id]) - x[ite->se]) * (y[i] - y[last_id]);
            one ? one = false : pts.erase(P(x[last_id], last_id));
        }
        if(!flag) pts.emplace(x[i], i);
    }
}

int main() {
    cin>>N;
    mat x(2, vec(N)), y(2, vec(N));
    vec res(N, 0);
    rep(i,N){
        rep(j,2) cin>>x[j][i]>>y[j][i];
        x[0][i] *= -1;
        y[0][i] *= -1;
    }
    rep(i,2) rep(j,2) {
        solve(res, x[i], y[j]);
/*
            rep(k,N){
                cout<<res[k]<<' ';
            }
            cout<<endl;
*/
    }
    rep(i,N) cout<<res[i]<<endl;
}
0