题意: n个球队,每个球队有 k个属性(属性值各不相同), a能胜 b当且仅当 a有至少一个属性大于 b,求对于每个 i,前 i个球队中可能能获得冠军的球队个数
Solution
如果把 a胜 b当作 a向 b连一条有向边,缩点后,可以得到一条链,缩点后如果 a向 b连一条边,则说明 a中每个属性最小值均大于 b中对应最大值,每加入一个数,就合并一次
Code
#include<bits/stdc++.h>
using namespace std;
int n,m,i,j;
inline char gc(){
static char buf[100000],*p1=buf,*p2=buf;
return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
inline int rd(){
int x=0,fl=1;char ch=gc();
for (;ch<48||ch>57;ch=gc())if(ch=='-')fl=-1;
for (;48<=ch&&ch<=57;ch=gc())x=(x<<3)+(x<<1)+(ch^48);
return x*fl;
}
inline void wri(int a){if(a<0)a=-a,putchar('-');if(a>=10)wri(a/10);putchar(a%10|48);}
struct node{
int mn[5],mx[5],sz;
friend node operator +(node a,node b){
for (int i=0;i<m;i++) a.mx[i]=max(a.mx[i],b.mx[i]),a.mn[i]=min(a.mn[i],b.mn[i]);
a.sz+=b.sz;
return a;
}
friend bool operator <(node a,node b){//可以看作>,a的所有属性max均小于b的min时a,a<b
for (int i=0;i<m;i++)
if (a.mx[i]>b.mn[i]) return 1;
return 0;
}
}a;
set<node>S;
set<node>::iterator it;
int main(){
n=rd();m=rd();
for (i=0;i<n;i++){
for (j=0;j<m;j++) a.mx[j]=a.mn[j]=rd();
a.sz=1;
for (it=S.upper_bound(a);it!=S.end() && a<*it && *it<a;) a=a+*it,S.erase(it++);
S.insert(a);
wri(S.begin()->sz);putchar(' ');
}
}