QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#782518#9810. Obliviate, Then ReincarnateA_J1eTL 1098ms39600kbC++233.5kb2024-11-25 20:19:092024-11-25 20:19:10

Judging History

This is the latest submission verdict.

  • [2024-11-26 23:19:26]
  • hack成功,自动添加数据
  • (/hack/1260)
  • [2024-11-25 20:19:10]
  • Judged
  • Verdict: TL
  • Time: 1098ms
  • Memory: 39600kb
  • [2024-11-25 20:19:09]
  • Submitted

answer

#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
using i32 = int;
using i64 = long long;
using i128 = __int128;
#define int long long
const int N = 5e5 + 10;
#define endl "\n"
bool ok[N];
int n, m, q;
vector<pair<int, int>> e[N];
vector<int> e2[N];
bool st[N];
int du[N];
int du2[N];
bool spfa(int s)
{
    vector<bool> inq(n + 10);
    vector<int> dis(n + 10);
    vector<int> cnt(n + 10);
    for (int i = 0; i < n; i++)
        dis[i] = 0;
    priority_queue<pair<int ,int > > q;
    q.push({0 , s});
    inq[s] = 1;
    st[s] = 1;
    cnt[s] = 1;
    while (!q.empty())
    {
        auto tmp = q.top();
        int u = tmp.second;
        q.pop();
        inq[u] = 0;
        for (auto i : e[u])
        {
            int v = i.first;
            int val = i.second;
            if(v == s && dis[s] < 0) return true;
            if (dis[v] > dis[u] + val)
            {
                dis[v] = dis[u] + val;
                st[v] = 1;
                if (!inq[v])
                {
                    q.push({dis[v] , v});
                    inq[v] = 1;
                    cnt[v]++;
                    if (cnt[v] > n)
                        return true;
                }
            }
        }
    }
    return false;
}
bool tt[N];
bool ok2[N];
void topu()
{
    queue<int> q;
    for (int i = 0; i < n; i++)
        if (du[i] == 0)
            q.push(i), st[i] = 1;
    while (!q.empty())
    {
        int tmp = q.front();
        q.pop();
        for (auto i : e[tmp])
        {
            int v = i.first;
            du[v]--;
            if (du[v] == 0)
                st[v] = 1, q.push(v);
        }
    }
    for(int i = 0 ; i < n ; i++)
        tt[i] = st[i];
    for (int i = 0; i < n; i++)
    {
        if (!st[i])
            if (spfa(i))
            {
                queue<int> q;
                q.push(i);
                while (!q.empty())
                {
                    int tmp = q.front();
                    q.pop();
                    for (int v : e2[tmp])
                        if (!ok[v])
                            ok[v] = 1, q.push(v);
                }
            }
    }

    for(int i = 0 ; i < n ; i++)
        st[i] = tt[i];
    for(int i = 0 ; i < n; i++)
        for(auto &v : e[i])
            v.second = -v.second;

    for (int i = 0; i < n; i++)
    {
        if (!st[i])
            if (spfa(i))
            {
                queue<int> q;
                q.push(i);
                while (!q.empty())
                {
                    int tmp = q.front();
                    q.pop();
                    for (int v : e2[tmp])
                        if (!ok2[v])
                            ok2[v] = 1, q.push(v);
                }
            }
    }
    for(int i = 0 ; i < n ; i++)
        ok[i] = ok[i] || ok2[i];
} 

void solve()
{
    cin >> n >> m >> q;
    for (int i = 1; i <= m; i++)
    {
        int a, b;
        cin >> a >> b;
        int u = ((a % n) + n) % n  , v = ((u + b) % n + n) % n;
        if(b == 0) continue;
        du[v]++;
        e[u].push_back({v, b});
        e2[v].push_back(u);
    }
    topu();
    while (q--)
    {
        int tmp;
        cin >> tmp;
        tmp = ((tmp % n) + n) % n;
        if (ok[tmp])
            cout << "Yes" << endl;
        else
            cout << "No" << endl;
    }
}
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    i32 t = 1;
    while (t--)
        solve();
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 7984kb

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: 2ms
memory: 5704kb

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: 2ms
memory: 7684kb

input:

1 1 1
0 1000000000
-1000000000

output:

Yes

result:

ok "Yes"

Test #4:

score: 0
Accepted
time: 1ms
memory: 5732kb

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: 371ms
memory: 33344kb

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: 0
Accepted
time: 736ms
memory: 37172kb

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:

ok 500000 tokens

Test #7:

score: 0
Accepted
time: 1098ms
memory: 39600kb

input:

150017 500000 500000
-421117558 -111455068
-339650079 -834968786
-41718919 419434475
-574669254 477810078
-208090630 898829660
960273942 388265109
-125813433 327374640
360078728 -43670454
325384591 -821490639
180403987 -234797747
-66837706 246624381
691417200 -488557843
-12157264 809720468
-27690539...

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 #8:

score: -100
Time Limit Exceeded

input:

200806 500000 500000
-258823842 -746938452
767141873 239212613
-636327282 608642297
32878678 -599637555
-886750171 266284414
-305571379 -530753894
-479699957 -314474638
-314368519 891752869
-532306854 949604876
-786780332 924096014
881624655 -427208447
-828777932 982410017
-993666003 -964783795
4739...

output:


result: