QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#213418 | #5116. Contests | zhuibao | WA | 1ms | 13916kb | C++20 | 3.5kb | 2023-10-14 14:10:16 | 2023-10-14 14:10:16 |
Judging History
answer
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll; typedef unsigned long long ull; typedef pair<ll, ll>pi; typedef complex<double>cx;
#define int ll
#define X first
#define Y second
#define fer(i,a,n) for(int i=a;i<=n;i++)
#define ref(i,n,a) for(int i=n;i>=a;i--)
#define endl '\n'
#define mem(a,x) memset(a,x,sizeof a)
#define ac IO;int t;cin>>t;while(t--)solve()
#define AC signed main(){IO;solve();}
#define NO {cout<<"NO"<<endl;return;}
#define YES {cout<<"YES"<<endl;return;}
#define re(a) {cout<<a<<endl;return;}
#define all(v) v.begin(),v.end()
//ofstream fout("1.out", ios::out);
//ifstream fin("1.in", ios::in);
//#define cout fout
//#define cin fin
//--------------------瑞神神中神--------------------
const int N=1e5+10,M=7,K=18;
int a[M][N],f[N][M][K+2],tot[M][N],mx[M][M];
int n,m,q;
int cmp(int i,int x,int y)
{
if(tot[i][x]<tot[i][y])return 1;
if(tot[i][x]==tot[i][y])return 0;
return -1;
}
void solve()
{
cin>>n>>m;
for(int i=1;i<=m;i++)
{
tot[i][0]=n+1;
for(int j=1;j<=n;j++)
{
cin>>a[i][j];
tot[i][a[i][j]]=j;
f[j][i][0]=j;
}
for(int k=1;k<=m;k++)
{
mx[i][k]=0;
}
}
for(int i=n;i>=1;i--)
{
for(int j=1;j<=m;j++)
{
for(int k=1;k<=m;k++) //从k跳向j
{
if(cmp(j,mx[k][j],f[a[k][i]][j][0])==1)
{
f[a[k][i]][j][0]=mx[k][j];
}
}
}
for(int j=1;j<=m;j++)
{
for(int k=1;k<=m;k++)
{
if(cmp(k,a[j][i],mx[j][k])==1)
{
mx[j][k]=a[j][i];
}
}
}
}
for(int k=1;k<=K;k++)
{
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
f[i][j][k]=f[i][j][k-1];
for(int l=1;l<=m;l++)
{
int ul=f[i][l][k-1];
if(cmp(j,f[ul][j][k-1],f[i][j][k])==1)
{
f[i][j][k]=f[ul][j][k-1];
}
}
}
}
}
cin>>q;
while(q--)
{
int x,y;
cin>>x>>y;
int flg=0;
for(int i=1;i<=m;i++)
{
if(cmp(i,x,y)==1)
{
flg=1;
}
}
if(flg)
{
cout<<1<<'\n';
continue;
}
if(m==1)
{
cout<<-1<<'\n';
continue;
}
vector<int>p(m+1,x);
int ans=0;
for(int k=K;k>=0;k--)
{
vector<int>tmp(m+1);
for(int i=1;i<=m;i++)
{
for(int j=1;j<=m;j++)
{
if(cmp(j,f[p[i]][j][k],tmp[j]))
{
tmp[j]=f[p[i]][j][k];
}
}
}
flg=-1;
for(int i=1;i<=m;i++)
{
flg=max(flg,cmp(i,tmp[i],y));
}
if(flg==-1)
{
ans+=1<<k;
p=tmp;
}
else if(flg==0)
{
ans+=1<<k;
break;
}
}
cout<<ans+2<<'\n';
}
}
AC
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 9752kb
input:
6 2 1 3 2 5 4 6 2 1 4 3 6 5 4 1 4 5 3 6 1 5 2
output:
1 2 5 3
result:
ok 4 number(s): "1 2 5 3"
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 13916kb
input:
998 5 1 2 6 3 4 5 7 11 8 9 14 12 13 10 15 16 18 19 20 17 23 22 21 26 24 25 27 29 30 28 32 31 34 33 37 38 39 35 40 36 41 43 42 46 44 48 45 47 51 49 50 56 52 57 53 54 55 62 58 59 63 64 60 65 66 61 67 69 70 68 71 73 74 75 72 78 77 79 82 76 81 85 84 80 86 87 83 88 90 91 89 92 96 98 94 95 97 101 93 103 1...
output:
96 524289 1 1 1 21 1 153 524289 1 19 524289 25 1 1 1 81 1 1 1 1 524289 1 36 104 1 1 1 32 92 1 1 524289 38 36 60 1 1 1 1 1 1 1 1 16 524289 524289 1 1 524289 524289 1 1 140 1 1 77 1 61 1 1 1 5 90 1 1 524289 37 94 1 1 17 149 1 1 1 137 524289 524289 1 28 524289 524289 33 183 1 524289 524289 1 1 1 57 524...
result:
wrong answer 1st numbers differ - expected: '94', found: '96'