Submission #1050417

# Submission time Handle Problem Language Result Execution time Memory
1050417 2024-08-09T09:16:32 Z duckindog Joker (BOI20_joker) C++17
39 / 100
168 ms 18000 KB
#include <bits/stdc++.h>

using namespace std;

const int N = 200'000 + 10;
int n, m, q;
vector<pair<int, int>> ad[N];
int co[N];

int32_t main() { 
  cin.tie(0)->sync_with_stdio(0);

  cin >> n >> m >> q;
  for (int i = 1; i <= m; ++i) { 
    int u, v; cin >> u >> v;
    ad[u].push_back({v, i});
    ad[v].push_back({u, i});
  }

  auto color = [&](int st, int l, int r) { 
    bool ret = false;
    co[st] = 1;
    queue<int> q({st});
    while (q.size()) { 
      auto u = q.front(); q.pop();
      for (const auto& [v, id] : ad[u]) { 
        if (l <= id && id <= r) continue;
        if (co[v] == co[u]) return true;
        if (co[v]) continue;
        co[v] = co[u] ^ 3;
        q.push(v);
      }
    }
    return false;
  };
  auto cal = [&](int l, int r) { 
    memset(co, 0, (n + 1) * sizeof(int));
    for (int i = 1; i <= n; ++i) if (!co[i] && color(i, l, r)) return true;
    return false; 
  };

  if (n <= 2000 && q <= 2000) { 
    while (q--) { 
      int l, r; cin >> l >> r;
      cout << (cal(l, r) ? "YES" : "NO") << "\n";
    }
    return 0;
  }

  int l = 1, r = m, ma = -1;
  while (l <= r) { 
    int mid = l + r >> 1;
    if (cal(1, mid)) l = (ma = mid) + 1;
    else r = mid - 1;
  }
  
  while (q--) { 
    int l, r; cin >> l >> r;
    cout << (r <= ma ? "YES" : "NO") << "\n";
  }
}

Compilation message

Joker.cpp: In lambda function:
Joker.cpp:21:10: warning: unused variable 'ret' [-Wunused-variable]
   21 |     bool ret = false;
      |          ^~~
Joker.cpp: In function 'int32_t main()':
Joker.cpp:52:17: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   52 |     int mid = l + r >> 1;
      |               ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 5724 KB Output is correct
2 Correct 1 ms 5556 KB Output is correct
3 Correct 1 ms 5720 KB Output is correct
4 Correct 1 ms 5724 KB Output is correct
5 Correct 1 ms 5724 KB Output is correct
6 Correct 2 ms 5720 KB Output is correct
7 Correct 3 ms 5724 KB Output is correct
8 Correct 2 ms 5724 KB Output is correct
9 Correct 1 ms 5724 KB Output is correct
10 Correct 2 ms 5724 KB Output is correct
11 Correct 3 ms 5724 KB Output is correct
12 Correct 2 ms 5724 KB Output is correct
13 Correct 1 ms 5724 KB Output is correct
14 Correct 2 ms 5724 KB Output is correct
15 Correct 2 ms 5724 KB Output is correct
16 Correct 2 ms 5724 KB Output is correct
17 Correct 2 ms 5540 KB Output is correct
18 Correct 2 ms 5724 KB Output is correct
19 Correct 1 ms 5724 KB Output is correct
20 Correct 1 ms 5724 KB Output is correct
21 Correct 2 ms 5724 KB Output is correct
22 Correct 1 ms 5724 KB Output is correct
23 Correct 2 ms 5724 KB Output is correct
24 Correct 1 ms 5724 KB Output is correct
25 Correct 2 ms 5724 KB Output is correct
26 Correct 1 ms 5724 KB Output is correct
27 Correct 2 ms 5724 KB Output is correct
28 Correct 2 ms 5724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 5724 KB Output is correct
2 Correct 1 ms 5556 KB Output is correct
3 Correct 1 ms 5720 KB Output is correct
4 Correct 1 ms 5724 KB Output is correct
5 Correct 1 ms 5724 KB Output is correct
6 Correct 2 ms 5720 KB Output is correct
7 Correct 3 ms 5724 KB Output is correct
8 Correct 2 ms 5724 KB Output is correct
9 Correct 1 ms 5724 KB Output is correct
10 Correct 2 ms 5724 KB Output is correct
11 Correct 3 ms 5724 KB Output is correct
12 Correct 2 ms 5724 KB Output is correct
13 Correct 1 ms 5724 KB Output is correct
14 Correct 2 ms 5724 KB Output is correct
15 Correct 2 ms 5724 KB Output is correct
16 Correct 2 ms 5724 KB Output is correct
17 Correct 2 ms 5540 KB Output is correct
18 Correct 2 ms 5724 KB Output is correct
19 Correct 1 ms 5724 KB Output is correct
20 Correct 1 ms 5724 KB Output is correct
21 Correct 2 ms 5724 KB Output is correct
22 Correct 1 ms 5724 KB Output is correct
23 Correct 2 ms 5724 KB Output is correct
24 Correct 1 ms 5724 KB Output is correct
25 Correct 2 ms 5724 KB Output is correct
26 Correct 1 ms 5724 KB Output is correct
27 Correct 2 ms 5724 KB Output is correct
28 Correct 2 ms 5724 KB Output is correct
29 Correct 168 ms 5724 KB Output is correct
30 Correct 81 ms 5840 KB Output is correct
31 Correct 71 ms 5720 KB Output is correct
32 Correct 21 ms 5724 KB Output is correct
33 Correct 9 ms 5832 KB Output is correct
34 Correct 54 ms 5724 KB Output is correct
35 Correct 89 ms 5720 KB Output is correct
36 Correct 24 ms 5724 KB Output is correct
37 Correct 119 ms 5820 KB Output is correct
38 Correct 50 ms 5720 KB Output is correct
39 Correct 90 ms 5720 KB Output is correct
40 Correct 51 ms 5720 KB Output is correct
41 Correct 30 ms 5724 KB Output is correct
42 Correct 31 ms 5724 KB Output is correct
43 Correct 3 ms 5724 KB Output is correct
44 Correct 4 ms 5724 KB Output is correct
45 Correct 6 ms 5724 KB Output is correct
46 Correct 16 ms 5816 KB Output is correct
47 Correct 22 ms 5724 KB Output is correct
48 Correct 24 ms 5832 KB Output is correct
49 Correct 48 ms 5724 KB Output is correct
50 Correct 118 ms 5968 KB Output is correct
51 Correct 22 ms 5720 KB Output is correct
52 Correct 52 ms 5720 KB Output is correct
53 Correct 49 ms 5724 KB Output is correct
54 Correct 76 ms 5820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 5724 KB Output is correct
2 Correct 1 ms 5556 KB Output is correct
3 Correct 58 ms 11240 KB Output is correct
4 Correct 142 ms 16976 KB Output is correct
5 Correct 147 ms 18000 KB Output is correct
6 Correct 82 ms 16884 KB Output is correct
7 Correct 59 ms 16872 KB Output is correct
8 Correct 61 ms 15700 KB Output is correct
9 Correct 59 ms 16212 KB Output is correct
10 Correct 154 ms 17068 KB Output is correct
11 Correct 74 ms 16596 KB Output is correct
12 Correct 123 ms 17404 KB Output is correct
13 Correct 49 ms 15700 KB Output is correct
14 Correct 61 ms 16240 KB Output is correct
15 Correct 86 ms 16976 KB Output is correct
16 Correct 159 ms 17612 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 5724 KB Output is correct
2 Correct 1 ms 5556 KB Output is correct
3 Correct 1 ms 5720 KB Output is correct
4 Correct 1 ms 5724 KB Output is correct
5 Correct 1 ms 5724 KB Output is correct
6 Correct 2 ms 5720 KB Output is correct
7 Correct 3 ms 5724 KB Output is correct
8 Correct 2 ms 5724 KB Output is correct
9 Correct 1 ms 5724 KB Output is correct
10 Correct 2 ms 5724 KB Output is correct
11 Correct 3 ms 5724 KB Output is correct
12 Correct 2 ms 5724 KB Output is correct
13 Correct 1 ms 5724 KB Output is correct
14 Correct 2 ms 5724 KB Output is correct
15 Correct 2 ms 5724 KB Output is correct
16 Correct 2 ms 5724 KB Output is correct
17 Correct 2 ms 5540 KB Output is correct
18 Correct 2 ms 5724 KB Output is correct
19 Correct 1 ms 5724 KB Output is correct
20 Correct 1 ms 5724 KB Output is correct
21 Correct 2 ms 5724 KB Output is correct
22 Correct 1 ms 5724 KB Output is correct
23 Correct 2 ms 5724 KB Output is correct
24 Correct 1 ms 5724 KB Output is correct
25 Correct 2 ms 5724 KB Output is correct
26 Correct 1 ms 5724 KB Output is correct
27 Correct 2 ms 5724 KB Output is correct
28 Correct 2 ms 5724 KB Output is correct
29 Correct 58 ms 11240 KB Output is correct
30 Correct 142 ms 16976 KB Output is correct
31 Correct 147 ms 18000 KB Output is correct
32 Correct 82 ms 16884 KB Output is correct
33 Correct 59 ms 16872 KB Output is correct
34 Correct 61 ms 15700 KB Output is correct
35 Correct 59 ms 16212 KB Output is correct
36 Correct 154 ms 17068 KB Output is correct
37 Correct 74 ms 16596 KB Output is correct
38 Correct 123 ms 17404 KB Output is correct
39 Correct 49 ms 15700 KB Output is correct
40 Correct 61 ms 16240 KB Output is correct
41 Correct 86 ms 16976 KB Output is correct
42 Correct 159 ms 17612 KB Output is correct
43 Incorrect 55 ms 15412 KB Output isn't correct
44 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 5724 KB Output is correct
2 Correct 1 ms 5556 KB Output is correct
3 Correct 1 ms 5720 KB Output is correct
4 Correct 1 ms 5724 KB Output is correct
5 Correct 1 ms 5724 KB Output is correct
6 Correct 2 ms 5720 KB Output is correct
7 Correct 3 ms 5724 KB Output is correct
8 Correct 2 ms 5724 KB Output is correct
9 Correct 1 ms 5724 KB Output is correct
10 Correct 2 ms 5724 KB Output is correct
11 Correct 3 ms 5724 KB Output is correct
12 Correct 2 ms 5724 KB Output is correct
13 Correct 1 ms 5724 KB Output is correct
14 Correct 2 ms 5724 KB Output is correct
15 Correct 2 ms 5724 KB Output is correct
16 Correct 2 ms 5724 KB Output is correct
17 Correct 2 ms 5540 KB Output is correct
18 Correct 2 ms 5724 KB Output is correct
19 Correct 1 ms 5724 KB Output is correct
20 Correct 1 ms 5724 KB Output is correct
21 Correct 2 ms 5724 KB Output is correct
22 Correct 1 ms 5724 KB Output is correct
23 Correct 2 ms 5724 KB Output is correct
24 Correct 1 ms 5724 KB Output is correct
25 Correct 2 ms 5724 KB Output is correct
26 Correct 1 ms 5724 KB Output is correct
27 Correct 2 ms 5724 KB Output is correct
28 Correct 2 ms 5724 KB Output is correct
29 Correct 168 ms 5724 KB Output is correct
30 Correct 81 ms 5840 KB Output is correct
31 Correct 71 ms 5720 KB Output is correct
32 Correct 21 ms 5724 KB Output is correct
33 Correct 9 ms 5832 KB Output is correct
34 Correct 54 ms 5724 KB Output is correct
35 Correct 89 ms 5720 KB Output is correct
36 Correct 24 ms 5724 KB Output is correct
37 Correct 119 ms 5820 KB Output is correct
38 Correct 50 ms 5720 KB Output is correct
39 Correct 90 ms 5720 KB Output is correct
40 Correct 51 ms 5720 KB Output is correct
41 Correct 30 ms 5724 KB Output is correct
42 Correct 31 ms 5724 KB Output is correct
43 Correct 3 ms 5724 KB Output is correct
44 Correct 4 ms 5724 KB Output is correct
45 Correct 6 ms 5724 KB Output is correct
46 Correct 16 ms 5816 KB Output is correct
47 Correct 22 ms 5724 KB Output is correct
48 Correct 24 ms 5832 KB Output is correct
49 Correct 48 ms 5724 KB Output is correct
50 Correct 118 ms 5968 KB Output is correct
51 Correct 22 ms 5720 KB Output is correct
52 Correct 52 ms 5720 KB Output is correct
53 Correct 49 ms 5724 KB Output is correct
54 Correct 76 ms 5820 KB Output is correct
55 Incorrect 45 ms 10576 KB Output isn't correct
56 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 5724 KB Output is correct
2 Correct 1 ms 5556 KB Output is correct
3 Correct 1 ms 5720 KB Output is correct
4 Correct 1 ms 5724 KB Output is correct
5 Correct 1 ms 5724 KB Output is correct
6 Correct 2 ms 5720 KB Output is correct
7 Correct 3 ms 5724 KB Output is correct
8 Correct 2 ms 5724 KB Output is correct
9 Correct 1 ms 5724 KB Output is correct
10 Correct 2 ms 5724 KB Output is correct
11 Correct 3 ms 5724 KB Output is correct
12 Correct 2 ms 5724 KB Output is correct
13 Correct 1 ms 5724 KB Output is correct
14 Correct 2 ms 5724 KB Output is correct
15 Correct 2 ms 5724 KB Output is correct
16 Correct 2 ms 5724 KB Output is correct
17 Correct 2 ms 5540 KB Output is correct
18 Correct 2 ms 5724 KB Output is correct
19 Correct 1 ms 5724 KB Output is correct
20 Correct 1 ms 5724 KB Output is correct
21 Correct 2 ms 5724 KB Output is correct
22 Correct 1 ms 5724 KB Output is correct
23 Correct 2 ms 5724 KB Output is correct
24 Correct 1 ms 5724 KB Output is correct
25 Correct 2 ms 5724 KB Output is correct
26 Correct 1 ms 5724 KB Output is correct
27 Correct 2 ms 5724 KB Output is correct
28 Correct 2 ms 5724 KB Output is correct
29 Correct 168 ms 5724 KB Output is correct
30 Correct 81 ms 5840 KB Output is correct
31 Correct 71 ms 5720 KB Output is correct
32 Correct 21 ms 5724 KB Output is correct
33 Correct 9 ms 5832 KB Output is correct
34 Correct 54 ms 5724 KB Output is correct
35 Correct 89 ms 5720 KB Output is correct
36 Correct 24 ms 5724 KB Output is correct
37 Correct 119 ms 5820 KB Output is correct
38 Correct 50 ms 5720 KB Output is correct
39 Correct 90 ms 5720 KB Output is correct
40 Correct 51 ms 5720 KB Output is correct
41 Correct 30 ms 5724 KB Output is correct
42 Correct 31 ms 5724 KB Output is correct
43 Correct 3 ms 5724 KB Output is correct
44 Correct 4 ms 5724 KB Output is correct
45 Correct 6 ms 5724 KB Output is correct
46 Correct 16 ms 5816 KB Output is correct
47 Correct 22 ms 5724 KB Output is correct
48 Correct 24 ms 5832 KB Output is correct
49 Correct 48 ms 5724 KB Output is correct
50 Correct 118 ms 5968 KB Output is correct
51 Correct 22 ms 5720 KB Output is correct
52 Correct 52 ms 5720 KB Output is correct
53 Correct 49 ms 5724 KB Output is correct
54 Correct 76 ms 5820 KB Output is correct
55 Correct 58 ms 11240 KB Output is correct
56 Correct 142 ms 16976 KB Output is correct
57 Correct 147 ms 18000 KB Output is correct
58 Correct 82 ms 16884 KB Output is correct
59 Correct 59 ms 16872 KB Output is correct
60 Correct 61 ms 15700 KB Output is correct
61 Correct 59 ms 16212 KB Output is correct
62 Correct 154 ms 17068 KB Output is correct
63 Correct 74 ms 16596 KB Output is correct
64 Correct 123 ms 17404 KB Output is correct
65 Correct 49 ms 15700 KB Output is correct
66 Correct 61 ms 16240 KB Output is correct
67 Correct 86 ms 16976 KB Output is correct
68 Correct 159 ms 17612 KB Output is correct
69 Incorrect 55 ms 15412 KB Output isn't correct
70 Halted 0 ms 0 KB -