QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#804608#9810. Obliviate, Then Reincarnatechzhc_WA 117ms55824kbC++144.0kb2024-12-08 01:02:122024-12-08 01:02:12

Judging History

This is the latest submission verdict.

  • [2024-12-08 01:02:12]
  • Judged
  • Verdict: WA
  • Time: 117ms
  • Memory: 55824kb
  • [2024-12-08 01:02:12]
  • Submitted

answer

#include <bits/stdc++.h>

template < typename T > 
inline void read(T &cnt)
{
    cnt = 0; char ch = getchar(); bool op = 1;
    for (; ! isdigit(ch); ch = getchar())
        if (ch == '-') op = 0;
    for (; isdigit(ch); ch = getchar())
        cnt = cnt * 10 + ch - 48;
    cnt = op ? cnt : - cnt;
}
#define int long long

const int N = 5e5 + 10;
const int M = 5e5 + 10;

namespace E1
{
    int head[N], nxt[M], to[M], val[M], tot;
    inline void add(int u, int v, int w)
    {
        // std::cout << "edge " << u << ' ' << v << '\n';
        nxt[++ tot] = head[u];
        head[u] = tot;
        to[tot] = v; 
        val[tot] = w;
    }
}

namespace E2
{
    int head[N], nxt[M], to[M], tot;
    inline void add(int u, int v)
    {
        // std::cout << "EDGE " << u << ' ' << v << '\n';
        nxt[++ tot] = head[u];
        head[u] = tot;
        to[tot] = v; 
    }
}

int n, m, q, valteam[N], in[N];
int dfn[N], low[N], dt;
int col[N], ct;
int sck[N], st;

std::vector < int > set[N];

bool choose[N];

inline void tarjan(int u)
{
    ++ dt; dfn[u] = low[u] = dt;
    ++ st; sck[st] = u;
    for (int i = E1::head[u]; i; i = E1::nxt[i])
    {
        int v = E1::to[i];
        if (! dfn[v])
        {
            tarjan(v);  
            low[u] = std::min(low[u], low[v]); 
        }
        else low[u] = std::min(low[u], dfn[v]);
    }

    if (dfn[u] == low[u])
    {
        ++ ct;
        while (sck[st] != u)
        {
            valteam[ct] ++; col[sck[st]] = ct; set[ct].push_back(sck[st]); st --;
        }
        valteam[ct] ++; col[sck[st]] = ct; set[ct].push_back(sck[st]); st --;
    }
}

std::queue < int > Q;

int opt[N], flg[N], vis[N], nowcase = 0;
long long h[N];

inline void dfs(int x) {
    vis[x] = 1;
    for (int i = E1::head[x]; i; i = E1::nxt[i]) {
        int v = E1::to[i];
        if (choose[v] == 0) continue;
        if (vis[v] == 0) h[v] = h[x] + E1::val[i];
        else if (h[v] != h[x] + E1::val[i]) { 
            nowcase = 1;
            return;
        }
        if (vis[v] == 0) dfs(v);
    }
}

bool exi[N];

inline bool check(int color) {
    exi[color] = 1;
    nowcase = 0;
    int beg = -1;
    for (int i = 0; i < set[color].size(); ++ i)
        choose[set[color][i]] = 1, beg = set[color][i];
    h[beg] = 1;
    dfs(beg);

    for (int i = 0; i < set[color].size(); ++ i)
        choose[set[color][i]] = 0, vis[set[color][i]] = 0;

    if (nowcase == 1) return 1;
    else return 0;
}

signed main()
{
    read(n), read(m), read(q);

    for (int i = 1; i <= m; ++ i)
    {
        int u, v, b; read(u), read(v); b = v;
        if (v == 0) continue;
        u = (((u % n) + n) % n);
        v = (((u + v) % n) + n) % n;
        if (u != v)
            E1::add(u, v, b);
        else opt[u] = 1;
    }
    for (int i = 0; i < n; ++ i)
        if (! dfn[i]) tarjan(i);
    for (int i = 0; i < n; ++ i) {
        // std::cout << "col " << i << ' ' << col[i] << '\n';
        int color = col[i];
        if (opt[i] == 1) {
            flg[color] = 1;
        }
        if (exi[color] == 0 && (valteam[color] > 1 && check(color)))
            flg[color] = 1;
    }
    for (int u = 0; u < n; ++ u)
    {
        for (int i = E1::head[u]; i; i = E1::nxt[i])
        {
            int v = E1::to[i];
            if (col[u] != col[v])
            {
                E2::add(col[v], col[u]);
                in[col[u]] ++; 
            }
        }
    }

    for (int i = 1; i <= ct; ++ i)
        if (in[i] == 0) 
            Q.push(i);

    while (Q.size())
    {
        int u = Q.front(); Q.pop();
        for (int i = E2::head[u]; i; i = E2::nxt[i])
        {
            int v = E2::to[i];
            flg[v] = std::max(flg[v], flg[u]);
            in[v] --;
            if (in[v] == 0) Q.push(v);
        }
    } 
    while (q --) {
        int x; read(x);
        x = (((x % n) + n) % n);
        if (flg[col[x]] == 0) std::cout << "No\n";
        else std::cout << "Yes\n";
    }
    return 0;
}

詳細信息

Test #1:

score: 100
Accepted
time: 0ms
memory: 34260kb

input:

3 2 3
1 1
-1 3
1
2
3

output:

Yes
Yes
No

result:

ok 3 tokens

Test #2:

score: 0
Accepted
time: 0ms
memory: 30508kb

input:

3 2 3
1 1
-1 0
1
2
3

output:

No
No
No

result:

ok 3 tokens

Test #3:

score: 0
Accepted
time: 0ms
memory: 26176kb

input:

1 1 1
0 1000000000
-1000000000

output:

Yes

result:

ok "Yes"

Test #4:

score: 0
Accepted
time: 3ms
memory: 28220kb

input:

3 2 3
0 1000000000
1 -1000000000
-1000000000
0
-1000000000

output:

No
No
No

result:

ok 3 tokens

Test #5:

score: 0
Accepted
time: 107ms
memory: 46568kb

input:

50134 500000 500000
-154428638 -283522863
-186373509 -327130969
154999046 46750274
-933523447 349415487
-437683609 140099255
864996699 -262318199
811293034 -264299324
120273173 52410685
874944410 -52048424
445049930 -803690605
-138111276 -104634331
720288580 126597671
471164416 -348777147
-356502322...

output:

No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
No
...

result:

ok 500000 tokens

Test #6:

score: -100
Wrong Answer
time: 117ms
memory: 55824kb

input:

100848 500000 500000
720352587 361776806
231853504 -933882325
960971230 -83519300
-152772415 -631132247
842871215 -666621297
857194330 -754943024
-698506963 -705416545
-3551931 -927937446
628710320 -942247987
674921043 847145884
-325629529 475694308
-339363446 686789318
236702996 654762989
420412365...

output:

Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
No
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Yes
Y...

result:

wrong answer 619th words differ - expected: 'No', found: 'Yes'