結果

問題 No.709 優勝可能性
ユーザー beetbeet
提出日時 2018-11-06 18:12:05
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 721 ms / 3,500 ms
コード長 1,983 bytes
コンパイル時間 2,957 ms
コンパイル使用メモリ 217,548 KB
実行使用メモリ 129,620 KB
最終ジャッジ日時 2024-04-30 22:17:44
合計ジャッジ時間 9,488 ms
ジャッジサーバーID
(参考情報)
judge2 / judge4
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
6,816 KB
testcase_01 AC 2 ms
6,944 KB
testcase_02 AC 2 ms
6,940 KB
testcase_03 AC 2 ms
6,940 KB
testcase_04 AC 2 ms
6,940 KB
testcase_05 AC 2 ms
6,944 KB
testcase_06 AC 2 ms
6,940 KB
testcase_07 AC 2 ms
6,944 KB
testcase_08 AC 2 ms
6,944 KB
testcase_09 AC 2 ms
6,944 KB
testcase_10 AC 310 ms
40,640 KB
testcase_11 AC 184 ms
11,216 KB
testcase_12 AC 529 ms
70,968 KB
testcase_13 AC 596 ms
129,488 KB
testcase_14 AC 522 ms
129,496 KB
testcase_15 AC 514 ms
129,620 KB
testcase_16 AC 549 ms
129,616 KB
testcase_17 AC 635 ms
129,492 KB
testcase_18 AC 2 ms
6,940 KB
testcase_19 AC 2 ms
6,940 KB
testcase_20 AC 713 ms
129,492 KB
testcase_21 AC 721 ms
129,488 KB
testcase_22 AC 2 ms
6,940 KB
testcase_23 AC 2 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(int n,F f):f(f){init(n);}
  
  void init(int n){
    int 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);j++) ht[j]=ht[j>>1]+1;
  }
  
  void build(int n,vector<T> &v){
    int h=1;
    while((1<<h)<=n) h++;
    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(n,f);
    ss[j].build(n,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);
    }
    //cout<<i<<" "<<s<<endl;
    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