結果

問題 No.709 優勝可能性
ユーザー beetbeet
提出日時 2018-11-06 18:52:53
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 607 ms / 3,500 ms
コード長 1,893 bytes
コンパイル時間 2,540 ms
コンパイル使用メモリ 215,820 KB
実行使用メモリ 122,216 KB
最終ジャッジ日時 2024-04-30 22:18:30
合計ジャッジ時間 8,361 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 1 ms
6,940 KB
testcase_02 AC 2 ms
6,944 KB
testcase_03 AC 2 ms
6,944 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,940 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 1 ms
6,940 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,940 KB
testcase_10 AC 255 ms
33,364 KB
testcase_11 AC 164 ms
11,212 KB
testcase_12 AC 462 ms
63,692 KB
testcase_13 AC 499 ms
122,084 KB
testcase_14 AC 443 ms
122,088 KB
testcase_15 AC 436 ms
122,212 KB
testcase_16 AC 460 ms
122,084 KB
testcase_17 AC 535 ms
122,084 KB
testcase_18 AC 2 ms
6,944 KB
testcase_19 AC 1 ms
6,944 KB
testcase_20 AC 607 ms
122,216 KB
testcase_21 AC 607 ms
122,108 KB
testcase_22 AC 2 ms
6,944 KB
testcase_23 AC 1 ms
6,944 KB
権限があれば一括ダウンロードができます

ソースコード

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;}


template<typename T>
struct DisjointSparseTable{
  using F = function<T(T, T)>;
  vector<vector<T> > dat;
  vector<int> ht;
  const F f;
  
  DisjointSparseTable(){}
  DisjointSparseTable(F f):f(f){}
  
  void build(const vector<T> &v){
    int n=v.size(),h=1;
    while((1<<h)<=n) h++;
    dat.assign(h,vector<T>(n));
    ht.assign((1<<h)+1,0);
    for(int j=2;j<=(1<<h)+1;j++) ht[j]=ht[j>>1]+1;
    
    for(int j=0;j<n;j++) dat[0][j]=v[j];
    for(int i=1;i<h;i++){
      int s=1<<i;
      for(int j=0;j<n;j+=s<<1){
        int t=min(j+s,n);
        dat[i][t-1]=v[t-1];
        for(int k=t-2;k>=j;k--) dat[i][k]=f(v[k],dat[i][k+1]);
        if(n<=t) break;
        dat[i][t]=v[t];
        int r=min(t+s,n);
        for(int k=t+1;k<r;k++) dat[i][k]=f(dat[i][k-1],v[k]);
      }
    }
  }

  T query(int l,int r){
    if(l>=--r) return dat[0][l];
    return f(dat[ht[l^r]][l],dat[ht[l^r]][r]);
  }
  
};

//INSERT ABOVE HERE
signed main(){
  int n,m;
  cin>>n>>m;
  vector<vector<int> > r(m,vector<int>(n));
  for(int i=0;i<n;i++)
    for(int j=0;j<m;j++)
      cin>>r[j][i];

  auto f=[](int a,int b){return max(a,b);};
  vector<DisjointSparseTable<int> > ss;
  for(int j=0;j<m;j++){
    ss.emplace_back(f);
    ss[j].build(r[j]);
  }
  
  vector<int> dp(n+1,0);
  for(int i=0;i<n;i++){
    int s=-1;
    for(int j=0;j<m;j++){
      if(ss[j].query(0,i+1)>r[j][i]) continue;
      int L=i,R=n;
      while(L+1<R){
        int M=(L+R)>>1;
        if(ss[j].query(0,M+1)>r[j][i]) R=M;
        else L=M;
      }
      chmax(s,R);
    }
    if(i<=s) dp[i]++,dp[s]--;
  }
  
  for(int i=0;i<n;i++) dp[i+1]+=dp[i];
  for(int i=0;i<n;i++) cout<<dp[i]<<endl;  
  return 0;
}
0