QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#375995 | #5116. Contests | 369Pai | WA | 0ms | 48716kb | C++14 | 2.0kb | 2024-04-03 19:26:03 | 2024-04-03 19:26:07 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e5 + 5 , LG = 17 , M = 5;
int n , m , a[M][N] , mn[M][M][N] , rk[M][N] , f[LG][M][N];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0) , cout.tie(0);
cin >> n >> m;
for(int i = 0 ; i < m ; i++)
{
for(int j = 1 ; j <= n ; j++)
cin >> a[i][j];
for(int j = 1 ; j <= n ; j++)
rk[i][a[i][j]] = j;
a[i][n + 1] = rk[i][n + 1] = n + 1;
}
for(int i = 0 ; i < m ; i++)
{
for(int j = 0 ; j < m ; j++)
{
mn[i][j][n + 1] = n + 1;
for(int k = n ; k >= 1 ; k--)
mn[i][j][k] = min(mn[i][j][k + 1] , rk[j][a[i][k]]);
}
}
auto chk = [&](int &x , const int &y){x = min(x , y);};
for(int i = 0 ; i < m ; i++)
for(int j = 1 ; j <= n + 1 ; j++)
{
f[0][i][j] = n + 1;
for(int k = 0 ; k < m ; k++)
chk(f[0][i][j] , mn[k][i][rk[k][j]]);
}
for(int i = 1 ; i < LG ; i++)
for(int j = 0 ; j < m ; j++)
for(int k = 1 ; k <= n + 1 ; k++)
{
f[i][j][k] = f[i - 1][j][k];
for(int x = 0 ; x < m ; x++)
chk(f[i][j][k] , f[i - 1][j][a[x][f[i - 1][x][k]]]);
}
// for(int i = 0 ; i < 3 ; i++)
// {
// cerr << "i = " << i << ":\n";
// for(int j = 0 ; j < m ; j++)
// {
// for(int k = 1 ; k <= n + 1 ; k++)
// cerr << " " << f[i][j][k];
// cerr << "\n";
// }
// }
int q; cin >> q;
while(q--)
{
int s , e , res = 0 , u[M] = {};
cin >> s >> e;
for(int i = 0 ; i < m ; i++)
{
u[i] = rk[i][s];
if(u[i] < rk[i][e])
{
res = 1;
break ;
}
}
if(res){cout << "1\n"; continue ;}
for(int i = LG - 1 ; i >= 0 ; i--)
{
int v[M] = {n + 1 , n + 1 , n + 1 , n + 1 , n + 1};
for(int j = 0 ; j < m ; j++)
for(int k = 0 ; k < m ; k++)
v[k] = min(v[k] , f[i][k][a[j][u[j]]]);
bool ok = 1;
for(int j = 0 ; j < m ; j++)
if(v[j] <= rk[j][e])ok = 0;
if(!ok)continue ;
for(int i = 0 ; i < m ; i++)u[i] = v[i];
res += 1ll << i;
}
cout << (res + 2) << "\n";
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 42488kb
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: 48716kb
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:
94 131073 1 1 1 21 1 153 131073 1 19 131073 25 1 1 1 80 1 1 1 1 131073 1 36 102 1 1 1 30 92 1 1 131073 37 36 60 1 1 1 1 1 1 1 1 16 131073 131073 1 1 131073 131073 1 1 140 1 1 77 1 60 1 1 1 4 90 1 1 131073 36 93 1 1 17 148 1 1 1 136 131073 131073 1 28 131073 131073 32 180 1 131073 131073 1 1 1 56 131...
result:
wrong answer 2nd numbers differ - expected: '-1', found: '131073'