QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#860386#9677. 基础博弈练习题Max_s_xaM0 162ms161208kbC++175.0kb2025-01-18 13:07:562025-01-18 13:08:04

Judging History

你现在查看的是最新测评结果

  • [2025-01-18 13:08:04]
  • 评测
  • 测评结果:0
  • 用时:162ms
  • 内存:161208kb
  • [2025-01-18 13:07:56]
  • 提交

answer

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <random>
#include <ctime>
#include <chrono>
#include <numeric>
#include <iomanip>
#include <cassert>

typedef long long ll;
typedef double lf;
typedef unsigned long long ull;

// #define DEBUG 1
struct IO
{
    #define MAXSIZE (1 << 20)
    #define isdigit(x) (x >= '0' && x <= '9')
    char buf[MAXSIZE], *p1, *p2;
    char pbuf[MAXSIZE], *pp;
    #if DEBUG
    #else
    IO() : p1(buf), p2(buf), pp(pbuf) {}
    ~IO() {fwrite(pbuf, 1, pp - pbuf, stdout);}
    #endif
    #define gc() (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, MAXSIZE, stdin), p1 == p2) ? ' ' : *p1++)
    #define blank(x) (x == ' ' || x == '\n' || x == '\r' || x == '\t')

    template <typename T>
    void Read(T &x)
    {
        #if DEBUG
        std::cin >> x;
        #else
        bool sign = 0; char ch = gc(); x = 0;
        for (; !isdigit(ch); ch = gc())
            if (ch == '-') sign = 1;
        for (; isdigit(ch); ch = gc()) x = x * 10 + (ch ^ 48);
        if (sign) x = -x;
        #endif
    }
    void Read(char *s)
    {
        #if DEBUG
        std::cin >> s;
        #else
        char ch = gc();
        for (; blank(ch); ch = gc());
        for (; !blank(ch); ch = gc()) *s++ = ch;
        *s = 0;
        #endif
    }
    void Read(char &c) {for (c = gc(); blank(c); c = gc());}

    void Push(const char &c)
    {
        #if DEBUG
        putchar(c);
        #else
        if (pp - pbuf == MAXSIZE) fwrite(pbuf, 1, MAXSIZE, stdout), pp = pbuf;
        *pp++ = c;
        #endif
    }
    template <typename T>
    void Write(T x)
    {
        if (x < 0) x = -x, Push('-');
        static T sta[35];
        int top = 0;
        do sta[top++] = x % 10, x /= 10; while (x);
        while (top) Push(sta[--top] ^ 48);
    }
    template <typename T>
    void Write(T x, char lst) {Write(x), Push(lst);}
} IO;
#define Read(x) IO.Read(x)
#define Write(x, y) IO.Write(x, y)
#define Put(x) IO.Push(x)

using namespace std;

const int MAXN = 1e6 + 10;

int n, m, k;
int a[MAXN], b[MAXN];
vector <int> e[MAXN], vec[MAXN], g[MAXN];

int dfn[MAXN], low[MAXN], clk, bel[MAXN], scc, st[MAXN], top; bool inq[MAXN];
void Tarjan(int u)
{
    dfn[u] = low[u] = ++clk, inq[u] = 1, st[++top] = u;
    for (auto v : e[u])
        if (!dfn[v]) Tarjan(v), low[u] = min(low[u], low[v]);
        else if (inq[v]) low[u] = min(low[u], dfn[v]);
    if (low[u] == dfn[u])
    {
        scc++;
        while (st[top] != u) inq[st[top]] = 0, bel[st[top]] = scc, top--;
        bel[u] = scc, inq[u] = 0, top--;
    }
}

int apr[MAXN], lst[MAXN], mnpos[MAXN];
int pre[MAXN], nxt[MAXN], dl[MAXN], da[MAXN], db[MAXN], dt;
int h1[MAXN], h2[MAXN];
int mn[MAXN], f[MAXN];

int main()
{
    #if DEBUG
    #else
    ios::sync_with_stdio(0), cin.tie(0);
    #endif
    Read(n), Read(m), Read(k);
    for (int i = 1; i <= n; i++) Read(a[i]);
    for (int i = 1; i <= k; i++) Read(b[i]);
    for (int i = 1, u, v; i <= m; i++) Read(u), Read(v), e[u].push_back(v);
    for (int i = 1; i <= n; i++)
        if (!dfn[i]) Tarjan(i);
    for (int i = 1; i <= k; i++) lst[i] = apr[b[i]], apr[b[i]] = i;
    for (int i = 1, t = 0; i <= k; i++)
        if (!lst[i])
        {
            lst[i] = mnpos[b[i]] = i;
            pre[i] = t, t = i;
        }
    for (int i = 1; i <= k; i++)
        if (lst[i] == i) nxt[pre[i]] = i;
    for (int i = 1; i <= scc; i++) mn[i] = 2e9;
    for (int i = 1; i <= n; i++) mn[bel[i]] = min(mn[bel[i]], mnpos[a[i]]), vec[bel[i]].push_back(a[i]);
    for (int i = 1; i <= scc; i++)
    {
        for (auto x : vec[i]) inq[x] = 1;
        for (auto x : vec[i])
            if (inq[x])
            {
                inq[x] = 0;
                int u = mnpos[x];
                if (u == mn[i]) continue;
                dl[++dt] = u, da[dt] = pre[u], db[dt] = nxt[u];
                nxt[pre[u]] = nxt[u], pre[nxt[u]] = pre[u];
            }
        h2[i] = (nxt[mn[i]] ? nxt[mn[i]] : 2e9);
        while (dt) nxt[da[dt]] = dl[dt], pre[db[dt]] = dl[dt], dt--;
    }
    for (int i = k; i >= 1; i--)
    {
        while (top && lst[st[top]] >= lst[i]) top--;
        st[++top] = i;
        while (top && lst[st[top]] >= i) top--;
        h1[i] = (top ? st[top] : 2e9);
    }
    for (int u = 1; u <= n; u++)
        for (auto v : e[u])
            if (bel[u] ^ bel[v]) g[bel[u]].push_back(bel[v]);
    for (int u = 1; u <= scc; u++)
    {
        f[u] = 2e9;
        for (auto v : g[u])
        {
            f[u] = min(f[u], f[v]);
            if (mn[v] + 1 < f[v]) f[u] = min(f[u], mn[v]);
        }
        if (vec[u].size() > 1 && mn[u] + 1 < f[u])
        {
            int p = min(f[u] - 2, min(h2[u], h1[mnpos[u]]));
            f[u] = min(f[u], mn[u] + (~(p - mn[u]) & 1));
        }
    }
    for (int i = 1; i <= n; i++) cout << (f[bel[i]] > k ? -1 : f[bel[i]] - 1) << ' '; cout << '\n';
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 8ms
memory: 98064kb

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:

-1 -1 -1 -1 -1 -1 -1 7 -1 -1 -1 -1 -1 -1 1 -1 -1 -1 -1 -1 -1 -1 -1 2 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 3 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 8 -1 -1 -1 -1 -1 -1 3 4 -1 3 -1 3 -1 -1 -1 -1 -1 

result:

wrong answer 1st numbers differ - expected: '0', found: '-1'

Subtask #2:

score: 0
Skipped

Dependency #1:

0%

Subtask #3:

score: 0
Wrong Answer

Test #6:

score: 30
Accepted
time: 36ms
memory: 105608kb

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:

ok 100000 numbers

Test #7:

score: 30
Accepted
time: 41ms
memory: 117780kb

input:

100000 300561 10000
6 3 6 10 10 9 7 3 6 4 5 4 1 2 3 2 10 6 3 7 8 7 10 5 9 10 2 3 9 5 6 10 9 1 4 9 1 10 7 2 9 10 5 5 9 3 5 5 5 9 9 5 1 7 5 10 8 6 8 4 5 9 2 10 1 6 4 10 10 9 2 1 10 1 9 5 3 2 9 3 4 8 10 7 5 2 4 5 3 6 9 7 5 10 2 7 4 7 10 8 1 7 7 1 7 7 6 6 7 1 5 4 6 2 1 8 6 10 6 10 1 5 8 4 6 2 10 6 10 4 ...

output:

0 4 0 0 3 0 0 4 0 0 0 0 0 0 0 0 0 0 1 0 0 1 7 0 1 2 0 0 0 0 4 0 0 1 0 0 0 2 0 0 0 3 0 0 1 0 0 0 3 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 1 0 9 0 0 0 2 0 3 1 0 2 1 0 0 0 2 0 0 0 0 0 0 3 0 0 0 0 0 2 2 0 0 1 0 0 0 0 0 1 0 0 1 0 2 0 6 0 0 1 5 0 0 3 0 0 1 2 0 2 3 0 0 2 0 1 1 9 0 2 5 2 0 2 1 3 1 6 4 0 0 1 0 2 1 0 ...

result:

ok 100000 numbers

Test #8:

score: 0
Wrong Answer
time: 162ms
memory: 161208kb

input:

500000 1770902 50000
4 7 2 3 6 10 8 2 2 6 2 3 3 7 3 1 5 2 1 10 2 6 3 4 2 8 10 6 6 10 9 3 3 2 9 10 4 5 3 9 7 10 4 3 6 6 4 9 4 4 4 1 9 5 6 10 3 7 5 8 10 1 6 5 1 7 9 10 2 4 6 9 6 2 2 8 4 7 9 1 9 4 6 4 6 3 9 2 2 1 1 1 8 3 10 10 2 2 5 15 20 18 17 15 12 11 11 11 11 12 13 19 18 20 15 11 11 20 10 14 13 14 1...

output:

-1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 -1 ...

result:

wrong answer 1st numbers differ - expected: '0', found: '-1'

Subtask #4:

score: 0
Skipped

Dependency #3:

0%

Subtask #5:

score: 0
Skipped

Dependency #4:

0%