結果

問題 No.709 優勝可能性
ユーザー beetbeet
提出日時 2018-11-06 17:49:59
言語 C++17
(gcc 13.2.0 + boost 1.83.0)
結果
AC  
実行時間 652 ms / 3,500 ms
コード長 1,705 bytes
コンパイル時間 2,701 ms
コンパイル使用メモリ 212,884 KB
実行使用メモリ 127,032 KB
最終ジャッジ日時 2023-08-13 03:52:37
合計ジャッジ時間 10,867 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
4,380 KB
testcase_01 AC 2 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 1 ms
4,380 KB
testcase_04 AC 2 ms
4,376 KB
testcase_05 AC 1 ms
4,380 KB
testcase_06 AC 2 ms
4,376 KB
testcase_07 AC 2 ms
4,376 KB
testcase_08 AC 1 ms
4,380 KB
testcase_09 AC 2 ms
4,376 KB
testcase_10 AC 288 ms
39,788 KB
testcase_11 AC 175 ms
10,908 KB
testcase_12 AC 490 ms
69,488 KB
testcase_13 AC 531 ms
127,004 KB
testcase_14 AC 475 ms
126,844 KB
testcase_15 AC 464 ms
127,004 KB
testcase_16 AC 491 ms
127,028 KB
testcase_17 AC 529 ms
126,844 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 2 ms
4,380 KB
testcase_20 AC 648 ms
127,032 KB
testcase_21 AC 652 ms
126,904 KB
testcase_22 AC 2 ms
4,376 KB
testcase_23 AC 2 ms
4,376 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 SparseTable{
  using F = function<T(T,T)>;
  vector<vector<T> > dat;
  vector<int> ht;
  const F f;
  
  SparseTable(){}
  SparseTable(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(n+1,0);
    for(int j=2;j<=n;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,p=1;i<h;i++,p<<=1)
      for(int j=0;j<n;j++)
        dat[i][j]=f(dat[i-1][j],dat[i-1][min(j+p,n-1)]);
  };

  T query(int a,int b){
    int l=b-a;
    return f(dat[ht[l]][a],dat[ht[l]][b-(1<<ht[l])]);
  }
};

//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<SparseTable<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