結果

問題 No.1074 増殖
コンテスト
ユーザー Chanyuh
提出日時 2020-06-06 17:19:30
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 263 ms / 2,000 ms
コード長 4,746 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 1,583 ms
コンパイル使用メモリ 150,868 KB
実行使用メモリ 9,088 KB
最終ジャッジ日時 2026-05-29 13:23:11
合計ジャッジ時間 4,317 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 12
権限があれば一括ダウンロードができます
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/functional:61,
                 from main.cpp:7:
In copy constructor 'std::function<_Res(_ArgTypes ...)>::function(const std::function<_Res(_ArgTypes ...)>&) [with _Res = std::pair<long long int, long long int>; _ArgTypes = {std::pair<long long int, long long int>, std::pair<long long int, long long int>}]',
    inlined from 'SegmentTree<T, E>::SegmentTree(F, G, H, T, E) [with T = std::pair<long long int, long long int>; E = long long int]' at main.cpp:59:5,
    inlined from 'void solve(std::vector<long long int>&, std::vector<long long int>&, std::vector<long long int>&)' at main.cpp:158:48:
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/std_function.h:393:17: warning: '<anonymous>' may be used uninitialized [-Wmaybe-uninitialized]
  393 |             __x._M_manager(_M_functor, __x._M_functor, __clone_functor);
      |             ~~~~^~~~~~~~~~
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/std_function.h: In function 'void solve(std::vector<long long int>&, std::vector<long long int>&, std::vector<long long int>&)':
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/std_function.h:269:7: note: by argument 2 of type 'const std::_Any_data&' to 'static bool std::_Function_handler<_Res(_ArgTypes ...), _Functor>::_M_manager(std::_Any_data&, const std::_Any_data&, std::_Manager_operation) [with _Res = std::pair<long long int, long long int>; _Functor = solve(std::vector<long long int>&, std::vector<long long int>&, std::vector<long long int>&)::<lambda(LP, LP)>; _ArgTypes = {std::pair<long long int, long long int>, std::pair<long long int, long long int>}]' declared here
  269 |       _M_manager(_Any_data& __dest, const _Any_data& __source,
      |       ^~~~~~~~~~
main.cpp:158:29: note: '<anonymous>' declared here
  158 |     SegmentTree<LP,ll> seg1(f1,g1,h1,LP(0,0),-1);
      |                             ^~
In copy constructor '

ソースコード

diff #
raw source code

#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
int dx[4]={1,-1,0,0};
int dy[4]={0,0,1,-1};

int n,M=20010;
vector<ll> xa,xb,ya,yb;
vector<ll> ans1,ans2,ans3,ans4;

template <typename T,typename E>
struct SegmentTree{
  using F = function<T(T,T)>;
  using G = function<T(T,E)>;
  using H = function<E(E,E)>;
  int n,height;
  F f;
  G g;
  H h;
  T ti;
  E ei;
  vector<T> dat;
  vector<E> laz;
  SegmentTree(F f,G g,H h,T ti,E ei):
    f(f),g(g),h(h),ti(ti),ei(ei){}

  void init(int n_){
    n=1;height=0;
    while(n<n_) n<<=1,height++;
    dat.assign(2*n,ti);
    laz.assign(2*n,ei);
  }

  void build(const vector<T> &v){
    int n_=v.size();
    init(n_);
    for(int i=0;i<n_;i++) dat[n+i]=v[i];
    for(int i=n-1;i;i--)
      dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);
  }

  inline T reflect(int k){
    return laz[k]==ei?dat[k]:g(dat[k],laz[k]);
  }

  inline void propagate(int k){
    if(laz[k]==ei) return;
    laz[(k<<1)|0]=h(laz[(k<<1)|0],laz[k]);
    laz[(k<<1)|1]=h(laz[(k<<1)|1],laz[k]);
    dat[k]=reflect(k);
    laz[k]=ei;
  }

  inline void thrust(int k){
    for(int i=height;i;i--) propagate(k>>i);
  }

  inline void recalc(int k){
    while(k>>=1)
      dat[k]=f(reflect((k<<1)|0),reflect((k<<1)|1));
  }

  void update(int a,int b,E x){
    if(a>=b) return;
    thrust(a+=n);
    thrust(b+=n-1);
    for(int l=a,r=b+1;l<r;l>>=1,r>>=1){
      if(l&1) laz[l]=h(laz[l],x),l++;
      if(r&1) --r,laz[r]=h(laz[r],x);
    }
    recalc(a);
    recalc(b);
  }

  void set_val(int a,T x){
    thrust(a+=n);
    dat[a]=x;laz[a]=ei;
    recalc(a);
  }

  T query(int a,int b){
    if(a>=b) return ti;
    thrust(a+=n);
    thrust(b+=n-1);
    T vl=ti,vr=ti;
    for(int l=a,r=b+1;l<r;l>>=1,r>>=1) {
      if(l&1) vl=f(vl,reflect(l++));
      if(r&1) vr=f(reflect(--r),vr);
    }
    return f(vl,vr);
  }

  template<typename C>
  int find(int st,C &check,T &acc,int k,int l,int r){
    if(l+1==r){
      acc=f(acc,reflect(k));
      return check(acc)?k-n:-1;
    }
    propagate(k);
    int m=(l+r)>>1;
    if(m<=st) return find(st,check,acc,(k<<1)|1,m,r);
    if(st<=l&&!check(f(acc,dat[k]))){
      acc=f(acc,dat[k]);
      return -1;
    }
    int vl=find(st,check,acc,(k<<1)|0,l,m);
    if(~vl) return vl;
    return find(st,check,acc,(k<<1)|1,m,r);
  }

  template<typename C>
  int find(int st,C &check){
    T acc=ti;
    return find(st,check,acc,1,0,n);
  }
};

void solve(vector<ll> &x,vector<ll> &y,vector<ll> &ans){
    auto f1=[](LP a,LP b) {return LP(a.first+b.first,a.second+b.second);};
    auto f2=[](ll a,ll b) {return max(a,b);};
    auto g1=[](LP a,ll b) {return LP(b*a.second,a.second);};
    auto h1=[](ll a,ll b) {a+=1;return b;};
    auto g2=[](ll a,ll b) {if(b==-1) return a;return b;};
    SegmentTree<LP,ll> seg1(f1,g1,h1,LP(0,0),-1);
    SegmentTree<ll,ll> seg2(f2,g2,g2,0,-1);
    vector<LP> v1(M+1,LP(0,1));v1[M]=LP(INF,1);
    vector<ll> v2(M+1);v2[M]=INF;
    seg1.build(v1);seg2.build(v2);
    rep(i,n){
        auto check=[&](ll p) {return p>y[i];};
        int nx=seg2.find(M-x[i],check);
        //cout << M-x[i] << " " << nx << endl;
        seg1.update(M-x[i],nx,y[i]);
        seg2.update(M-x[i],nx,y[i]);
        ans[i]=seg1.query(0,M).first;
        //cout << ans[i] << endl;
    }
}

int main(){
    cin >> n;
    xa.resize(n);
    xb.resize(n);
    ya.resize(n);
    yb.resize(n);
    ans1.resize(n);
    ans2.resize(n);
    ans3.resize(n);
    ans4.resize(n);
    rep(i,n){
        cin >> xa[i] >> ya[i] >> xb[i] >> yb[i];
        xa[i]*=-1;
        ya[i]*=-1;
    }
    solve(xa,ya,ans1);
    solve(xa,yb,ans2);
    solve(xb,ya,ans3);
    solve(xb,yb,ans4);
    vector<ll> S={0};
    rep(i,n){
        cout << ans1[i]+ans2[i]+ans3[i]+ans4[i]-S.back() << endl;
        S.push_back(ans1[i]+ans2[i]+ans3[i]+ans4[i]);
    }
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    
}
0