結果
| 問題 | No.709 優勝可能性 |
| コンテスト | |
| ユーザー |
beet
|
| 提出日時 | 2018-11-06 17:49:59 |
| 言語 | C++17 (gcc 13.3.0 + boost 1.89.0) |
| 結果 |
AC
|
| 実行時間 | 631 ms / 3,500 ms |
| コード長 | 1,705 bytes |
| 記録 | |
| コンパイル時間 | 1,960 ms |
| コンパイル使用メモリ | 208,940 KB |
| 最終ジャッジ日時 | 2025-01-06 15:40:56 |
|
ジャッジサーバーID (参考情報) |
judge3 / judge5 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 2 |
| other | AC * 22 |
ソースコード
#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;
}
beet