QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#861197 | #9677. 基础博弈练习题 | little_one | 0 | 142ms | 192380kb | C++14 | 3.8kb | 2025-01-18 16:28:10 | 2025-01-18 16:32:03 |
Judging History
answer
#include <cstdio>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
const int inf = 1e9;
int n,m,K,u,v,a[1000005],b[1000005],ord[1000005],cnt,belong[1000005],occ[1000005],mnocc[1000005],mn[4000005],mn2[1000005],old[1000005],mnto[1000005],deg[1000005],f[1000005];
bool vis[1000005];
vector <int> g[1000005],rg[1000005],scc[1000005],q[1000005],h[1000005],fr[1000005];
queue <int> qq;
void update(int pos){
mn[pos] = min(mn[pos << 1],mn[pos << 1 | 1]);
}
void build(int pos,int l,int r){
if(l == r){
mn[pos] = mn2[l] = inf;
return;
}
int mid = (l + r) >> 1;
build(pos << 1,l,mid);
build(pos << 1 | 1,mid + 1,r);
update(pos);
}
void modify(int pos,int l,int r,int p,int x){
if(l == r){
mn[pos] = mn2[l] = x;
return;
}
int mid = (l + r) >> 1;
if(p <= mid){
modify(pos << 1,l,mid,p,x);
}
else{
modify(pos << 1 | 1,mid + 1,r,p,x);
}
update(pos);
}
void dfs1(int pos){
vis[pos] = 1;
for(int i = 0;i < g[pos].size();i++){
if(!vis[g[pos][i]]){
dfs1(g[pos][i]);
}
}
ord[++cnt] = pos;
}
void dfs2(int pos){
scc[belong[pos] = cnt].push_back(pos);
mnocc[cnt] = min(mnocc[cnt],occ[a[pos]]);
for(int i = 0;i < rg[pos].size();i++){
if(!belong[rg[pos][i]]){
dfs2(rg[pos][i]);
}
}
}
int main(){
scanf("%d%d%d",&n,&m,&K);
for(int i = 1;i <= n;i++){
scanf("%d",&a[i]);
occ[i] = inf;
}
for(int i = 1;i <= K;i++){
scanf("%d",&b[i]);
if(occ[b[i]] == inf){
occ[b[i]] = i;
}
}
for(int i = 1;i <= m;i++){
scanf("%d%d",&u,&v);
g[u].push_back(v);
rg[v].push_back(u);
}
for(int i = 1;i <= n;i++){
if(!vis[i]){
dfs1(i);
}
}
cnt = 0;
for(int i = n;i;i--){
if(!belong[ord[i]]){
cnt++;
mnocc[cnt] = mnto[cnt] = f[cnt] = inf;
dfs2(ord[i]);
if(mnocc[cnt] < inf){
q[mnocc[cnt]].push_back(cnt);
}
}
}
build(1,1,n);
for(int i = K;i;i--){
modify(1,1,n,b[i],i);
for(int j = 0;j < q[i].size();j++){
for(int k = 0;k < scc[q[i][j]].size();k++){
old[k] = mn2[a[scc[q[i][j]][k]]];
modify(1,1,n,a[scc[q[i][j]][k]],inf);
}
mnto[-q[i][j]] = mn[1];
for(int k = 0;k < scc[q[i][j]].size();k++){
modify(1,1,n,a[scc[q[i][j]][k]],old[k]);
}
}
}
for(int i = 1;i <= n;i++){
for(int j = 0;j < rg[i].size();j++){
if(belong[i] != belong[rg[i][j]]){
h[belong[i]].push_back(belong[rg[i][j]]);
fr[belong[i]].push_back(i);
deg[belong[rg[i][j]]]++;
}
}
}
for(int i = 1;i <= cnt;i++){
if(!deg[i]){
qq.push(i);
}
}
while(qq.size()){
int tmp = qq.front();
qq.pop();
if(scc[tmp].size() > 1){
mnocc[tmp] = min(mnocc[tmp],f[tmp]);
mnto[tmp] = min(mnto[tmp],f[tmp]);
f[tmp] = mnocc[tmp] - ((mnto[tmp] - mnocc[tmp]) & 1);
}
for(int i = 0;i < h[tmp].size();i++){
f[h[tmp][i]] = min(f[h[tmp][i]],f[tmp]);
if(occ[a[fr[tmp][i]]] < inf){
f[h[tmp][i]] = min(f[h[tmp][i]],occ[a[fr[tmp][i]]] - 1);
}
if(!(--deg[h[tmp][i]])){
qq.push(h[tmp][i]);
}
}
}
for(int i = 1;i <= n;i++){
if(f[belong[i]] < inf){
printf("%d ",f[belong[i]]);
}
else{
printf("-1 ");
}
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 10
Accepted
time: 24ms
memory: 164008kb
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 2 0 -1 7 0 -1 3 -1 0 0 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 0 0 0 -1 0 0 3 0 0 0 -1 -1 3 -1 0 0 0 0 0 8 -1 -1 1 -1 -1 0 3 4 -1 3 -1 3 -1 0 0 0 -1
result:
ok 83 numbers
Test #2:
score: 0
Wrong Answer
time: 24ms
memory: 165616kb
input:
95 33 40 1 1 1 1 3 3 1 1 2 1 1 2 3 3 2 2 2 1 2 3 1 2 1 2 2 1 2 2 3 3 1 1 2 3 1 2 1 3 2 1 1 1 3 2 1 1 1 2 3 2 3 1 1 3 2 3 1 2 1 3 1 2 1 1 1 1 2 1 2 3 1 1 3 3 2 1 3 3 3 1 2 3 1 2 2 1 3 2 1 1 1 2 2 3 1 2 2 3 1 3 3 2 3 3 2 2 2 2 1 1 1 1 2 1 1 1 1 1 2 3 1 3 2 2 3 1 3 3 1 2 2 3 2 1 3 11 95 57 80 22 89 56 ...
output:
2 -1 -1 -1 -1 -1 -1 -1 -1 -1 0 3 -1 -1 -1 -1 -1 -1 -1 3 -1 3 -1 -1 0 -1 3 3 -1 0 0 -1 2 -1 -1 0 -1 -1 -1 -1 -1 -1 3 -1 -1 -1 -1 -1 0 -1 -1 2 -1 -1 -1 3 3 -1 -1 -1 0 -1 -1 -1 -1 2 -1 0 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 3 -1 -1 -1 -1 -1 -1 3 0 -1 -1 -1 -1 2 -1 0 0
result:
wrong answer 66th numbers differ - expected: '3', found: '2'
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Wrong Answer
Test #6:
score: 0
Wrong Answer
time: 142ms
memory: 192380kb
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 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 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 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 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 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 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
wrong answer 544th numbers differ - expected: '4', found: '3'
Subtask #4:
score: 0
Skipped
Dependency #3:
0%
Subtask #5:
score: 0
Skipped
Dependency #4:
0%