QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#879633 | #9677. 基础博弈练习题 | Felix72 | 0 | 66ms | 84464kb | C++14 | 3.3kb | 2025-02-02 09:29:06 | 2025-02-02 09:29:07 |
Judging History
answer
#include <bits/stdc++.h>
#define lowbit(x) (x & (-x))
using namespace std;
const int N = 1000010, M = 220010;
int n, m, k, a[N], b[N], fir_app[N]; vector < int > edge[N];
vector < int > con[N]; int scc, belong[N];
namespace Tarjan
{
int dfn[N], low[N], sign, sta[N], top; bool vis[N];
inline void tarjan(int now)
{
dfn[now] = low[now] = ++sign, sta[++top] = now; vis[now] = true;
for(int to : edge[now])
{
if(!dfn[to]) {tarjan(to); low[now] = min(low[now], low[to]);}
else if(vis[to]) low[now] = min(low[now], dfn[to]);
}
if(dfn[now] == low[now])
{
++scc; sta[top + 1] = 0;
while(sta[top + 1] != now)
{
vis[sta[top]] = false;
con[scc].push_back(sta[top]);
belong[sta[top]] = scc; --top;
}
}
}
inline void solve()
{
for(int i = 1; i <= n; ++i) if(!dfn[i]) tarjan(i);
}
}
int ln[N], rn[N];
namespace Init
{
int s_id[N], pt; bool tag[N];
inline bool cmp(int x, int y) {return ln[x] > ln[y];}
struct Chain
{
int pre, nxt, data, p;
}; Chain ch[N]; int p_toch[N], idch, st_ch;
inline void erase(int id)
{
if(id == st_ch) {st_ch = 0; return ;}
int pr = ch[id].pre, nx = ch[id].nxt;
ch[pr].nxt = nx, ch[nx].pre = pr;
}
inline void push_front(int id)
{
if(!st_ch) {st_ch = id; return ;}
ch[id].nxt = st_ch;
st_ch = id;
}
inline void solve()
{
for(int id = 1; id <= scc; ++id)
{
ln[id] = 1e9;
for(int x : con[id]) ln[id] = min(ln[id], fir_app[a[x]]);
}
for(int i = 1; i <= scc; ++i) s_id[i] = i;
sort(s_id + 1, s_id + scc + 1, cmp);
pt = k;
for(int i = 1; i <= scc; ++i)
{
int id = s_id[i];
while(pt >= ln[id])
{
int c = b[pt];
if(p_toch[c]) erase(p_toch[c]);
ch[++idch].data = c, ch[idch].p = pt;
push_front(idch);
--pt;
}
for(int x : con[id]) tag[a[x]] = true;
if(st_ch)
{
rn[id] = k;
for(int j = st_ch; j; j = ch[j].nxt)
if(!tag[ch[j].data])
{rn[id] = ch[j].p - 1; break;}
}
for(int x : con[id]) tag[a[x]] = false;
}
}
}
int f[N];
namespace Dp
{
bool vis[N];
inline void solve()
{
memset(f, 0x3f, sizeof(f));
for(int i = scc; i >= 1; --i)
{
vector < int > tr;
for(int x : con[i])
{
for(int y : edge[x])
{
if(belong[x] == belong[y]) continue;
if(vis[belong[y]]) continue;
vis[belong[y]] = true;
tr.push_back(belong[y]);
}
}
for(int j : tr) vis[j] = false;
// cerr << "DP " << i << " +++++++++++++++++++++\n";
for(int j : tr)
{
// cerr << "tr " << j << " " << ln[j] << '\n';
f[i] = min(f[i], f[j]);
if(f[j] != ln[j] + 1) f[i] = min(f[i], ln[j]);
}
}
}
}
int main()
{
// freopen("text.in", "r", stdin);
// freopen("prog.out", "w", stdout);
ios::sync_with_stdio(false);
cin.tie(0), cout.tie(0);
cin >> n >> m >> k;
for(int i = 1; i <= n; ++i) cin >> a[i];
for(int i = 1; i <= k; ++i) cin >> b[i];
memset(fir_app, 0x3f, sizeof(fir_app));
for(int i = k; i >= 1; --i) fir_app[b[i]] = i;
for(int i = 1, x, y; i <= m; ++i)
{
cin >> x >> y;
edge[x].push_back(y);
}
Tarjan::solve(); Init::solve();
Dp::solve();
for(int i = 1; i <= n; ++i)
{
if(f[belong[i]] <= n) cout << f[belong[i]] - 1 << " ";
else cout << -1 << " ";
}
cout << '\n';
return 0;
}
/*
*/
詳細信息
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 6ms
memory: 77692kb
input:
83 93 13 8 9 10 7 7 7 6 3 1 10 6 2 5 7 1 3 4 2 1 10 7 4 8 9 2 2 1 9 2 5 1 7 8 6 1 9 9 10 4 1 2 9 2 3 4 2 9 10 8 1 4 1 8 4 1 4 4 7 4 8 2 9 2 5 2 2 3 3 8 5 2 9 3 10 8 8 1 6 6 1 6 7 10 7 5 10 3 2 2 7 4 8 7 6 6 5 56 36 33 41 32 62 37 7 6 53 41 13 9 36 44 77 38 62 76 16 72 5 40 13 55 60 5 78 72 45 13 44 ...
output:
0 -1 -1 -1 10 0 -1 7 0 -1 7 -1 0 8 1 -1 0 -1 0 0 -1 0 -1 2 -1 -1 -1 -1 -1 -1 0 0 0 -1 0 -1 3 0 0 0 0 0 -1 -1 -1 -1 1 0 4 -1 4 0 3 7 0 0 -1 -1 3 -1 7 0 0 0 0 8 -1 -1 7 -1 -1 0 3 4 -1 3 -1 3 -1 4 0 0 -1
result:
wrong answer 5th numbers differ - expected: '2', found: '10'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Wrong Answer
Test #6:
score: 0
Wrong Answer
time: 66ms
memory: 84464kb
input:
100000 355071 10000 5 7 4 7 4 1 10 5 9 4 9 4 3 10 5 4 9 1 7 10 1 6 10 3 10 9 8 4 6 3 10 8 6 8 3 5 10 9 7 7 1 3 8 8 6 2 8 4 2 9 1 10 3 6 3 8 9 10 5 7 3 2 1 5 7 4 3 4 6 4 2 7 2 5 5 6 4 6 7 4 4 6 4 2 3 9 9 9 10 8 1 6 7 2 9 8 2 3 1 6 9 4 10 3 10 1 2 3 3 4 1 1 1 5 8 6 8 3 1 6 2 9 5 9 4 7 2 10 7 5 2 2 7 4...
output:
0 0 2 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1 2 0 0 0 0 0 3 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 0 7 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 8 0 0 0 0 0 0 0 ...
result:
wrong answer 3rd numbers differ - expected: '0', found: '2'
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Skipped
Dependency #4:
0%