Submission #1097209

# Submission time Handle Problem Language Result Execution time Memory
1097209 2024-10-06T12:18:54 Z vjudge1 Joker (BOI20_joker) C++14
49 / 100
1054 ms 23632 KB
#include<bits/stdc++.h>
 
using namespace std;
 
#define pi pair<int, int>
#define fi first
#define se second
#define all(v) v.begin(), v.end()
 
const int N = 2e5 + 5;
 
using tp = tuple<int, int, int>;
 
int n, m, q;
pi edge[N];
tp Q[N];
vector<int> ad[N];
 
namespace sub2 {
  bool ok = 0;
  int col[N];
 
  void dfs(int u, int c) {
    col[u] = c;
    for(auto v : ad[u]) {
      if(col[v] == col[u]) ok = 1;
      if(col[v] == -1) dfs(v, c ^ 1);
    }
  }
 
  void solve() {
    for(int que = 1; que <= q; ++que) {
      int l, r, id; tie(l, r, id) = Q[que];
 
      for(int i = 1; i <= n; ++i) ad[i].clear();
 
      for(int i = 1; i < l; ++i) {
        int u, v; tie(u, v) = edge[i];
        ad[u].push_back(v);
        ad[v].push_back(u);
      }
      for(int i = r + 1; i <= m; ++i) {
        int u, v; tie(u, v) = edge[i];
        ad[u].push_back(v);
        ad[v].push_back(u);
      }
 
      for(int i = 1; i <= n; ++i) col[i] = -1;
 
      ok = 0;
      for(int i = 1; i <= n; ++i)
        if(col[i] == -1) dfs(i, 0);
 
      cout << (ok ? "YES\n" : "NO\n");
    }
  }
}
 
///
namespace sub3 {
  int par[N], sz[N], lz[N], ans[N];
  vector<int> L;
  vector<pi> queries[N];
 
  void make_set() {
    for(int i = 1; i <= n; ++i) par[i] = i, sz[i] = 1, lz[i] = 0;
  }
 
  int find_set(int v, int &c) {
    c ^= lz[v];
    if(v == par[v]) return v;
    return find_set(par[v], c);
  }
 
  void union_set(int a, int b) {
    int ca = 0, cb = 0;
    a = find_set(a, ca); b = find_set(b, cb);
    if(a != b) {
      if(sz[a] < sz[b]) swap(a, b);
      sz[a] += sz[b];
      par[b] = a;
      if(ca == cb) lz[b] = 1;
    }
  }
 
  bool check(int a, int b) {
    int ca = 0, cb = 0;
    a = find_set(a, ca); b = find_set(b, cb);
    if(a == b && ca == cb) return true;
    return false;
  }
 
  void solve() {
    sort(Q + 1, Q + q + 1);
 
    for(int i = 1, cur = 0; i <= q; ++i) {
      int l, r, id; tie(l, r, id) = Q[i];
      if(l != cur) cur = l, L.push_back(cur);
      queries[cur].emplace_back(r, id);
    }
 
    for(auto x : L) sort(all(queries[x]), greater<pi>());
 
    for(auto l : L) {
      make_set();
      bool ok = 0;
 
      for(int i = 1; i < l; ++i) {
        int u, v; tie(u, v) = edge[i];
        if(check(u, v)) ok = 1;
        union_set(u, v);
      }
 
      int j = m;
      for(int i = m; i > queries[l][0].fi; --i) {
        int u, v; tie(u, v) = edge[i];
        if(check(u, v)) ok = 1;
        union_set(u, v);
        j = i;
      }
      ans[queries[l][0].se] = ok;
 
      for(int i = 1; i < queries[l].size(); ++i) {
        int r, id; tie(r, id) = queries[l][i];
        if(ok) {
          ans[id] = ok;
          continue;
        }
 
        while(j > r) {
          if(check(edge[j].fi, edge[j].se)) ok = 1;
          union_set(edge[j].fi, edge[j].se);
          --j;
        }
        ans[id] = ok;
      }
    }
 
    for(int i = 1; i <= q; ++i) cout << (ans[i] ? "YES\n" : "NO\n");
  }
}
 
signed main() {
  cin.tie(0)->sync_with_stdio(0);
 
  if(fopen("task.inp", "r")) {
    freopen("task.inp", "r", stdin);
    freopen("task.out", "w", stdout);
  }
 
  cin >> n >> m >> q;
 
  for(int i = 1; i <= m; ++i) {
    int u, v; cin >> u >> v;
    edge[i] = {u, v};
  }
 
  bool chk = 1;
  for(int i = 1; i <= q; ++i) {
    int l, r; cin >> l >> r;
    Q[i] = {l, r, i};
    if(l > 200) chk = 0;
  }
 
  if(chk) sub3 :: solve();
  else if(n <= 2000 && m <= 2000 && q <= 2000) sub2 :: solve();
}

Compilation message

Joker.cpp: In function 'void sub3::solve()':
Joker.cpp:123:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  123 |       for(int i = 1; i < queries[l].size(); ++i) {
      |                      ~~^~~~~~~~~~~~~~~~~~~
Joker.cpp: In function 'int main()':
Joker.cpp:147:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  147 |     freopen("task.inp", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Joker.cpp:148:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
  148 |     freopen("task.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9820 KB Output is correct
2 Correct 4 ms 9820 KB Output is correct
3 Correct 4 ms 9820 KB Output is correct
4 Correct 4 ms 9820 KB Output is correct
5 Correct 4 ms 9820 KB Output is correct
6 Correct 4 ms 9820 KB Output is correct
7 Correct 4 ms 9820 KB Output is correct
8 Correct 4 ms 9668 KB Output is correct
9 Correct 5 ms 9820 KB Output is correct
10 Correct 5 ms 9820 KB Output is correct
11 Correct 6 ms 9816 KB Output is correct
12 Correct 4 ms 9816 KB Output is correct
13 Correct 4 ms 9816 KB Output is correct
14 Correct 4 ms 9820 KB Output is correct
15 Correct 4 ms 9820 KB Output is correct
16 Correct 4 ms 9820 KB Output is correct
17 Correct 4 ms 9692 KB Output is correct
18 Correct 4 ms 9816 KB Output is correct
19 Correct 5 ms 9864 KB Output is correct
20 Correct 4 ms 9820 KB Output is correct
21 Correct 4 ms 9820 KB Output is correct
22 Correct 4 ms 9820 KB Output is correct
23 Correct 4 ms 9820 KB Output is correct
24 Correct 4 ms 9820 KB Output is correct
25 Correct 6 ms 10072 KB Output is correct
26 Correct 5 ms 9820 KB Output is correct
27 Correct 5 ms 9820 KB Output is correct
28 Correct 5 ms 9820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9820 KB Output is correct
2 Correct 4 ms 9820 KB Output is correct
3 Correct 4 ms 9820 KB Output is correct
4 Correct 4 ms 9820 KB Output is correct
5 Correct 4 ms 9820 KB Output is correct
6 Correct 4 ms 9820 KB Output is correct
7 Correct 4 ms 9820 KB Output is correct
8 Correct 4 ms 9668 KB Output is correct
9 Correct 5 ms 9820 KB Output is correct
10 Correct 5 ms 9820 KB Output is correct
11 Correct 6 ms 9816 KB Output is correct
12 Correct 4 ms 9816 KB Output is correct
13 Correct 4 ms 9816 KB Output is correct
14 Correct 4 ms 9820 KB Output is correct
15 Correct 4 ms 9820 KB Output is correct
16 Correct 4 ms 9820 KB Output is correct
17 Correct 4 ms 9692 KB Output is correct
18 Correct 4 ms 9816 KB Output is correct
19 Correct 5 ms 9864 KB Output is correct
20 Correct 4 ms 9820 KB Output is correct
21 Correct 4 ms 9820 KB Output is correct
22 Correct 4 ms 9820 KB Output is correct
23 Correct 4 ms 9820 KB Output is correct
24 Correct 4 ms 9820 KB Output is correct
25 Correct 6 ms 10072 KB Output is correct
26 Correct 5 ms 9820 KB Output is correct
27 Correct 5 ms 9820 KB Output is correct
28 Correct 5 ms 9820 KB Output is correct
29 Correct 42 ms 9820 KB Output is correct
30 Correct 78 ms 9820 KB Output is correct
31 Correct 76 ms 9820 KB Output is correct
32 Correct 68 ms 9820 KB Output is correct
33 Correct 54 ms 10028 KB Output is correct
34 Correct 83 ms 9820 KB Output is correct
35 Correct 84 ms 9816 KB Output is correct
36 Correct 38 ms 9816 KB Output is correct
37 Correct 60 ms 10076 KB Output is correct
38 Correct 54 ms 10072 KB Output is correct
39 Correct 58 ms 9796 KB Output is correct
40 Correct 58 ms 9816 KB Output is correct
41 Correct 58 ms 9816 KB Output is correct
42 Correct 57 ms 9820 KB Output is correct
43 Correct 52 ms 9820 KB Output is correct
44 Correct 62 ms 9820 KB Output is correct
45 Correct 68 ms 9816 KB Output is correct
46 Correct 71 ms 9820 KB Output is correct
47 Correct 54 ms 9816 KB Output is correct
48 Correct 63 ms 9816 KB Output is correct
49 Correct 70 ms 9816 KB Output is correct
50 Correct 77 ms 9816 KB Output is correct
51 Correct 54 ms 9816 KB Output is correct
52 Correct 63 ms 10016 KB Output is correct
53 Correct 73 ms 10036 KB Output is correct
54 Correct 83 ms 9820 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9820 KB Output is correct
2 Correct 4 ms 9820 KB Output is correct
3 Correct 71 ms 21964 KB Output is correct
4 Correct 78 ms 22552 KB Output is correct
5 Correct 80 ms 23240 KB Output is correct
6 Correct 75 ms 21960 KB Output is correct
7 Correct 77 ms 21908 KB Output is correct
8 Correct 72 ms 21036 KB Output is correct
9 Correct 75 ms 21452 KB Output is correct
10 Correct 72 ms 22820 KB Output is correct
11 Correct 73 ms 21880 KB Output is correct
12 Correct 72 ms 22984 KB Output is correct
13 Correct 80 ms 20812 KB Output is correct
14 Correct 73 ms 21444 KB Output is correct
15 Correct 85 ms 22308 KB Output is correct
16 Correct 79 ms 23244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9820 KB Output is correct
2 Correct 4 ms 9820 KB Output is correct
3 Correct 4 ms 9820 KB Output is correct
4 Correct 4 ms 9820 KB Output is correct
5 Correct 4 ms 9820 KB Output is correct
6 Correct 4 ms 9820 KB Output is correct
7 Correct 4 ms 9820 KB Output is correct
8 Correct 4 ms 9668 KB Output is correct
9 Correct 5 ms 9820 KB Output is correct
10 Correct 5 ms 9820 KB Output is correct
11 Correct 6 ms 9816 KB Output is correct
12 Correct 4 ms 9816 KB Output is correct
13 Correct 4 ms 9816 KB Output is correct
14 Correct 4 ms 9820 KB Output is correct
15 Correct 4 ms 9820 KB Output is correct
16 Correct 4 ms 9820 KB Output is correct
17 Correct 4 ms 9692 KB Output is correct
18 Correct 4 ms 9816 KB Output is correct
19 Correct 5 ms 9864 KB Output is correct
20 Correct 4 ms 9820 KB Output is correct
21 Correct 4 ms 9820 KB Output is correct
22 Correct 4 ms 9820 KB Output is correct
23 Correct 4 ms 9820 KB Output is correct
24 Correct 4 ms 9820 KB Output is correct
25 Correct 6 ms 10072 KB Output is correct
26 Correct 5 ms 9820 KB Output is correct
27 Correct 5 ms 9820 KB Output is correct
28 Correct 5 ms 9820 KB Output is correct
29 Correct 71 ms 21964 KB Output is correct
30 Correct 78 ms 22552 KB Output is correct
31 Correct 80 ms 23240 KB Output is correct
32 Correct 75 ms 21960 KB Output is correct
33 Correct 77 ms 21908 KB Output is correct
34 Correct 72 ms 21036 KB Output is correct
35 Correct 75 ms 21452 KB Output is correct
36 Correct 72 ms 22820 KB Output is correct
37 Correct 73 ms 21880 KB Output is correct
38 Correct 72 ms 22984 KB Output is correct
39 Correct 80 ms 20812 KB Output is correct
40 Correct 73 ms 21444 KB Output is correct
41 Correct 85 ms 22308 KB Output is correct
42 Correct 79 ms 23244 KB Output is correct
43 Correct 426 ms 22400 KB Output is correct
44 Correct 1054 ms 23240 KB Output is correct
45 Correct 938 ms 23552 KB Output is correct
46 Correct 119 ms 22356 KB Output is correct
47 Correct 129 ms 22292 KB Output is correct
48 Correct 347 ms 22000 KB Output is correct
49 Correct 603 ms 23504 KB Output is correct
50 Correct 612 ms 22096 KB Output is correct
51 Correct 523 ms 22892 KB Output is correct
52 Correct 484 ms 23632 KB Output is correct
53 Correct 407 ms 21332 KB Output is correct
54 Correct 329 ms 22096 KB Output is correct
55 Correct 498 ms 22868 KB Output is correct
56 Correct 567 ms 23632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9820 KB Output is correct
2 Correct 4 ms 9820 KB Output is correct
3 Correct 4 ms 9820 KB Output is correct
4 Correct 4 ms 9820 KB Output is correct
5 Correct 4 ms 9820 KB Output is correct
6 Correct 4 ms 9820 KB Output is correct
7 Correct 4 ms 9820 KB Output is correct
8 Correct 4 ms 9668 KB Output is correct
9 Correct 5 ms 9820 KB Output is correct
10 Correct 5 ms 9820 KB Output is correct
11 Correct 6 ms 9816 KB Output is correct
12 Correct 4 ms 9816 KB Output is correct
13 Correct 4 ms 9816 KB Output is correct
14 Correct 4 ms 9820 KB Output is correct
15 Correct 4 ms 9820 KB Output is correct
16 Correct 4 ms 9820 KB Output is correct
17 Correct 4 ms 9692 KB Output is correct
18 Correct 4 ms 9816 KB Output is correct
19 Correct 5 ms 9864 KB Output is correct
20 Correct 4 ms 9820 KB Output is correct
21 Correct 4 ms 9820 KB Output is correct
22 Correct 4 ms 9820 KB Output is correct
23 Correct 4 ms 9820 KB Output is correct
24 Correct 4 ms 9820 KB Output is correct
25 Correct 6 ms 10072 KB Output is correct
26 Correct 5 ms 9820 KB Output is correct
27 Correct 5 ms 9820 KB Output is correct
28 Correct 5 ms 9820 KB Output is correct
29 Correct 42 ms 9820 KB Output is correct
30 Correct 78 ms 9820 KB Output is correct
31 Correct 76 ms 9820 KB Output is correct
32 Correct 68 ms 9820 KB Output is correct
33 Correct 54 ms 10028 KB Output is correct
34 Correct 83 ms 9820 KB Output is correct
35 Correct 84 ms 9816 KB Output is correct
36 Correct 38 ms 9816 KB Output is correct
37 Correct 60 ms 10076 KB Output is correct
38 Correct 54 ms 10072 KB Output is correct
39 Correct 58 ms 9796 KB Output is correct
40 Correct 58 ms 9816 KB Output is correct
41 Correct 58 ms 9816 KB Output is correct
42 Correct 57 ms 9820 KB Output is correct
43 Correct 52 ms 9820 KB Output is correct
44 Correct 62 ms 9820 KB Output is correct
45 Correct 68 ms 9816 KB Output is correct
46 Correct 71 ms 9820 KB Output is correct
47 Correct 54 ms 9816 KB Output is correct
48 Correct 63 ms 9816 KB Output is correct
49 Correct 70 ms 9816 KB Output is correct
50 Correct 77 ms 9816 KB Output is correct
51 Correct 54 ms 9816 KB Output is correct
52 Correct 63 ms 10016 KB Output is correct
53 Correct 73 ms 10036 KB Output is correct
54 Correct 83 ms 9820 KB Output is correct
55 Incorrect 24 ms 13652 KB Output isn't correct
56 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 5 ms 9820 KB Output is correct
2 Correct 4 ms 9820 KB Output is correct
3 Correct 4 ms 9820 KB Output is correct
4 Correct 4 ms 9820 KB Output is correct
5 Correct 4 ms 9820 KB Output is correct
6 Correct 4 ms 9820 KB Output is correct
7 Correct 4 ms 9820 KB Output is correct
8 Correct 4 ms 9668 KB Output is correct
9 Correct 5 ms 9820 KB Output is correct
10 Correct 5 ms 9820 KB Output is correct
11 Correct 6 ms 9816 KB Output is correct
12 Correct 4 ms 9816 KB Output is correct
13 Correct 4 ms 9816 KB Output is correct
14 Correct 4 ms 9820 KB Output is correct
15 Correct 4 ms 9820 KB Output is correct
16 Correct 4 ms 9820 KB Output is correct
17 Correct 4 ms 9692 KB Output is correct
18 Correct 4 ms 9816 KB Output is correct
19 Correct 5 ms 9864 KB Output is correct
20 Correct 4 ms 9820 KB Output is correct
21 Correct 4 ms 9820 KB Output is correct
22 Correct 4 ms 9820 KB Output is correct
23 Correct 4 ms 9820 KB Output is correct
24 Correct 4 ms 9820 KB Output is correct
25 Correct 6 ms 10072 KB Output is correct
26 Correct 5 ms 9820 KB Output is correct
27 Correct 5 ms 9820 KB Output is correct
28 Correct 5 ms 9820 KB Output is correct
29 Correct 42 ms 9820 KB Output is correct
30 Correct 78 ms 9820 KB Output is correct
31 Correct 76 ms 9820 KB Output is correct
32 Correct 68 ms 9820 KB Output is correct
33 Correct 54 ms 10028 KB Output is correct
34 Correct 83 ms 9820 KB Output is correct
35 Correct 84 ms 9816 KB Output is correct
36 Correct 38 ms 9816 KB Output is correct
37 Correct 60 ms 10076 KB Output is correct
38 Correct 54 ms 10072 KB Output is correct
39 Correct 58 ms 9796 KB Output is correct
40 Correct 58 ms 9816 KB Output is correct
41 Correct 58 ms 9816 KB Output is correct
42 Correct 57 ms 9820 KB Output is correct
43 Correct 52 ms 9820 KB Output is correct
44 Correct 62 ms 9820 KB Output is correct
45 Correct 68 ms 9816 KB Output is correct
46 Correct 71 ms 9820 KB Output is correct
47 Correct 54 ms 9816 KB Output is correct
48 Correct 63 ms 9816 KB Output is correct
49 Correct 70 ms 9816 KB Output is correct
50 Correct 77 ms 9816 KB Output is correct
51 Correct 54 ms 9816 KB Output is correct
52 Correct 63 ms 10016 KB Output is correct
53 Correct 73 ms 10036 KB Output is correct
54 Correct 83 ms 9820 KB Output is correct
55 Correct 71 ms 21964 KB Output is correct
56 Correct 78 ms 22552 KB Output is correct
57 Correct 80 ms 23240 KB Output is correct
58 Correct 75 ms 21960 KB Output is correct
59 Correct 77 ms 21908 KB Output is correct
60 Correct 72 ms 21036 KB Output is correct
61 Correct 75 ms 21452 KB Output is correct
62 Correct 72 ms 22820 KB Output is correct
63 Correct 73 ms 21880 KB Output is correct
64 Correct 72 ms 22984 KB Output is correct
65 Correct 80 ms 20812 KB Output is correct
66 Correct 73 ms 21444 KB Output is correct
67 Correct 85 ms 22308 KB Output is correct
68 Correct 79 ms 23244 KB Output is correct
69 Correct 426 ms 22400 KB Output is correct
70 Correct 1054 ms 23240 KB Output is correct
71 Correct 938 ms 23552 KB Output is correct
72 Correct 119 ms 22356 KB Output is correct
73 Correct 129 ms 22292 KB Output is correct
74 Correct 347 ms 22000 KB Output is correct
75 Correct 603 ms 23504 KB Output is correct
76 Correct 612 ms 22096 KB Output is correct
77 Correct 523 ms 22892 KB Output is correct
78 Correct 484 ms 23632 KB Output is correct
79 Correct 407 ms 21332 KB Output is correct
80 Correct 329 ms 22096 KB Output is correct
81 Correct 498 ms 22868 KB Output is correct
82 Correct 567 ms 23632 KB Output is correct
83 Incorrect 24 ms 13652 KB Output isn't correct
84 Halted 0 ms 0 KB -