답안 #648643

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
648643 2022-10-07T08:52:22 Z mychecksedad Joker (BOI20_joker) C++17
39 / 100
2000 ms 60912 KB
/* Author : Mychecksdead */
#include<bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long int ll;
typedef long double ld;
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define PI 3.1415926535
#define pb push_back
#define setp() cout << setprecision(15)
#define all(x) x.begin(), x.end()
#define oset tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define debug(x) cerr << #x << " is " << x << '\n';
const int N = 1e6+100, M = 2e5+10, F = 2147483646, K = 20;

struct Dsu {
    vector<int> rank;
    vector<pair<int, int>> p;
    vector<bool> bp;
    Dsu(int n){
        rank.resize(n+1, 0);
        p.resize(n+1);
        bp.resize(n+1);
        for(int i = 0; i <= n; ++i) p[i] = {i, 0}, bp[i] = 1;
    }
    pair<int, int> find_set(int v) {
        if (v != p[v].first) {
            int parity = p[v].second;
            p[v] = find_set(p[v].first);
            p[v].second ^= parity;
        }
        return p[v];
    }
    void merge(int a, int b){
        pair<int, int> pa = find_set(a);
        a = pa.first;
        int x = pa.second;

        pair<int, int> pb = find_set(b);
        b = pb.first;
        int y = pb.second;

        if (a == b) {
            if (x == y)
                bp[a] = 0;
        } else {
            if (rank[a] < rank[b])
                swap (a, b);
            p[b] = make_pair(a, x^y^1);
            bp[a] = bp[b] & bp[a];
            if (rank[a] == rank[b])
                ++rank[a];
        }
    }
};


int n, m, q, l, r;
bool ok;
vector<pair<int, int>> g[N], edges;
bitset<M> vis, pos;
void dfs(int v, int p, bool c){
    vis[v] = 1;
    pos[v] = c;
    for(auto k: g[v]){
        int u = k.first;
        if(l <= k.second && k.second <= r) continue;
        if(u != p){
            if(vis[u])
                ok |= pos[v] == pos[u];
            else
                dfs(u, v, !c);
        }
    }
}
void solve(){
    cin >> n >> m >> q;
    for(int i = 0; i < m; ++i){
        int u, v; cin >> u >> v;
        g[u].pb({v, i + 1});
        g[v].pb({u, i + 1});
        edges.pb({u, v});
    }
    if(n <= 2000 && q <= 2000){
        for(int i = 0; i < q; ++i){
            cin >> l >> r;
            vis = 0;
            ok = 0;
            for(int v = 1; v <= n; ++v) if(!ok && !vis[v]) dfs(v, v, 0);
            if(ok) cout << "YES\n";
            else cout << "NO\n";
        }
    }
    else{
        vector<pair<int, int>> queries[205];
        vector<int> qq(q + 1);
        for(int i = 1; i <= q; ++i){
            cin >> l >> r;
            queries[l].pb({r, i});
        }
        for(int i = 1; i <= 200; ++i){
            if(queries[i].empty()) continue;
            Dsu d(n);
            ok = 0;
            for(int j = 1; j < i; ++j){
                int u = edges[j - 1].first, v = edges[j - 1].second;
                d.merge(u, v);
                ok |= !d.bp[d.find_set(u).first] | !d.bp[d.find_set(v).first];
            }
            sort(all(queries[i]), [&](const pair<int, int> &a, const pair<int, int> &b){
                return a.first > b.first;
            });
            int cur = m;
            for(auto k: queries[i]){
                while(cur > k.first){
                    int u = edges[cur - 1].first, v = edges[cur - 1].second;
                    d.merge(u, v);
                    ok |= !d.bp[d.find_set(u).first] | !d.bp[d.find_set(v).first];
                    cur--;
                }
                qq[k.second] = ok;
            }
        }
        for(int i = 1; i <= q; ++i) cout << (qq[i] ? "YES\n" : "NO\n");
    }
}



int main(){
    cin.tie(0); ios::sync_with_stdio(0);
    int T = 1, aa;
    // cin >> T;aa=T;
    while(T--){
        // cout << "Case #" << aa-T << ": ";
        solve();
        cout << '\n';
    }
    return 0;
 
}

Compilation message

Joker.cpp: In function 'int main()':
Joker.cpp:134:16: warning: unused variable 'aa' [-Wunused-variable]
  134 |     int T = 1, aa;
      |                ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 23812 KB Output is correct
2 Correct 15 ms 23756 KB Output is correct
3 Correct 17 ms 23736 KB Output is correct
4 Correct 17 ms 23852 KB Output is correct
5 Correct 19 ms 23860 KB Output is correct
6 Correct 17 ms 23840 KB Output is correct
7 Correct 17 ms 23772 KB Output is correct
8 Correct 18 ms 23764 KB Output is correct
9 Correct 17 ms 23764 KB Output is correct
10 Correct 20 ms 23876 KB Output is correct
11 Correct 18 ms 23848 KB Output is correct
12 Correct 19 ms 23860 KB Output is correct
13 Correct 20 ms 23864 KB Output is correct
14 Correct 17 ms 23764 KB Output is correct
15 Correct 13 ms 23764 KB Output is correct
16 Correct 14 ms 23812 KB Output is correct
17 Correct 13 ms 23764 KB Output is correct
18 Correct 13 ms 23868 KB Output is correct
19 Correct 13 ms 23764 KB Output is correct
20 Correct 14 ms 23876 KB Output is correct
21 Correct 14 ms 23772 KB Output is correct
22 Correct 14 ms 23764 KB Output is correct
23 Correct 14 ms 23764 KB Output is correct
24 Correct 14 ms 23764 KB Output is correct
25 Correct 14 ms 23764 KB Output is correct
26 Correct 15 ms 23872 KB Output is correct
27 Correct 15 ms 23868 KB Output is correct
28 Correct 14 ms 23764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 23812 KB Output is correct
2 Correct 15 ms 23756 KB Output is correct
3 Correct 17 ms 23736 KB Output is correct
4 Correct 17 ms 23852 KB Output is correct
5 Correct 19 ms 23860 KB Output is correct
6 Correct 17 ms 23840 KB Output is correct
7 Correct 17 ms 23772 KB Output is correct
8 Correct 18 ms 23764 KB Output is correct
9 Correct 17 ms 23764 KB Output is correct
10 Correct 20 ms 23876 KB Output is correct
11 Correct 18 ms 23848 KB Output is correct
12 Correct 19 ms 23860 KB Output is correct
13 Correct 20 ms 23864 KB Output is correct
14 Correct 17 ms 23764 KB Output is correct
15 Correct 13 ms 23764 KB Output is correct
16 Correct 14 ms 23812 KB Output is correct
17 Correct 13 ms 23764 KB Output is correct
18 Correct 13 ms 23868 KB Output is correct
19 Correct 13 ms 23764 KB Output is correct
20 Correct 14 ms 23876 KB Output is correct
21 Correct 14 ms 23772 KB Output is correct
22 Correct 14 ms 23764 KB Output is correct
23 Correct 14 ms 23764 KB Output is correct
24 Correct 14 ms 23764 KB Output is correct
25 Correct 14 ms 23764 KB Output is correct
26 Correct 15 ms 23872 KB Output is correct
27 Correct 15 ms 23868 KB Output is correct
28 Correct 14 ms 23764 KB Output is correct
29 Correct 90 ms 23892 KB Output is correct
30 Correct 100 ms 23892 KB Output is correct
31 Correct 115 ms 23984 KB Output is correct
32 Correct 91 ms 23892 KB Output is correct
33 Correct 78 ms 23964 KB Output is correct
34 Correct 107 ms 23988 KB Output is correct
35 Correct 121 ms 23972 KB Output is correct
36 Correct 46 ms 23928 KB Output is correct
37 Correct 91 ms 23860 KB Output is correct
38 Correct 97 ms 23956 KB Output is correct
39 Correct 96 ms 23972 KB Output is correct
40 Correct 87 ms 23988 KB Output is correct
41 Correct 92 ms 23992 KB Output is correct
42 Correct 102 ms 23984 KB Output is correct
43 Correct 87 ms 23892 KB Output is correct
44 Correct 120 ms 23984 KB Output is correct
45 Correct 123 ms 23976 KB Output is correct
46 Correct 121 ms 23976 KB Output is correct
47 Correct 89 ms 23960 KB Output is correct
48 Correct 95 ms 23968 KB Output is correct
49 Correct 102 ms 23972 KB Output is correct
50 Correct 100 ms 23952 KB Output is correct
51 Correct 84 ms 23984 KB Output is correct
52 Correct 97 ms 23976 KB Output is correct
53 Correct 107 ms 23984 KB Output is correct
54 Correct 116 ms 23964 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 23812 KB Output is correct
2 Correct 15 ms 23756 KB Output is correct
3 Correct 128 ms 34260 KB Output is correct
4 Correct 133 ms 37180 KB Output is correct
5 Correct 164 ms 37048 KB Output is correct
6 Correct 144 ms 35912 KB Output is correct
7 Correct 133 ms 35832 KB Output is correct
8 Correct 139 ms 34972 KB Output is correct
9 Correct 161 ms 35952 KB Output is correct
10 Correct 155 ms 37036 KB Output is correct
11 Correct 131 ms 35556 KB Output is correct
12 Correct 148 ms 36616 KB Output is correct
13 Correct 118 ms 34712 KB Output is correct
14 Correct 125 ms 34944 KB Output is correct
15 Correct 174 ms 35904 KB Output is correct
16 Correct 168 ms 37028 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 23812 KB Output is correct
2 Correct 15 ms 23756 KB Output is correct
3 Correct 17 ms 23736 KB Output is correct
4 Correct 17 ms 23852 KB Output is correct
5 Correct 19 ms 23860 KB Output is correct
6 Correct 17 ms 23840 KB Output is correct
7 Correct 17 ms 23772 KB Output is correct
8 Correct 18 ms 23764 KB Output is correct
9 Correct 17 ms 23764 KB Output is correct
10 Correct 20 ms 23876 KB Output is correct
11 Correct 18 ms 23848 KB Output is correct
12 Correct 19 ms 23860 KB Output is correct
13 Correct 20 ms 23864 KB Output is correct
14 Correct 17 ms 23764 KB Output is correct
15 Correct 13 ms 23764 KB Output is correct
16 Correct 14 ms 23812 KB Output is correct
17 Correct 13 ms 23764 KB Output is correct
18 Correct 13 ms 23868 KB Output is correct
19 Correct 13 ms 23764 KB Output is correct
20 Correct 14 ms 23876 KB Output is correct
21 Correct 14 ms 23772 KB Output is correct
22 Correct 14 ms 23764 KB Output is correct
23 Correct 14 ms 23764 KB Output is correct
24 Correct 14 ms 23764 KB Output is correct
25 Correct 14 ms 23764 KB Output is correct
26 Correct 15 ms 23872 KB Output is correct
27 Correct 15 ms 23868 KB Output is correct
28 Correct 14 ms 23764 KB Output is correct
29 Correct 128 ms 34260 KB Output is correct
30 Correct 133 ms 37180 KB Output is correct
31 Correct 164 ms 37048 KB Output is correct
32 Correct 144 ms 35912 KB Output is correct
33 Correct 133 ms 35832 KB Output is correct
34 Correct 139 ms 34972 KB Output is correct
35 Correct 161 ms 35952 KB Output is correct
36 Correct 155 ms 37036 KB Output is correct
37 Correct 131 ms 35556 KB Output is correct
38 Correct 148 ms 36616 KB Output is correct
39 Correct 118 ms 34712 KB Output is correct
40 Correct 125 ms 34944 KB Output is correct
41 Correct 174 ms 35904 KB Output is correct
42 Correct 168 ms 37028 KB Output is correct
43 Correct 1356 ms 34772 KB Output is correct
44 Correct 1764 ms 38460 KB Output is correct
45 Correct 1762 ms 38404 KB Output is correct
46 Correct 1601 ms 36516 KB Output is correct
47 Correct 1686 ms 36584 KB Output is correct
48 Correct 1709 ms 36532 KB Output is correct
49 Execution timed out 2085 ms 37688 KB Time limit exceeded
50 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 23812 KB Output is correct
2 Correct 15 ms 23756 KB Output is correct
3 Correct 17 ms 23736 KB Output is correct
4 Correct 17 ms 23852 KB Output is correct
5 Correct 19 ms 23860 KB Output is correct
6 Correct 17 ms 23840 KB Output is correct
7 Correct 17 ms 23772 KB Output is correct
8 Correct 18 ms 23764 KB Output is correct
9 Correct 17 ms 23764 KB Output is correct
10 Correct 20 ms 23876 KB Output is correct
11 Correct 18 ms 23848 KB Output is correct
12 Correct 19 ms 23860 KB Output is correct
13 Correct 20 ms 23864 KB Output is correct
14 Correct 17 ms 23764 KB Output is correct
15 Correct 13 ms 23764 KB Output is correct
16 Correct 14 ms 23812 KB Output is correct
17 Correct 13 ms 23764 KB Output is correct
18 Correct 13 ms 23868 KB Output is correct
19 Correct 13 ms 23764 KB Output is correct
20 Correct 14 ms 23876 KB Output is correct
21 Correct 14 ms 23772 KB Output is correct
22 Correct 14 ms 23764 KB Output is correct
23 Correct 14 ms 23764 KB Output is correct
24 Correct 14 ms 23764 KB Output is correct
25 Correct 14 ms 23764 KB Output is correct
26 Correct 15 ms 23872 KB Output is correct
27 Correct 15 ms 23868 KB Output is correct
28 Correct 14 ms 23764 KB Output is correct
29 Correct 90 ms 23892 KB Output is correct
30 Correct 100 ms 23892 KB Output is correct
31 Correct 115 ms 23984 KB Output is correct
32 Correct 91 ms 23892 KB Output is correct
33 Correct 78 ms 23964 KB Output is correct
34 Correct 107 ms 23988 KB Output is correct
35 Correct 121 ms 23972 KB Output is correct
36 Correct 46 ms 23928 KB Output is correct
37 Correct 91 ms 23860 KB Output is correct
38 Correct 97 ms 23956 KB Output is correct
39 Correct 96 ms 23972 KB Output is correct
40 Correct 87 ms 23988 KB Output is correct
41 Correct 92 ms 23992 KB Output is correct
42 Correct 102 ms 23984 KB Output is correct
43 Correct 87 ms 23892 KB Output is correct
44 Correct 120 ms 23984 KB Output is correct
45 Correct 123 ms 23976 KB Output is correct
46 Correct 121 ms 23976 KB Output is correct
47 Correct 89 ms 23960 KB Output is correct
48 Correct 95 ms 23968 KB Output is correct
49 Correct 102 ms 23972 KB Output is correct
50 Correct 100 ms 23952 KB Output is correct
51 Correct 84 ms 23984 KB Output is correct
52 Correct 97 ms 23976 KB Output is correct
53 Correct 107 ms 23984 KB Output is correct
54 Correct 116 ms 23964 KB Output is correct
55 Runtime error 87 ms 60912 KB Execution killed with signal 11
56 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 23812 KB Output is correct
2 Correct 15 ms 23756 KB Output is correct
3 Correct 17 ms 23736 KB Output is correct
4 Correct 17 ms 23852 KB Output is correct
5 Correct 19 ms 23860 KB Output is correct
6 Correct 17 ms 23840 KB Output is correct
7 Correct 17 ms 23772 KB Output is correct
8 Correct 18 ms 23764 KB Output is correct
9 Correct 17 ms 23764 KB Output is correct
10 Correct 20 ms 23876 KB Output is correct
11 Correct 18 ms 23848 KB Output is correct
12 Correct 19 ms 23860 KB Output is correct
13 Correct 20 ms 23864 KB Output is correct
14 Correct 17 ms 23764 KB Output is correct
15 Correct 13 ms 23764 KB Output is correct
16 Correct 14 ms 23812 KB Output is correct
17 Correct 13 ms 23764 KB Output is correct
18 Correct 13 ms 23868 KB Output is correct
19 Correct 13 ms 23764 KB Output is correct
20 Correct 14 ms 23876 KB Output is correct
21 Correct 14 ms 23772 KB Output is correct
22 Correct 14 ms 23764 KB Output is correct
23 Correct 14 ms 23764 KB Output is correct
24 Correct 14 ms 23764 KB Output is correct
25 Correct 14 ms 23764 KB Output is correct
26 Correct 15 ms 23872 KB Output is correct
27 Correct 15 ms 23868 KB Output is correct
28 Correct 14 ms 23764 KB Output is correct
29 Correct 90 ms 23892 KB Output is correct
30 Correct 100 ms 23892 KB Output is correct
31 Correct 115 ms 23984 KB Output is correct
32 Correct 91 ms 23892 KB Output is correct
33 Correct 78 ms 23964 KB Output is correct
34 Correct 107 ms 23988 KB Output is correct
35 Correct 121 ms 23972 KB Output is correct
36 Correct 46 ms 23928 KB Output is correct
37 Correct 91 ms 23860 KB Output is correct
38 Correct 97 ms 23956 KB Output is correct
39 Correct 96 ms 23972 KB Output is correct
40 Correct 87 ms 23988 KB Output is correct
41 Correct 92 ms 23992 KB Output is correct
42 Correct 102 ms 23984 KB Output is correct
43 Correct 87 ms 23892 KB Output is correct
44 Correct 120 ms 23984 KB Output is correct
45 Correct 123 ms 23976 KB Output is correct
46 Correct 121 ms 23976 KB Output is correct
47 Correct 89 ms 23960 KB Output is correct
48 Correct 95 ms 23968 KB Output is correct
49 Correct 102 ms 23972 KB Output is correct
50 Correct 100 ms 23952 KB Output is correct
51 Correct 84 ms 23984 KB Output is correct
52 Correct 97 ms 23976 KB Output is correct
53 Correct 107 ms 23984 KB Output is correct
54 Correct 116 ms 23964 KB Output is correct
55 Correct 128 ms 34260 KB Output is correct
56 Correct 133 ms 37180 KB Output is correct
57 Correct 164 ms 37048 KB Output is correct
58 Correct 144 ms 35912 KB Output is correct
59 Correct 133 ms 35832 KB Output is correct
60 Correct 139 ms 34972 KB Output is correct
61 Correct 161 ms 35952 KB Output is correct
62 Correct 155 ms 37036 KB Output is correct
63 Correct 131 ms 35556 KB Output is correct
64 Correct 148 ms 36616 KB Output is correct
65 Correct 118 ms 34712 KB Output is correct
66 Correct 125 ms 34944 KB Output is correct
67 Correct 174 ms 35904 KB Output is correct
68 Correct 168 ms 37028 KB Output is correct
69 Correct 1356 ms 34772 KB Output is correct
70 Correct 1764 ms 38460 KB Output is correct
71 Correct 1762 ms 38404 KB Output is correct
72 Correct 1601 ms 36516 KB Output is correct
73 Correct 1686 ms 36584 KB Output is correct
74 Correct 1709 ms 36532 KB Output is correct
75 Execution timed out 2085 ms 37688 KB Time limit exceeded
76 Halted 0 ms 0 KB -