Submission #1050412

# Submission time Handle Problem Language Result Execution time Memory
1050412 2024-08-09T09:14:13 Z duckindog Joker (BOI20_joker) C++17
14 / 100
160 ms 15184 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(l, 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 5724 KB Output is correct
3 Correct 1 ms 5724 KB Output is correct
4 Correct 1 ms 5724 KB Output is correct
5 Correct 1 ms 5724 KB Output is correct
6 Correct 1 ms 5724 KB Output is correct
7 Correct 3 ms 5560 KB Output is correct
8 Correct 2 ms 5724 KB Output is correct
9 Correct 1 ms 5724 KB Output is correct
10 Correct 1 ms 5724 KB Output is correct
11 Correct 2 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 1 ms 5724 KB Output is correct
15 Correct 1 ms 5724 KB Output is correct
16 Correct 2 ms 5724 KB Output is correct
17 Correct 1 ms 5724 KB Output is correct
18 Correct 2 ms 5976 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 1 ms 5724 KB Output is correct
24 Correct 1 ms 5724 KB Output is correct
25 Correct 1 ms 5724 KB Output is correct
26 Correct 1 ms 5724 KB Output is correct
27 Correct 1 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 5724 KB Output is correct
3 Correct 1 ms 5724 KB Output is correct
4 Correct 1 ms 5724 KB Output is correct
5 Correct 1 ms 5724 KB Output is correct
6 Correct 1 ms 5724 KB Output is correct
7 Correct 3 ms 5560 KB Output is correct
8 Correct 2 ms 5724 KB Output is correct
9 Correct 1 ms 5724 KB Output is correct
10 Correct 1 ms 5724 KB Output is correct
11 Correct 2 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 1 ms 5724 KB Output is correct
15 Correct 1 ms 5724 KB Output is correct
16 Correct 2 ms 5724 KB Output is correct
17 Correct 1 ms 5724 KB Output is correct
18 Correct 2 ms 5976 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 1 ms 5724 KB Output is correct
24 Correct 1 ms 5724 KB Output is correct
25 Correct 1 ms 5724 KB Output is correct
26 Correct 1 ms 5724 KB Output is correct
27 Correct 1 ms 5724 KB Output is correct
28 Correct 2 ms 5724 KB Output is correct
29 Correct 160 ms 5724 KB Output is correct
30 Correct 78 ms 5816 KB Output is correct
31 Correct 51 ms 5720 KB Output is correct
32 Correct 21 ms 5724 KB Output is correct
33 Correct 9 ms 5724 KB Output is correct
34 Correct 54 ms 5836 KB Output is correct
35 Correct 82 ms 5724 KB Output is correct
36 Correct 24 ms 5720 KB Output is correct
37 Correct 77 ms 5724 KB Output is correct
38 Correct 51 ms 5840 KB Output is correct
39 Correct 90 ms 5720 KB Output is correct
40 Correct 34 ms 5836 KB Output is correct
41 Correct 29 ms 5724 KB Output is correct
42 Correct 33 ms 5724 KB Output is correct
43 Correct 3 ms 5724 KB Output is correct
44 Correct 4 ms 5840 KB Output is correct
45 Correct 6 ms 5724 KB Output is correct
46 Correct 15 ms 5840 KB Output is correct
47 Correct 23 ms 5720 KB Output is correct
48 Correct 25 ms 5724 KB Output is correct
49 Correct 48 ms 5832 KB Output is correct
50 Correct 73 ms 5724 KB Output is correct
51 Correct 22 ms 5724 KB Output is correct
52 Correct 32 ms 5720 KB Output is correct
53 Correct 49 ms 5724 KB Output is correct
54 Correct 76 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 5724 KB Output is correct
3 Incorrect 51 ms 15184 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 5724 KB Output is correct
2 Correct 1 ms 5724 KB Output is correct
3 Correct 1 ms 5724 KB Output is correct
4 Correct 1 ms 5724 KB Output is correct
5 Correct 1 ms 5724 KB Output is correct
6 Correct 1 ms 5724 KB Output is correct
7 Correct 3 ms 5560 KB Output is correct
8 Correct 2 ms 5724 KB Output is correct
9 Correct 1 ms 5724 KB Output is correct
10 Correct 1 ms 5724 KB Output is correct
11 Correct 2 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 1 ms 5724 KB Output is correct
15 Correct 1 ms 5724 KB Output is correct
16 Correct 2 ms 5724 KB Output is correct
17 Correct 1 ms 5724 KB Output is correct
18 Correct 2 ms 5976 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 1 ms 5724 KB Output is correct
24 Correct 1 ms 5724 KB Output is correct
25 Correct 1 ms 5724 KB Output is correct
26 Correct 1 ms 5724 KB Output is correct
27 Correct 1 ms 5724 KB Output is correct
28 Correct 2 ms 5724 KB Output is correct
29 Incorrect 51 ms 15184 KB Output isn't correct
30 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 5724 KB Output is correct
2 Correct 1 ms 5724 KB Output is correct
3 Correct 1 ms 5724 KB Output is correct
4 Correct 1 ms 5724 KB Output is correct
5 Correct 1 ms 5724 KB Output is correct
6 Correct 1 ms 5724 KB Output is correct
7 Correct 3 ms 5560 KB Output is correct
8 Correct 2 ms 5724 KB Output is correct
9 Correct 1 ms 5724 KB Output is correct
10 Correct 1 ms 5724 KB Output is correct
11 Correct 2 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 1 ms 5724 KB Output is correct
15 Correct 1 ms 5724 KB Output is correct
16 Correct 2 ms 5724 KB Output is correct
17 Correct 1 ms 5724 KB Output is correct
18 Correct 2 ms 5976 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 1 ms 5724 KB Output is correct
24 Correct 1 ms 5724 KB Output is correct
25 Correct 1 ms 5724 KB Output is correct
26 Correct 1 ms 5724 KB Output is correct
27 Correct 1 ms 5724 KB Output is correct
28 Correct 2 ms 5724 KB Output is correct
29 Correct 160 ms 5724 KB Output is correct
30 Correct 78 ms 5816 KB Output is correct
31 Correct 51 ms 5720 KB Output is correct
32 Correct 21 ms 5724 KB Output is correct
33 Correct 9 ms 5724 KB Output is correct
34 Correct 54 ms 5836 KB Output is correct
35 Correct 82 ms 5724 KB Output is correct
36 Correct 24 ms 5720 KB Output is correct
37 Correct 77 ms 5724 KB Output is correct
38 Correct 51 ms 5840 KB Output is correct
39 Correct 90 ms 5720 KB Output is correct
40 Correct 34 ms 5836 KB Output is correct
41 Correct 29 ms 5724 KB Output is correct
42 Correct 33 ms 5724 KB Output is correct
43 Correct 3 ms 5724 KB Output is correct
44 Correct 4 ms 5840 KB Output is correct
45 Correct 6 ms 5724 KB Output is correct
46 Correct 15 ms 5840 KB Output is correct
47 Correct 23 ms 5720 KB Output is correct
48 Correct 25 ms 5724 KB Output is correct
49 Correct 48 ms 5832 KB Output is correct
50 Correct 73 ms 5724 KB Output is correct
51 Correct 22 ms 5724 KB Output is correct
52 Correct 32 ms 5720 KB Output is correct
53 Correct 49 ms 5724 KB Output is correct
54 Correct 76 ms 5724 KB Output is correct
55 Incorrect 45 ms 12884 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 5724 KB Output is correct
3 Correct 1 ms 5724 KB Output is correct
4 Correct 1 ms 5724 KB Output is correct
5 Correct 1 ms 5724 KB Output is correct
6 Correct 1 ms 5724 KB Output is correct
7 Correct 3 ms 5560 KB Output is correct
8 Correct 2 ms 5724 KB Output is correct
9 Correct 1 ms 5724 KB Output is correct
10 Correct 1 ms 5724 KB Output is correct
11 Correct 2 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 1 ms 5724 KB Output is correct
15 Correct 1 ms 5724 KB Output is correct
16 Correct 2 ms 5724 KB Output is correct
17 Correct 1 ms 5724 KB Output is correct
18 Correct 2 ms 5976 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 1 ms 5724 KB Output is correct
24 Correct 1 ms 5724 KB Output is correct
25 Correct 1 ms 5724 KB Output is correct
26 Correct 1 ms 5724 KB Output is correct
27 Correct 1 ms 5724 KB Output is correct
28 Correct 2 ms 5724 KB Output is correct
29 Correct 160 ms 5724 KB Output is correct
30 Correct 78 ms 5816 KB Output is correct
31 Correct 51 ms 5720 KB Output is correct
32 Correct 21 ms 5724 KB Output is correct
33 Correct 9 ms 5724 KB Output is correct
34 Correct 54 ms 5836 KB Output is correct
35 Correct 82 ms 5724 KB Output is correct
36 Correct 24 ms 5720 KB Output is correct
37 Correct 77 ms 5724 KB Output is correct
38 Correct 51 ms 5840 KB Output is correct
39 Correct 90 ms 5720 KB Output is correct
40 Correct 34 ms 5836 KB Output is correct
41 Correct 29 ms 5724 KB Output is correct
42 Correct 33 ms 5724 KB Output is correct
43 Correct 3 ms 5724 KB Output is correct
44 Correct 4 ms 5840 KB Output is correct
45 Correct 6 ms 5724 KB Output is correct
46 Correct 15 ms 5840 KB Output is correct
47 Correct 23 ms 5720 KB Output is correct
48 Correct 25 ms 5724 KB Output is correct
49 Correct 48 ms 5832 KB Output is correct
50 Correct 73 ms 5724 KB Output is correct
51 Correct 22 ms 5724 KB Output is correct
52 Correct 32 ms 5720 KB Output is correct
53 Correct 49 ms 5724 KB Output is correct
54 Correct 76 ms 5724 KB Output is correct
55 Incorrect 51 ms 15184 KB Output isn't correct
56 Halted 0 ms 0 KB -