답안 #446718

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
446718 2021-07-23T07:21:33 Z prvocislo Joker (BOI20_joker) C++17
100 / 100
732 ms 13364 KB
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;

const int maxn = 2e5 + 5, maxvr = maxn * 2;
//const int maxn = 10, maxvr = maxn * 2;
int p[maxvr], siz[maxvr], u[maxn], v[maxn], first[maxn], n, m, q;
vector<int> ch;
int root(int a) { return p[a] == a ? a : root(p[a]); }
void merge(int a, int b)
{
    a = root(a), b = root(b);
    if (a == b) return;
    if (siz[a] < siz[b]) swap(a, b);
    siz[a] += siz[b], p[b] = a;
    ch.push_back(b);
}
void undo(int until)
{
    while (ch.size() > until)
    {
        siz[p[ch.back()]] -= siz[ch.back()];
        p[ch.back()] = ch.back();
        ch.pop_back();
    }
}
bool add(int i)
{
    merge(u[i], v[i]+n), merge(u[i]+n, v[i]);
    return root(v[i]) == root(v[i]+n) || root(u[i]) == root(u[i]+n);
}
void divide_and_conquer(int l1, int l2, int r1, int r2, bool odd) // v dsu mame hrany [0,...,l1-1], [r2,...,m+1]
{
    if (l1 > l2) return;
    int mid = (l1 + l2) >> 1, siz = ch.size();
    bool odd2 = odd;
    for (int i = l1; i < mid; i++) odd2 |= add(i);
    if (odd2) first[mid] = r2;
    else for (int i = r2-1; i >= -1; i--)
    {
        if (i >= 0) odd2 |= add(i);
        if (i != -1 && odd2)
        {
            first[mid] = i;
            break;
        }
    }
    undo(siz);
    odd2 = odd;
    for (int i = r2-1; i >= first[mid]; i--) odd2 |= add(i);
    divide_and_conquer(l1, mid-1, r1, first[mid], odd2);
    undo(siz);
    odd2 = odd;
    for (int i = l1; i <= mid; i++) odd2 |= add(i);
    divide_and_conquer(mid+1, l2, first[mid], r2, odd2);
    undo(siz);
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> m >> q;
    for (int i = 0; i < 2*n; i++) p[i] = i, siz[i] = 1;
    for (int i = 0; i < m; i++) cin >> u[i] >> v[i], u[i]--, v[i]--;
    divide_and_conquer(0, m-1, 0, m, false);
    while (q--)
    {
        int l, r;
        cin >> l >> r; l--, r--;
        if (first[l] > r) cout << "YES\n"; // first[l] - ak mame tuto hranu a prvych l-1 a tie za nou tak mame odd cyclus
        else cout << "NO\n";
    }
    return 0;
}

Compilation message

Joker.cpp: In function 'void undo(int)':
Joker.cpp:20:22: warning: comparison of integer expressions of different signedness: 'std::vector<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   20 |     while (ch.size() > until)
      |            ~~~~~~~~~~^~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 320 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 320 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 320 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 320 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 2 ms 332 KB Output is correct
30 Correct 3 ms 456 KB Output is correct
31 Correct 3 ms 460 KB Output is correct
32 Correct 3 ms 332 KB Output is correct
33 Correct 3 ms 332 KB Output is correct
34 Correct 3 ms 460 KB Output is correct
35 Correct 4 ms 460 KB Output is correct
36 Correct 2 ms 332 KB Output is correct
37 Correct 4 ms 460 KB Output is correct
38 Correct 3 ms 460 KB Output is correct
39 Correct 3 ms 460 KB Output is correct
40 Correct 3 ms 332 KB Output is correct
41 Correct 3 ms 332 KB Output is correct
42 Correct 3 ms 332 KB Output is correct
43 Correct 3 ms 332 KB Output is correct
44 Correct 3 ms 332 KB Output is correct
45 Correct 3 ms 460 KB Output is correct
46 Correct 4 ms 460 KB Output is correct
47 Correct 3 ms 332 KB Output is correct
48 Correct 3 ms 332 KB Output is correct
49 Correct 3 ms 460 KB Output is correct
50 Correct 3 ms 460 KB Output is correct
51 Correct 4 ms 332 KB Output is correct
52 Correct 3 ms 332 KB Output is correct
53 Correct 3 ms 460 KB Output is correct
54 Correct 4 ms 460 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 387 ms 9792 KB Output is correct
4 Correct 507 ms 10804 KB Output is correct
5 Correct 381 ms 11828 KB Output is correct
6 Correct 413 ms 9792 KB Output is correct
7 Correct 435 ms 9692 KB Output is correct
8 Correct 447 ms 8292 KB Output is correct
9 Correct 519 ms 9280 KB Output is correct
10 Correct 688 ms 11636 KB Output is correct
11 Correct 435 ms 9752 KB Output is correct
12 Correct 546 ms 11700 KB Output is correct
13 Correct 380 ms 7828 KB Output is correct
14 Correct 460 ms 8896 KB Output is correct
15 Correct 681 ms 10680 KB Output is correct
16 Correct 701 ms 11924 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 320 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 320 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 387 ms 9792 KB Output is correct
30 Correct 507 ms 10804 KB Output is correct
31 Correct 381 ms 11828 KB Output is correct
32 Correct 413 ms 9792 KB Output is correct
33 Correct 435 ms 9692 KB Output is correct
34 Correct 447 ms 8292 KB Output is correct
35 Correct 519 ms 9280 KB Output is correct
36 Correct 688 ms 11636 KB Output is correct
37 Correct 435 ms 9752 KB Output is correct
38 Correct 546 ms 11700 KB Output is correct
39 Correct 380 ms 7828 KB Output is correct
40 Correct 460 ms 8896 KB Output is correct
41 Correct 681 ms 10680 KB Output is correct
42 Correct 701 ms 11924 KB Output is correct
43 Correct 390 ms 10104 KB Output is correct
44 Correct 502 ms 11424 KB Output is correct
45 Correct 579 ms 12444 KB Output is correct
46 Correct 403 ms 10120 KB Output is correct
47 Correct 428 ms 10040 KB Output is correct
48 Correct 574 ms 9792 KB Output is correct
49 Correct 705 ms 11952 KB Output is correct
50 Correct 409 ms 9564 KB Output is correct
51 Correct 516 ms 11052 KB Output is correct
52 Correct 577 ms 12248 KB Output is correct
53 Correct 376 ms 8032 KB Output is correct
54 Correct 529 ms 9604 KB Output is correct
55 Correct 650 ms 11080 KB Output is correct
56 Correct 730 ms 12192 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 320 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 320 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 2 ms 332 KB Output is correct
30 Correct 3 ms 456 KB Output is correct
31 Correct 3 ms 460 KB Output is correct
32 Correct 3 ms 332 KB Output is correct
33 Correct 3 ms 332 KB Output is correct
34 Correct 3 ms 460 KB Output is correct
35 Correct 4 ms 460 KB Output is correct
36 Correct 2 ms 332 KB Output is correct
37 Correct 4 ms 460 KB Output is correct
38 Correct 3 ms 460 KB Output is correct
39 Correct 3 ms 460 KB Output is correct
40 Correct 3 ms 332 KB Output is correct
41 Correct 3 ms 332 KB Output is correct
42 Correct 3 ms 332 KB Output is correct
43 Correct 3 ms 332 KB Output is correct
44 Correct 3 ms 332 KB Output is correct
45 Correct 3 ms 460 KB Output is correct
46 Correct 4 ms 460 KB Output is correct
47 Correct 3 ms 332 KB Output is correct
48 Correct 3 ms 332 KB Output is correct
49 Correct 3 ms 460 KB Output is correct
50 Correct 3 ms 460 KB Output is correct
51 Correct 4 ms 332 KB Output is correct
52 Correct 3 ms 332 KB Output is correct
53 Correct 3 ms 460 KB Output is correct
54 Correct 4 ms 460 KB Output is correct
55 Correct 341 ms 7500 KB Output is correct
56 Correct 451 ms 9724 KB Output is correct
57 Correct 321 ms 9692 KB Output is correct
58 Correct 391 ms 7384 KB Output is correct
59 Correct 542 ms 7364 KB Output is correct
60 Correct 652 ms 9740 KB Output is correct
61 Correct 449 ms 7404 KB Output is correct
62 Correct 544 ms 9732 KB Output is correct
63 Correct 362 ms 6004 KB Output is correct
64 Correct 574 ms 8144 KB Output is correct
65 Correct 670 ms 9892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 316 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 332 KB Output is correct
19 Correct 1 ms 320 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 1 ms 332 KB Output is correct
22 Correct 1 ms 332 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 332 KB Output is correct
25 Correct 1 ms 332 KB Output is correct
26 Correct 1 ms 320 KB Output is correct
27 Correct 1 ms 332 KB Output is correct
28 Correct 1 ms 332 KB Output is correct
29 Correct 2 ms 332 KB Output is correct
30 Correct 3 ms 456 KB Output is correct
31 Correct 3 ms 460 KB Output is correct
32 Correct 3 ms 332 KB Output is correct
33 Correct 3 ms 332 KB Output is correct
34 Correct 3 ms 460 KB Output is correct
35 Correct 4 ms 460 KB Output is correct
36 Correct 2 ms 332 KB Output is correct
37 Correct 4 ms 460 KB Output is correct
38 Correct 3 ms 460 KB Output is correct
39 Correct 3 ms 460 KB Output is correct
40 Correct 3 ms 332 KB Output is correct
41 Correct 3 ms 332 KB Output is correct
42 Correct 3 ms 332 KB Output is correct
43 Correct 3 ms 332 KB Output is correct
44 Correct 3 ms 332 KB Output is correct
45 Correct 3 ms 460 KB Output is correct
46 Correct 4 ms 460 KB Output is correct
47 Correct 3 ms 332 KB Output is correct
48 Correct 3 ms 332 KB Output is correct
49 Correct 3 ms 460 KB Output is correct
50 Correct 3 ms 460 KB Output is correct
51 Correct 4 ms 332 KB Output is correct
52 Correct 3 ms 332 KB Output is correct
53 Correct 3 ms 460 KB Output is correct
54 Correct 4 ms 460 KB Output is correct
55 Correct 387 ms 9792 KB Output is correct
56 Correct 507 ms 10804 KB Output is correct
57 Correct 381 ms 11828 KB Output is correct
58 Correct 413 ms 9792 KB Output is correct
59 Correct 435 ms 9692 KB Output is correct
60 Correct 447 ms 8292 KB Output is correct
61 Correct 519 ms 9280 KB Output is correct
62 Correct 688 ms 11636 KB Output is correct
63 Correct 435 ms 9752 KB Output is correct
64 Correct 546 ms 11700 KB Output is correct
65 Correct 380 ms 7828 KB Output is correct
66 Correct 460 ms 8896 KB Output is correct
67 Correct 681 ms 10680 KB Output is correct
68 Correct 701 ms 11924 KB Output is correct
69 Correct 390 ms 10104 KB Output is correct
70 Correct 502 ms 11424 KB Output is correct
71 Correct 579 ms 12444 KB Output is correct
72 Correct 403 ms 10120 KB Output is correct
73 Correct 428 ms 10040 KB Output is correct
74 Correct 574 ms 9792 KB Output is correct
75 Correct 705 ms 11952 KB Output is correct
76 Correct 409 ms 9564 KB Output is correct
77 Correct 516 ms 11052 KB Output is correct
78 Correct 577 ms 12248 KB Output is correct
79 Correct 376 ms 8032 KB Output is correct
80 Correct 529 ms 9604 KB Output is correct
81 Correct 650 ms 11080 KB Output is correct
82 Correct 730 ms 12192 KB Output is correct
83 Correct 341 ms 7500 KB Output is correct
84 Correct 451 ms 9724 KB Output is correct
85 Correct 321 ms 9692 KB Output is correct
86 Correct 391 ms 7384 KB Output is correct
87 Correct 542 ms 7364 KB Output is correct
88 Correct 652 ms 9740 KB Output is correct
89 Correct 449 ms 7404 KB Output is correct
90 Correct 544 ms 9732 KB Output is correct
91 Correct 362 ms 6004 KB Output is correct
92 Correct 574 ms 8144 KB Output is correct
93 Correct 670 ms 9892 KB Output is correct
94 Correct 398 ms 10780 KB Output is correct
95 Correct 550 ms 13112 KB Output is correct
96 Correct 390 ms 12840 KB Output is correct
97 Correct 426 ms 10816 KB Output is correct
98 Correct 465 ms 10864 KB Output is correct
99 Correct 485 ms 9720 KB Output is correct
100 Correct 641 ms 13060 KB Output is correct
101 Correct 413 ms 10284 KB Output is correct
102 Correct 537 ms 11984 KB Output is correct
103 Correct 654 ms 13008 KB Output is correct
104 Correct 440 ms 9320 KB Output is correct
105 Correct 619 ms 11336 KB Output is correct
106 Correct 732 ms 12856 KB Output is correct
107 Correct 274 ms 13364 KB Output is correct
108 Correct 396 ms 10532 KB Output is correct
109 Correct 387 ms 10564 KB Output is correct
110 Correct 401 ms 10604 KB Output is correct
111 Correct 390 ms 10616 KB Output is correct
112 Correct 393 ms 10636 KB Output is correct
113 Correct 404 ms 10556 KB Output is correct
114 Correct 391 ms 10476 KB Output is correct
115 Correct 389 ms 10640 KB Output is correct
116 Correct 395 ms 10696 KB Output is correct