結果

問題 No.1074 増殖
ユーザー mugen_1337mugen_1337
提出日時 2020-06-06 00:17:31
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 94 ms / 2,000 ms
コード長 1,670 bytes
コンパイル時間 2,276 ms
コンパイル使用メモリ 206,224 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-08-22 19:16:49
合計ジャッジ時間 4,094 ms
ジャッジサーバーID
(参考情報)
judge13 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 2 ms
4,376 KB
testcase_03 AC 1 ms
4,376 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 70 ms
4,376 KB
testcase_07 AC 75 ms
4,380 KB
testcase_08 AC 74 ms
4,380 KB
testcase_09 AC 83 ms
4,380 KB
testcase_10 AC 69 ms
4,376 KB
testcase_11 AC 70 ms
4,380 KB
testcase_12 AC 71 ms
4,376 KB
testcase_13 AC 94 ms
4,380 KB
testcase_14 AC 94 ms
4,380 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define INF 1000000000
#define mod 1000000007
using ll=long long;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}

struct RectangleUnion{
    map<long long,long long> data;
    ll sum;
    RectangleUnion():sum(0){
        data[0]=1ll<<60;// banpei
        data[1ll<<60]=0;
    }
    // x>=0 and y>=0
    void add_point(long long x,long long y){
        auto ite=data.lower_bound(x);
        if(ite->second>=y) return ;
        long long yn=ite->second;
        ite--;
        while(ite->second<=y){
            auto k=*ite;
            // 削除した場所の次のiteratorを返す
            ite=--data.erase(ite);
            sum-=(k.first-ite->first)*(k.second-yn);
        }
        sum+=(x-ite->first)*(y-yn);
        data[x]=y;
    }
    ll get_sum(){
        return sum;
    }
};

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    
    int n;cin>>n;

    RectangleUnion ur,ul,dr,dl;
    ll pre=0;
    rep(i,n){
        ll xp,yp,xm,ym;cin>>xm>>ym>>xp>>yp;
        ur.add_point(xp,yp);
        ul.add_point(-xm,yp);
        dr.add_point(xp,-ym);
        dl.add_point(-xm,-ym);
        ll sum=ur.get_sum()+ul.get_sum()+dr.get_sum()+dl.get_sum();
        cout<<sum-pre<<endl;
        pre=sum;
    }
    return 0;
}
0