[CF1792D]你说得对,但是卡卡就过了
题意省流
给你 \(n(\leq 5e4)\) 个排列长度为 \(m(\leq 10)\),定义排列的乘法 \(pq=r,r_i=q_{p_i}\),说人话就是 \(q\) 的第 \(p_i\) 个数。
定义 \(i\) 的答案为排列 \(a_ia_j(1\leq j\leq n)\) 的开头为 \(1,2,\dots,k\) 的最大 \(k\)。
做法
所以我们开 \(m^2\) 个 bitset,每个 bitset 维护第 \(i\) 位上值为 \(v\) 的集合,然后按照题意模拟合并,直到这个集合为空,空间复杂度 \(O(\frac{nm^2}{\omega})\),时间复杂度 \(O(\frac{n^2m}{\omega})\),不用卡都能过。
代码
#include<bits/stdc++.h>
#define int long long
using namespace std;
namespace Qaaxaap
{
const int N=5e4+5,mod=998244353;
void work()
{
int t;
cin>>t;
while(t--)
{
int n,m,cnt=0;
cin>>n>>m;
vector<vector<int>> a(n);
vector<vector<bitset<N>>> mp(m,vector<bitset<N>>(m));
for(auto &tmp:a)
{
for(int i=1;i<=m;i++)
{
int v;
cin>>v;
tmp.push_back(v-1);
mp[v-1][i-1][cnt]=1;
}
cnt++;
}
for(int i=0;i<n;i++)
{
int ans=0,lst=1;
bitset<N> chk=mp[0][a[i][0]];
if(chk!=0)
{
ans=1;
while(lst<m)
{
chk&=mp[lst][a[i][lst]],lst++;
if(chk!=0) ans++;
else break;
}
}
cout<<ans<<' ';
}
cout<<endl;
}
}
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0),cout.tie(0);
return Qaaxaap::work(),0;
}

浙公网安备 33010602011771号