結果

問題 No.674 n連勤
ユーザー 夕叢霧香(ゆうむらきりか)夕叢霧香(ゆうむらきりか)
提出日時 2018-04-13 23:25:55
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 151 ms / 2,000 ms
コード長 2,370 bytes
コンパイル時間 1,153 ms
コンパイル使用メモリ 98,428 KB
実行使用メモリ 8,564 KB
最終ジャッジ日時 2023-09-09 04:48:37
合計ジャッジ時間 3,290 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,380 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 2 ms
4,380 KB
testcase_04 AC 1 ms
4,380 KB
testcase_05 AC 2 ms
4,376 KB
testcase_06 AC 2 ms
4,380 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 2 ms
4,380 KB
testcase_09 AC 1 ms
4,384 KB
testcase_10 AC 1 ms
4,380 KB
testcase_11 AC 11 ms
4,376 KB
testcase_12 AC 13 ms
4,380 KB
testcase_13 AC 124 ms
4,380 KB
testcase_14 AC 142 ms
8,460 KB
testcase_15 AC 123 ms
7,688 KB
testcase_16 AC 151 ms
8,564 KB
testcase_17 AC 151 ms
8,472 KB
testcase_18 AC 138 ms
7,360 KB
testcase_19 AC 132 ms
8,068 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include<algorithm>
#include<iostream>
#include<vector>
#include<map>
using namespace std;
typedef long long lint;
typedef vector<int>vi;
typedef pair<int,int>pii;
#define rep(i,n)for(int i=0;i<(int)(n);++i)

const int W=300;
const int N=W*W;
vector<lint> coord;
map<lint,int> tbl;

lint u[N];

struct iroha{
  lint s,e,m;
  iroha():s(0),e(0),m(0){}
  iroha(lint s,lint e,lint m):s(s),e(e),m(m){}
  iroha operator*(const iroha &o){
    if(m==-1&&o.m==-1){
      return iroha(s+o.s,e+o.e,-1);
    }
    if(m==-1){
      return iroha(s+o.s,o.e,max(o.m,m+o.s));
    }
    if(o.m==-1){
      return iroha(s,e+o.s,max(m,e+o.s));
    }
    return iroha(s,o.e,max(m,max(o.m,e+o.s)));
  }
};

iroha meg[W];
int pop[W];

void tap(int b){
  iroha acc(0,0,-1);
  rep(i,W){
    if(u[b*W+i]){
      lint dif=coord[b*W+i+1]-coord[b*W+i];
      acc=acc*iroha(dif,dif,-1);
    }else{
      acc=acc*iroha(0,0,0);
    }
  }
  meg[b]=acc;
}

void update_range(int l,int r){
  int b=l/W;
  if(pop[b]==W)return;
  for(int i=l;i<r;++i){
    pop[b]+=1-u[i];
    u[i]=1;
  }
  tap(b);
}

void update(int l,int r){
  int lb=(l+W-1)/W;
  int rb=r/W;
  if(lb>rb){
    update_range(l,r);
  }else{
    update_range(l,lb*W);
    update_range(rb*W,r);
    for(int i=lb;i<rb;++i){
      lint dif=coord[i*W+W]-coord[i*W];
      meg[i]=iroha(dif,dif,-1);
      pop[i]=W;
    }
  }
}

iroha query_range(int l,int r){
  iroha acc(0,0,0);
  for(int i=l;i<r;++i){
    lint dif=u[i]?coord[i+1]-coord[i]:0;
    acc=acc*(u[i]?iroha(dif,dif,-1):iroha(0,0,0));
  }
  return acc;
}


lint query(int l,int r){
  int lb=(l+W-1)/W;
  int rb=r/W;
  iroha res;
  if(lb>rb){
    res=query_range(l,r);
  }else{
    res=query_range(l,lb*W);
    for(int i=lb;i<rb;++i){
      res=res*meg[i];
    }
    res=res*query_range(rb*W,r);
  }
  return res.m;
}

int main(){
  lint d;
  int q;
  cin>>d>>q;
  vector<lint> a(q),b(q);
  rep(i,q){
    cin>>a[i]>>b[i];
    b[i]++;
    coord.push_back(a[i]);
    coord.push_back(b[i]);
  }
  coord.push_back(0);
  coord.push_back(d);
  sort(coord.begin(),coord.end());
  coord.erase(unique(coord.begin(),coord.end()),coord.end());
  rep(i,coord.size())tbl[coord[i]]=i;
  vi ca(q),cb(q);
  rep(i,q){
    ca[i]=tbl[a[i]];
    cb[i]=tbl[b[i]];
  }
  rep(i,q){
    update(ca[i],cb[i]);
    cout<<query(0,N)<<endl;
    if(0){
      rep(j,20)cerr<<" "<<u[j];
      cerr<<endl;
    }
  }
  
}
0