結果

問題 No.814 ジジ抜き
ユーザー beetbeet
提出日時 2019-04-12 22:40:42
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
RE  
実行時間 -
コード長 2,671 bytes
コンパイル時間 2,754 ms
コンパイル使用メモリ 217,252 KB
実行使用メモリ 55,740 KB
最終ジャッジ日時 2023-10-12 22:19:13
合計ジャッジ時間 39,714 ms
ジャッジサーバーID
(参考情報)
judge13 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,352 KB
testcase_01 AC 1 ms
4,348 KB
testcase_02 AC 1 ms
4,352 KB
testcase_03 RE -
testcase_04 RE -
testcase_05 RE -
testcase_06 RE -
testcase_07 RE -
testcase_08 RE -
testcase_09 RE -
testcase_10 RE -
testcase_11 RE -
testcase_12 RE -
testcase_13 RE -
testcase_14 RE -
testcase_15 RE -
testcase_16 RE -
testcase_17 RE -
testcase_18 RE -
testcase_19 TLE -
testcase_20 RE -
testcase_21 RE -
testcase_22 RE -
testcase_23 RE -
testcase_24 RE -
testcase_25 RE -
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;

struct DS{
  using P = pair<Int, Int>;
  set<P> sp;
  // [l, r)
  void add(Int l,Int r){
    assert(l!=r);
    if(sp.empty()){
      sp.emplace(l,r);
      return;
    }
    while(1){
      auto it=sp.upper_bound(P(l,l));
      if(it==sp.begin()) break;        
      it--;        
      Int pl,pr;
      tie(pl,pr)=*it;
      assert(pl<l);
        
      if(pr<=l) break;
      if(r<=pr){
        sp.erase(P(pl,pr));
        if(pl!=l) sp.emplace(pl,l);
        if(r!=pr) sp.emplace(r,pr);
        return;
      }
        
      if(pl!=l) sp.emplace(pl,l);
      l=pr;
      break;
    }
      
    while(l<r){
      auto it=sp.upper_bound(P(l,l));
      if(it==sp.end()) break;
      Int nl,nr;
      tie(nl,nr)=*it;
      assert(l<=nl);
      if(r<=nl){
        if(l!=r) sp.emplace(l,r);
        break;
      }
      if(r<=nr){
        sp.erase(P(nl,nr));
        if(l!=nl) sp.emplace(l,nl);
        if(r!=nr) sp.emplace(r,nr);
        return;
      }
        
      assert(nr<r);
      sp.erase(P(nl,nr));
      if(l!=nl) sp.emplace(l,nl);
      l=nr;
    }
  }
};

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  vector<Int> a(n),b(n),c(n);
  for(Int i=0;i<n;i++) cin>>a[i]>>b[i]>>c[i];


  vector<Int> l(n),r(n),v(n),w(n);
  for(Int i=0;i<n;i++){
    w[i]=1LL<<c[i];
    v[i]=b[i]%w[i];
    l[i]=b[i]/w[i];
    r[i]=l[i]+a[i];
    // cout<<v[i]<<" "<<w[i]<<" "<<l[i]<<" "<<r[i]<<endl;
  }


  map<Int, DS> dp;
  for(Int t=0;t<60;t++){
    for(Int i=0;i<n;i++){
      if(c[i]!=t) continue;
      dp[v[i]].add(l[i],r[i]);
    }    
    map<Int, DS> nx;
    for(auto &st:dp){
      Int x=st.first;
      for(auto p:st.second.sp){
        // cout<<t<<" "<<x<<":"<<p.first<<" "<<p.second<<endl;
        Int n0=x;
        Int n1=x|(1LL<<t);

        Int l0=(p.first+1)>>1;
        Int l1=l0-(p.first&1);
        
        Int r0=(p.second+1)>>1;
        Int r1=r0-(p.second&1);

        //cout<<p.first<<" "<<p.second;
        //cout<<":"<<l0<<" "<<r0<<":"<<l1<<" "<<r1<<endl;
        if(l0!=r0) nx[n0].add(l0,r0);
        if(l1!=r1) nx[n1].add(l1,r1);        
      }
    }
    swap(dp,nx);
  }

  Int cnt=0;
  for(auto &p:dp){
    if(p.second.sp.empty()) continue;
    auto it=p.second.sp.begin();
    assert((it->first)+1==(it->second));
    Int x=p.first+(1LL<<60)*(it->first);
    cout<<x<<endl;
    cnt++;
  }
  assert(cnt==1);
  return 0;
}
0