QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#877757#8593. Coinarnur29373 3ms18344kbC++233.5kb2025-02-01 03:26:362025-02-01 03:26:37

Judging History

This is the latest submission verdict.

  • [2025-02-01 03:26:37]
  • Judged
  • Verdict: 3
  • Time: 3ms
  • Memory: 18344kb
  • [2025-02-01 03:26:36]
  • Submitted

answer

#include <bits/stdc++.h>
// #pragma GCC optimize("Ofast,unroll-loops,no-stack-protector,fast-math,inline")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,lzcnt,mmx,abm,avx,avx2,fma")
using namespace std;
#define static_assert(...);
#define speed ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define bigInt __int128
#define int long long
#define dl double long
#define fl float
#define all(s) s.begin(), s.end()
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pob_front
#define ins insert
#define F first
#define S second
#define len length
const int N = 100005;
const int M = 1005;
const int LN = 131072;
const int MOD = 1e9 + 7;//998244353;
const int BLOCK = 500;
int binpow(int a, int b) {//, int MOD) {
    int res = 1;
    a %= MOD;
    while (b > 0) {
        if (b & 1) {
            res = res * a;
            res %= MOD;
        }
        a = a * a;
        a %= MOD;
        b >>= 1;
    }
    return res;
}
int mdiv(int a, int b) {
    int ret = (a % MOD) * binpow(b, MOD - 2);
    ret %= MOD;
    return ret;
}
int mmul(int a, int b) {
    int ret = (a % MOD) * (b % MOD);
    ret %= MOD;
    return ret;
}
int madd(int a, int b) {
    int ret = (a % MOD) + (b % MOD);
    ret %= MOD;
    return ret;
}
int msub(int a, int b) {
    int ret = (a % MOD) - (b % MOD);
    ret = (ret + MOD) % MOD;
    return ret;
}
int GCD(int a, int b) {
    if (b == 0) {
        return a;
    }
    return GCD(b, a % b);
}
struct pqComp
{
    bool operator()(const pair<int, int>& p1, const pair<int, int>& p2) const
    {
        return (p1.F < p2.F) || (p1.F == p2.F && p1.S < p2.S);
    }
};
bool pCompF(pair<int, int>& p1, pair<int, int>& p2)
{
    return p1.F < p2.F;
}
bool pCompS(const pair<int, int>& p1, const pair<int, int>& p2)
{
    return p1.S < p2.S;
}
bool pCompFS(pair<int, int>& p1, pair<int, int>& p2)
{
    return (p1.S < p2.S) || (p1.S == p2.S && p1.F < p2.F);
}
vector <vector<int>> DS {{0, -1}, {0, 1}, {-1, 0}, {1, 0}};
int n, m, lf[2*N], rg[2*N], vis[2*N];
vector<int> tp, g[2*N];
map<int,bool> can[2*N];

void dfs(int v) {
    vis[v] = 1;
    for (int u: g[v]) {
        if (vis[u]) continue;
        dfs(u);
    }
    tp.pub(v);
}

void solve() {
    cin >> n >> m;
    for (int i = 1; i <= m; ++i) {
        int v, u; cin >> v >> u;
        g[v].pub(u);
        can[v][u] = 1;
    }
    for (int i = 1; i <= n; ++i) {
        if (!vis[i]) {
            dfs(i);
        }
    }
    tp.pub(0);
    reverse(all(tp));
    for (int i = 1; i <= n; ++i) {
        int l = i - 1;
        while (l >= 1 && can[tp[l]][tp[i]]) {
            l = lf[l];
        }
        lf[i] = l;
    }
    for (int i = n; i >= 1; --i) {
        int r = i + 1;
        while (r <= n && can[tp[i]][tp[r]]) {
            r = rg[r];
        }
        rg[i] = r;
    }
    vector<int> ans(n + 1);
    for (int i = 1; i <= n; ++i) {
        //cout << tp[i] << " : " << lf[i] << ' ' << rg[i] << '\n';
        if (lf[i] == 0 && rg[i] == n + 1) {
            ans[tp[i]] = 1;
        }
        else {
            ans[tp[i]] = -1;
        }
    }
    for (int i = 1; i <= n; ++i) {
        cout << ans[i] << ' ';
    }
}

signed main() {
    speed;
    int T = 1;
    //cin >> T;
    while (T--) {
        solve();
    }
}
/*
НЕ ЗАХОДИТ РЕШЕНИЕ?
1) ПРОВЕРЬ НА ОЧЕВИДНЫЕ ОШИБКИ В КОДЕ
2) ПРОВЕРЬ НА ПЕРЕПОЛНЕНИЯ
3) УБЕДИСЬ В ПРАВИЛЬНОСТИ АЛГОРИТМА
*/

詳細信息

Subtask #1:

score: 3
Acceptable Answer

Test #1:

score: 3
Acceptable Answer
time: 1ms
memory: 15184kb

input:

4 4
2 4
3 1
4 1
2 3

output:

1 1 -1 -1 

result:

points 0.50 -1 correct

Test #2:

score: 3
Acceptable Answer
time: 0ms
memory: 16516kb

input:

6 8
1 5
5 4
6 2
2 5
4 3
6 1
6 5
2 1

output:

1 1 1 1 1 1 

result:

points 0.50 -1 correct

Test #3:

score: 6
Accepted
time: 1ms
memory: 16724kb

input:

2 1
1 2

output:

1 1 

result:

ok ac

Test #4:

score: 3
Acceptable Answer
time: 2ms
memory: 17032kb

input:

6 12
1 5
5 4
6 2
2 5
4 3
6 5
1 5
1 5
2 4
6 3
1 3
4 3

output:

-1 -1 1 1 1 -1 

result:

points 0.50 -1 correct

Test #5:

score: 3
Acceptable Answer
time: 1ms
memory: 15508kb

input:

7 20
1 6
6 3
1 4
1 5
1 7
1 2
1 5
2 3
4 5
7 2
2 4
5 3
6 3
1 3
4 3
7 5
2 6
4 6
7 2
7 5

output:

1 1 1 1 -1 -1 1 

result:

points 0.50 -1 correct

Test #6:

score: 3
Acceptable Answer
time: 2ms
memory: 18344kb

input:

7 20
5 6
1 3
3 6
4 1
7 4
2 5
4 3
2 6
7 5
4 6
2 6
2 1
4 5
1 3
1 5
7 1
7 6
4 1
7 6
3 6

output:

1 -1 -1 -1 -1 1 -1 

result:

points 0.50 -1 correct

Test #7:

score: 3
Acceptable Answer
time: 2ms
memory: 16472kb

input:

7 20
7 6
4 5
6 4
3 6
4 1
6 2
3 5
5 2
7 6
1 2
3 6
6 4
7 1
6 1
7 1
4 5
3 6
3 5
4 5
3 1

output:

-1 1 -1 1 -1 1 -1 

result:

points 0.50 -1 correct

Subtask #2:

score: 0
Wrong Answer

Dependency #1:

50%
Acceptable Answer

Test #8:

score: 8
Acceptable Answer
time: 0ms
memory: 16412kb

input:

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

output:

-1 -1 -1 1 1 1 1 -1 1 -1 1 1 1 -1 1 -1 -1 -1 -1 1 

result:

points 0.50 -1 correct

Test #9:

score: 0
Wrong Answer
time: 3ms
memory: 16800kb

input:

100 400
87 45
42 17
9 81
65 10
8 82
76 48
39 73
21 58
76 30
76 92
74 76
99 90
38 50
86 74
75 52
8 2
80 55
20 95
66 60
78 82
10 18
22 59
23 17
63 76
56 51
38 10
50 65
41 28
64 77
59 53
100 66
38 84
23 47
17 9
45 75
41 28
33 41
8 78
2 95
3 11
40 15
60 63
23 17
82 2
61 44
44 16
77 34
100 66
96 99
68 12...

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 wa

Subtask #3:

score: 0
Skipped

Dependency #1:

50%
Acceptable Answer

Dependency #2:

0%

Subtask #4:

score: 0
Skipped

Dependency #1:

50%
Acceptable Answer

Dependency #2:

0%