QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#823013#9810. Obliviate, Then Reincarnateucup-team2179#TL 204ms41632kbC++233.3kb2024-12-20 18:20:132024-12-20 18:20:14

Judging History

This is the latest submission verdict.

  • [2024-12-20 18:20:14]
  • Judged
  • Verdict: TL
  • Time: 204ms
  • Memory: 41632kb
  • [2024-12-20 18:20:13]
  • Submitted

answer

#include<bits/stdc++.h>
#define int long long
#define ll long long
#define pii pair<int, int>
using namespace std;
const int maxn = 5e5 + 10;
vector<pii> G[maxn];
vector<int> vec[maxn];
stack<int> stk;
int dfn[maxn], low[maxn], instk[maxn], scc[maxn], cscc, Cnt;
int dp[maxn], vis[maxn];
void tarjan(int u) {
    low[u] = dfn[u] = ++Cnt;
    instk[u] = 1;
    stk.push(u);
    for (auto [v, w] : G[u]) {
        if (!dfn[v]) {
            tarjan(v);
            low[u] = min(low[u], low[v]);
        } else if (instk[v])
            low[u] = min(low[u], dfn[v]);
    }
    if (low[u] == dfn[u]) {
        int top;
        cscc++;
        do {
            top = stk.top();
            stk.pop();
            instk[top] = 0;
            scc[top] = cscc;
            vec[cscc].push_back(top);
        } while (top != u);
    }
}
int in[maxn], dis[maxn], CNT[maxn];
void solve() {
    memset(vis, -1, sizeof vis);
    memset(dis, 0x3f, sizeof dis);
    int n, m, Q; cin >> n >> m >> Q;
    for (int i = 1; i <= m; i++) {
        int a, b; cin >> a >> b;
        if (b == 0) continue;
        a = (a % n + n) % n;
        int v = (a + b % n + n) % n;
        G[a].emplace_back(v, b);
    }
    for (int i = 0; i < n; i++)
        if (!dfn[i]) tarjan(i);
    for (int i = 1; i <= cscc; i++) {
        queue<int> q;
        q.push(vec[i][0]);
        dis[vec[i][0]] = 0;
        CNT[vec[i][0]] = 1;
        while (!q.empty()) {
            int u = q.front(); q.pop();
            in[u] = 0;
            if (CNT[u] > vec[i].size()) {
                dp[i] = 1;
                break;
            }
            for (auto [v, w] : G[u]) {
                if (scc[v] != scc[u]) continue;
                if (dis[v] > dis[u] + w) {
                    dis[v] = dis[u] + w;
                    if (!in[v]) {
                        in[v] = 1;
                        CNT[v]++;
                        q.push(v);
                    }
                }
            }
        }
        while (!q.empty()) q.pop();
        for (auto u : vec[i]) in[u] = CNT[u] = 0, dis[u] = -1e9;
        if (dp[i]) continue;
        q.push(vec[i][0]);
        dis[vec[i][0]] = 0;
        CNT[vec[i][0]] = 1;
        while (!q.empty()) {
            int u = q.front(); q.pop();
            in[u] = 0;
            if (CNT[u] > vec[i].size()) {
                dp[i] = 1;
                break;
            }
            for (auto [v, w] : G[u]) {
                if (scc[v] != scc[u]) continue;
                if (dis[v] < dis[u] + w) {
                    dis[v] = dis[u] + w;
                    if (!in[v]) {
                        in[v] = 1;
                        CNT[v]++;
                        q.push(v);
                    }
                }
            }
        }
    }
    for (int i = cscc; i; i--) {
        for (auto u : vec[i])
            for (auto [v, w] : G[u]) {
                if (scc[u] != scc[v]) {
                    dp[scc[u]] |= dp[scc[v]];
                }
            }
    }
    while (Q--) {
        int x; cin >> x;
        x = (x % n + n) % n;
        if (dp[scc[x]]) cout << "Yes\n";
        else cout << "No\n";
    }
}
signed main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    int t = 1;
    // cin >> t;
    while (t--) solve();
    return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

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: 5ms
memory: 19912kb

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: 22208kb

input:

1 1 1
0 1000000000
-1000000000

output:

Yes

result:

ok "Yes"

Test #4:

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

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: 204ms
memory: 41632kb

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
Time Limit Exceeded

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:


result: