답안 #529280

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
529280 2022-02-22T15:57:09 Z Saacoota Joker (BOI20_joker) C++14
100 / 100
198 ms 13800 KB
#include <bits/stdc++.h>
#define fi first
#define se second
#define ii pair < int , int >

using namespace std;

const int maxn = 3e5 + 10;

struct node {
    int u , v , pu , pv;
    node(){}
    node(int u,int pu,int v,int pv):
    u(u) , v(v) , pu(pu) , pv(pv){}
};
vector < node > indsu;
int par[maxn] , c[maxn] , last[maxn] , u[maxn] , v[maxn] , n , m , q;

ii fin(int u) {
    int color = 0;
    while (par[u] > 0) {
        color ^= c[u];
        u = par[u];
    }
    return ii(u , color);
}

bool push(int u,int v) {
    ii x = fin(u);
    ii y = fin(v);
    if (x.fi == y.fi) return (x.se != y.se);
    indsu.emplace_back(x.fi , par[x.fi] , y.fi , par[y.fi]);
    if (par[x.fi] > par[y.fi]) swap(x , y);
    par[x.fi] += par[y.fi];
    par[y.fi] = x.fi;
    c[y.fi] = x.se ^ y.se ^ 1;
    return true;
}

void roll(int stp) {
    while (indsu.size() > stp) {
        node x = indsu.back();
        indsu.pop_back();
        par[x.u] = x.pu;
        par[x.v] = x.pv;
    }
}

void cal(int l,int r,int optl,int optr) {
    if (l > r || optl > optr) return;
    int mid = l + r >> 1;
    int cur = indsu.size();
    bool ok = true;
    for (int i = l ; i < mid ; ++i)
    ok &= push(u[i] , v[i]);
    if (ok) {
        int crr = indsu.size();
        last[mid] = optl;
        for (int i = min(optr , m) ; i >= max(optl , mid) ; --i) {
            if (!push(u[i] , v[i])) {
                last[mid] = i;
                break;
            }
        }
        roll(crr);
        if (push(u[mid] , v[mid])) cal(mid + 1 , r , last[mid] , optr);
    }
    roll(cur);
    for (int i = last[mid] + 1 ; i <= optr ; ++i) push(u[i] , v[i]);
    cal(l , mid - 1 , optl , last[mid]);
    roll(cur);
}

int main() {
//    freopen("nohome.inp","r",stdin);
//    freopen("nohome.out","w",stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m >> q;
    for (int i = 1 ; i <= m ; ++i) {
        cin >> u[i] >> v[i];
        last[i] = m + 1;
    }
    memset(par,-1,sizeof(par));
    cal(1 , m , 1 , m + 1);
    while (q--) {
        int l , r;
        cin >> l >> r;
        if (r >= last[l]) cout << "NO\n";
        else cout << "YES\n";
    }
}

Compilation message

Joker.cpp: In function 'void roll(int)':
Joker.cpp:41:25: warning: comparison of integer expressions of different signedness: 'std::vector<node>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   41 |     while (indsu.size() > stp) {
      |            ~~~~~~~~~~~~~^~~~~
Joker.cpp: In function 'void cal(int, int, int, int)':
Joker.cpp:51:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   51 |     int mid = l + r >> 1;
      |               ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1484 KB Output is correct
2 Correct 1 ms 1484 KB Output is correct
3 Correct 1 ms 1484 KB Output is correct
4 Correct 1 ms 1484 KB Output is correct
5 Correct 1 ms 1484 KB Output is correct
6 Correct 1 ms 1484 KB Output is correct
7 Correct 1 ms 1484 KB Output is correct
8 Correct 1 ms 1484 KB Output is correct
9 Correct 1 ms 1484 KB Output is correct
10 Correct 1 ms 1484 KB Output is correct
11 Correct 1 ms 1484 KB Output is correct
12 Correct 1 ms 1484 KB Output is correct
13 Correct 1 ms 1484 KB Output is correct
14 Correct 1 ms 1484 KB Output is correct
15 Correct 1 ms 1484 KB Output is correct
16 Correct 1 ms 1468 KB Output is correct
17 Correct 1 ms 1524 KB Output is correct
18 Correct 1 ms 1484 KB Output is correct
19 Correct 1 ms 1484 KB Output is correct
20 Correct 1 ms 1472 KB Output is correct
21 Correct 2 ms 1484 KB Output is correct
22 Correct 1 ms 1484 KB Output is correct
23 Correct 1 ms 1484 KB Output is correct
24 Correct 1 ms 1484 KB Output is correct
25 Correct 1 ms 1484 KB Output is correct
26 Correct 1 ms 1484 KB Output is correct
27 Correct 1 ms 1484 KB Output is correct
28 Correct 1 ms 1484 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1484 KB Output is correct
2 Correct 1 ms 1484 KB Output is correct
3 Correct 1 ms 1484 KB Output is correct
4 Correct 1 ms 1484 KB Output is correct
5 Correct 1 ms 1484 KB Output is correct
6 Correct 1 ms 1484 KB Output is correct
7 Correct 1 ms 1484 KB Output is correct
8 Correct 1 ms 1484 KB Output is correct
9 Correct 1 ms 1484 KB Output is correct
10 Correct 1 ms 1484 KB Output is correct
11 Correct 1 ms 1484 KB Output is correct
12 Correct 1 ms 1484 KB Output is correct
13 Correct 1 ms 1484 KB Output is correct
14 Correct 1 ms 1484 KB Output is correct
15 Correct 1 ms 1484 KB Output is correct
16 Correct 1 ms 1468 KB Output is correct
17 Correct 1 ms 1524 KB Output is correct
18 Correct 1 ms 1484 KB Output is correct
19 Correct 1 ms 1484 KB Output is correct
20 Correct 1 ms 1472 KB Output is correct
21 Correct 2 ms 1484 KB Output is correct
22 Correct 1 ms 1484 KB Output is correct
23 Correct 1 ms 1484 KB Output is correct
24 Correct 1 ms 1484 KB Output is correct
25 Correct 1 ms 1484 KB Output is correct
26 Correct 1 ms 1484 KB Output is correct
27 Correct 1 ms 1484 KB Output is correct
28 Correct 1 ms 1484 KB Output is correct
29 Correct 2 ms 1464 KB Output is correct
30 Correct 2 ms 1608 KB Output is correct
31 Correct 2 ms 1612 KB Output is correct
32 Correct 3 ms 1612 KB Output is correct
33 Correct 2 ms 1484 KB Output is correct
34 Correct 2 ms 1536 KB Output is correct
35 Correct 3 ms 1612 KB Output is correct
36 Correct 2 ms 1604 KB Output is correct
37 Correct 2 ms 1652 KB Output is correct
38 Correct 2 ms 1612 KB Output is correct
39 Correct 2 ms 1612 KB Output is correct
40 Correct 2 ms 1532 KB Output is correct
41 Correct 2 ms 1540 KB Output is correct
42 Correct 2 ms 1608 KB Output is correct
43 Correct 2 ms 1612 KB Output is correct
44 Correct 2 ms 1612 KB Output is correct
45 Correct 2 ms 1608 KB Output is correct
46 Correct 2 ms 1612 KB Output is correct
47 Correct 2 ms 1612 KB Output is correct
48 Correct 3 ms 1608 KB Output is correct
49 Correct 2 ms 1612 KB Output is correct
50 Correct 2 ms 1612 KB Output is correct
51 Correct 2 ms 1508 KB Output is correct
52 Correct 2 ms 1612 KB Output is correct
53 Correct 2 ms 1612 KB Output is correct
54 Correct 2 ms 1612 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1484 KB Output is correct
2 Correct 1 ms 1484 KB Output is correct
3 Correct 111 ms 6512 KB Output is correct
4 Correct 154 ms 8760 KB Output is correct
5 Correct 100 ms 8676 KB Output is correct
6 Correct 98 ms 6496 KB Output is correct
7 Correct 98 ms 6516 KB Output is correct
8 Correct 129 ms 5868 KB Output is correct
9 Correct 131 ms 6608 KB Output is correct
10 Correct 146 ms 8764 KB Output is correct
11 Correct 119 ms 6456 KB Output is correct
12 Correct 135 ms 8764 KB Output is correct
13 Correct 115 ms 4920 KB Output is correct
14 Correct 112 ms 5688 KB Output is correct
15 Correct 151 ms 6928 KB Output is correct
16 Correct 162 ms 8764 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1484 KB Output is correct
2 Correct 1 ms 1484 KB Output is correct
3 Correct 1 ms 1484 KB Output is correct
4 Correct 1 ms 1484 KB Output is correct
5 Correct 1 ms 1484 KB Output is correct
6 Correct 1 ms 1484 KB Output is correct
7 Correct 1 ms 1484 KB Output is correct
8 Correct 1 ms 1484 KB Output is correct
9 Correct 1 ms 1484 KB Output is correct
10 Correct 1 ms 1484 KB Output is correct
11 Correct 1 ms 1484 KB Output is correct
12 Correct 1 ms 1484 KB Output is correct
13 Correct 1 ms 1484 KB Output is correct
14 Correct 1 ms 1484 KB Output is correct
15 Correct 1 ms 1484 KB Output is correct
16 Correct 1 ms 1468 KB Output is correct
17 Correct 1 ms 1524 KB Output is correct
18 Correct 1 ms 1484 KB Output is correct
19 Correct 1 ms 1484 KB Output is correct
20 Correct 1 ms 1472 KB Output is correct
21 Correct 2 ms 1484 KB Output is correct
22 Correct 1 ms 1484 KB Output is correct
23 Correct 1 ms 1484 KB Output is correct
24 Correct 1 ms 1484 KB Output is correct
25 Correct 1 ms 1484 KB Output is correct
26 Correct 1 ms 1484 KB Output is correct
27 Correct 1 ms 1484 KB Output is correct
28 Correct 1 ms 1484 KB Output is correct
29 Correct 111 ms 6512 KB Output is correct
30 Correct 154 ms 8760 KB Output is correct
31 Correct 100 ms 8676 KB Output is correct
32 Correct 98 ms 6496 KB Output is correct
33 Correct 98 ms 6516 KB Output is correct
34 Correct 129 ms 5868 KB Output is correct
35 Correct 131 ms 6608 KB Output is correct
36 Correct 146 ms 8764 KB Output is correct
37 Correct 119 ms 6456 KB Output is correct
38 Correct 135 ms 8764 KB Output is correct
39 Correct 115 ms 4920 KB Output is correct
40 Correct 112 ms 5688 KB Output is correct
41 Correct 151 ms 6928 KB Output is correct
42 Correct 162 ms 8764 KB Output is correct
43 Correct 119 ms 10840 KB Output is correct
44 Correct 139 ms 12444 KB Output is correct
45 Correct 158 ms 12828 KB Output is correct
46 Correct 95 ms 10824 KB Output is correct
47 Correct 109 ms 10852 KB Output is correct
48 Correct 169 ms 10388 KB Output is correct
49 Correct 198 ms 11796 KB Output is correct
50 Correct 126 ms 10344 KB Output is correct
51 Correct 132 ms 11452 KB Output is correct
52 Correct 153 ms 11852 KB Output is correct
53 Correct 124 ms 9152 KB Output is correct
54 Correct 138 ms 10428 KB Output is correct
55 Correct 194 ms 11508 KB Output is correct
56 Correct 172 ms 11980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1484 KB Output is correct
2 Correct 1 ms 1484 KB Output is correct
3 Correct 1 ms 1484 KB Output is correct
4 Correct 1 ms 1484 KB Output is correct
5 Correct 1 ms 1484 KB Output is correct
6 Correct 1 ms 1484 KB Output is correct
7 Correct 1 ms 1484 KB Output is correct
8 Correct 1 ms 1484 KB Output is correct
9 Correct 1 ms 1484 KB Output is correct
10 Correct 1 ms 1484 KB Output is correct
11 Correct 1 ms 1484 KB Output is correct
12 Correct 1 ms 1484 KB Output is correct
13 Correct 1 ms 1484 KB Output is correct
14 Correct 1 ms 1484 KB Output is correct
15 Correct 1 ms 1484 KB Output is correct
16 Correct 1 ms 1468 KB Output is correct
17 Correct 1 ms 1524 KB Output is correct
18 Correct 1 ms 1484 KB Output is correct
19 Correct 1 ms 1484 KB Output is correct
20 Correct 1 ms 1472 KB Output is correct
21 Correct 2 ms 1484 KB Output is correct
22 Correct 1 ms 1484 KB Output is correct
23 Correct 1 ms 1484 KB Output is correct
24 Correct 1 ms 1484 KB Output is correct
25 Correct 1 ms 1484 KB Output is correct
26 Correct 1 ms 1484 KB Output is correct
27 Correct 1 ms 1484 KB Output is correct
28 Correct 1 ms 1484 KB Output is correct
29 Correct 2 ms 1464 KB Output is correct
30 Correct 2 ms 1608 KB Output is correct
31 Correct 2 ms 1612 KB Output is correct
32 Correct 3 ms 1612 KB Output is correct
33 Correct 2 ms 1484 KB Output is correct
34 Correct 2 ms 1536 KB Output is correct
35 Correct 3 ms 1612 KB Output is correct
36 Correct 2 ms 1604 KB Output is correct
37 Correct 2 ms 1652 KB Output is correct
38 Correct 2 ms 1612 KB Output is correct
39 Correct 2 ms 1612 KB Output is correct
40 Correct 2 ms 1532 KB Output is correct
41 Correct 2 ms 1540 KB Output is correct
42 Correct 2 ms 1608 KB Output is correct
43 Correct 2 ms 1612 KB Output is correct
44 Correct 2 ms 1612 KB Output is correct
45 Correct 2 ms 1608 KB Output is correct
46 Correct 2 ms 1612 KB Output is correct
47 Correct 2 ms 1612 KB Output is correct
48 Correct 3 ms 1608 KB Output is correct
49 Correct 2 ms 1612 KB Output is correct
50 Correct 2 ms 1612 KB Output is correct
51 Correct 2 ms 1508 KB Output is correct
52 Correct 2 ms 1612 KB Output is correct
53 Correct 2 ms 1612 KB Output is correct
54 Correct 2 ms 1612 KB Output is correct
55 Correct 83 ms 8728 KB Output is correct
56 Correct 84 ms 11324 KB Output is correct
57 Correct 73 ms 11240 KB Output is correct
58 Correct 71 ms 8640 KB Output is correct
59 Correct 101 ms 8736 KB Output is correct
60 Correct 133 ms 9152 KB Output is correct
61 Correct 107 ms 8664 KB Output is correct
62 Correct 108 ms 11192 KB Output is correct
63 Correct 83 ms 7364 KB Output is correct
64 Correct 109 ms 8824 KB Output is correct
65 Correct 127 ms 11324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 1484 KB Output is correct
2 Correct 1 ms 1484 KB Output is correct
3 Correct 1 ms 1484 KB Output is correct
4 Correct 1 ms 1484 KB Output is correct
5 Correct 1 ms 1484 KB Output is correct
6 Correct 1 ms 1484 KB Output is correct
7 Correct 1 ms 1484 KB Output is correct
8 Correct 1 ms 1484 KB Output is correct
9 Correct 1 ms 1484 KB Output is correct
10 Correct 1 ms 1484 KB Output is correct
11 Correct 1 ms 1484 KB Output is correct
12 Correct 1 ms 1484 KB Output is correct
13 Correct 1 ms 1484 KB Output is correct
14 Correct 1 ms 1484 KB Output is correct
15 Correct 1 ms 1484 KB Output is correct
16 Correct 1 ms 1468 KB Output is correct
17 Correct 1 ms 1524 KB Output is correct
18 Correct 1 ms 1484 KB Output is correct
19 Correct 1 ms 1484 KB Output is correct
20 Correct 1 ms 1472 KB Output is correct
21 Correct 2 ms 1484 KB Output is correct
22 Correct 1 ms 1484 KB Output is correct
23 Correct 1 ms 1484 KB Output is correct
24 Correct 1 ms 1484 KB Output is correct
25 Correct 1 ms 1484 KB Output is correct
26 Correct 1 ms 1484 KB Output is correct
27 Correct 1 ms 1484 KB Output is correct
28 Correct 1 ms 1484 KB Output is correct
29 Correct 2 ms 1464 KB Output is correct
30 Correct 2 ms 1608 KB Output is correct
31 Correct 2 ms 1612 KB Output is correct
32 Correct 3 ms 1612 KB Output is correct
33 Correct 2 ms 1484 KB Output is correct
34 Correct 2 ms 1536 KB Output is correct
35 Correct 3 ms 1612 KB Output is correct
36 Correct 2 ms 1604 KB Output is correct
37 Correct 2 ms 1652 KB Output is correct
38 Correct 2 ms 1612 KB Output is correct
39 Correct 2 ms 1612 KB Output is correct
40 Correct 2 ms 1532 KB Output is correct
41 Correct 2 ms 1540 KB Output is correct
42 Correct 2 ms 1608 KB Output is correct
43 Correct 2 ms 1612 KB Output is correct
44 Correct 2 ms 1612 KB Output is correct
45 Correct 2 ms 1608 KB Output is correct
46 Correct 2 ms 1612 KB Output is correct
47 Correct 2 ms 1612 KB Output is correct
48 Correct 3 ms 1608 KB Output is correct
49 Correct 2 ms 1612 KB Output is correct
50 Correct 2 ms 1612 KB Output is correct
51 Correct 2 ms 1508 KB Output is correct
52 Correct 2 ms 1612 KB Output is correct
53 Correct 2 ms 1612 KB Output is correct
54 Correct 2 ms 1612 KB Output is correct
55 Correct 111 ms 6512 KB Output is correct
56 Correct 154 ms 8760 KB Output is correct
57 Correct 100 ms 8676 KB Output is correct
58 Correct 98 ms 6496 KB Output is correct
59 Correct 98 ms 6516 KB Output is correct
60 Correct 129 ms 5868 KB Output is correct
61 Correct 131 ms 6608 KB Output is correct
62 Correct 146 ms 8764 KB Output is correct
63 Correct 119 ms 6456 KB Output is correct
64 Correct 135 ms 8764 KB Output is correct
65 Correct 115 ms 4920 KB Output is correct
66 Correct 112 ms 5688 KB Output is correct
67 Correct 151 ms 6928 KB Output is correct
68 Correct 162 ms 8764 KB Output is correct
69 Correct 119 ms 10840 KB Output is correct
70 Correct 139 ms 12444 KB Output is correct
71 Correct 158 ms 12828 KB Output is correct
72 Correct 95 ms 10824 KB Output is correct
73 Correct 109 ms 10852 KB Output is correct
74 Correct 169 ms 10388 KB Output is correct
75 Correct 198 ms 11796 KB Output is correct
76 Correct 126 ms 10344 KB Output is correct
77 Correct 132 ms 11452 KB Output is correct
78 Correct 153 ms 11852 KB Output is correct
79 Correct 124 ms 9152 KB Output is correct
80 Correct 138 ms 10428 KB Output is correct
81 Correct 194 ms 11508 KB Output is correct
82 Correct 172 ms 11980 KB Output is correct
83 Correct 83 ms 8728 KB Output is correct
84 Correct 84 ms 11324 KB Output is correct
85 Correct 73 ms 11240 KB Output is correct
86 Correct 71 ms 8640 KB Output is correct
87 Correct 101 ms 8736 KB Output is correct
88 Correct 133 ms 9152 KB Output is correct
89 Correct 107 ms 8664 KB Output is correct
90 Correct 108 ms 11192 KB Output is correct
91 Correct 83 ms 7364 KB Output is correct
92 Correct 109 ms 8824 KB Output is correct
93 Correct 127 ms 11324 KB Output is correct
94 Correct 137 ms 11536 KB Output is correct
95 Correct 153 ms 13520 KB Output is correct
96 Correct 114 ms 13192 KB Output is correct
97 Correct 109 ms 11596 KB Output is correct
98 Correct 114 ms 11572 KB Output is correct
99 Correct 132 ms 10744 KB Output is correct
100 Correct 149 ms 12752 KB Output is correct
101 Correct 130 ms 11064 KB Output is correct
102 Correct 142 ms 12136 KB Output is correct
103 Correct 165 ms 12720 KB Output is correct
104 Correct 132 ms 10328 KB Output is correct
105 Correct 150 ms 11848 KB Output is correct
106 Correct 175 ms 12572 KB Output is correct
107 Correct 119 ms 13800 KB Output is correct
108 Correct 129 ms 11288 KB Output is correct
109 Correct 120 ms 11324 KB Output is correct
110 Correct 125 ms 11440 KB Output is correct
111 Correct 125 ms 11296 KB Output is correct
112 Correct 120 ms 11336 KB Output is correct
113 Correct 125 ms 11276 KB Output is correct
114 Correct 118 ms 11324 KB Output is correct
115 Correct 132 ms 11292 KB Output is correct
116 Correct 116 ms 11260 KB Output is correct