Submission #914296

# Submission time Handle Problem Language Result Execution time Memory
914296 2024-01-21T14:45:41 Z 3as8 Joker (BOI20_joker) C++14
14 / 100
2000 ms 23796 KB
#include <bits/stdc++.h>

#define ll long long
#define endl "\n"
#define fastIO cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false);

#define mid ((l + r) / 2)
#define lChild ((index * 2) + 1)
#define rChild ((index * 2) + 2)

using namespace std;

struct node {
    ll u, i;
};

bool bi(vector<vector<node> >& graph, vector<ll>& color, ll startIndex, ll p, ll col, ll l, ll r) {

    color[startIndex] = col;

    ll ret = true;
    for(auto [el, i] : graph[startIndex]) {
        if(el == p || (l <= i && i <= r)) continue;
        if(color[el] == -1) ret &= bi(graph, color, el, startIndex, !col, l, r);


        if(color[el] != -1 && color[el] == col) return false;
        if(color[el] != col) continue;

    }

    return ret;
}

bool check(vector<vector<node> >& graph, ll i, ll l = 0) {

    ll n = graph.size();

    vector<ll> col(n, -1);

    ll ans = true;
    for(int j = 0; j < n; j++) {
        if(col[j] != -1) continue;
        ans &= bi(graph, col, j, -1, 0, l, i);
    }

    return !ans;
}


void solve(ll _) {

    ll n, m, q; cin>>n>>m>>q;

    vector<vector<node> > graph(n);
    for(int i = 0; i < m; i++) {
        ll x, y; cin>>x>>y;
        x--; y--;

        graph[x].push_back({y, i});
        graph[y].push_back({x, i});
    }

    vector<bool> is(200, false);
    vector<ll> x(200, 0);

    for(int k = 0; k <= min(m - 1, (ll)200); k++) {
        ll l = 0, r = m - 1;
        while (l < r) {

            bool ckB = check(graph, mid - 1, k), ck = check(graph, mid, k), ckA = check(graph, mid + 1, k);

            if (ckB != ckA) {
                l = r = mid;
                break;
            }

            //cout<<mid<<": => "<<ck<<endl;
            if (!ck) {
                r = mid - 1;
            } else {
                l = mid + 1;
            }
        }

        is[k] = check(graph, l, k);
        x[k] = l;
    }
    // cout<<" => "<<l<<" "<<r<<endl;

    /*for(int i = 0; i < q; i++) {
        cout<<i + 1<<": "<<x[i]<<" => "<<is[i]<<endl;
        for(int j = 0; j < i; j++) cout<<"--"<<endl;
        for(int j = i; j < q; j++) {

            cout<<(check(graph, j, i) ? "YES" : "NO")<<endl;

        }
    }*/

    for(int i = 0; i < q; i++) {
        ll l, r; cin>>l>>r;
        l--; r--;
        //ll l = 0, r = min(q - 1, (ll)i);

        if(n <= 2050 && q <= 2050) {

            cout<<(check(graph, r, l) ? "YES" : "NO")<<endl;
            continue;
        }
        if(x[l] < r) cout<<"NO"<<endl;
        else if(r < x[l]) cout<<"YES"<<endl;
        else {
            cout<<(is[l] ? "YES" : "NO")<<endl;
        }

    }

}

int main() {
    //fastIO

    //freopen("file.in", "r", stdin);
    //freopen("file.out", "w", stdout);

    ll t = 0; solve(t);
}

Compilation message

Joker.cpp: In function 'bool bi(std::vector<std::vector<node> >&, std::vector<long long int>&, long long int, long long int, long long int, long long int, long long int)':
Joker.cpp:22:14: warning: structured bindings only available with '-std=c++17' or '-std=gnu++17'
   22 |     for(auto [el, i] : graph[startIndex]) {
      |              ^
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 3 ms 348 KB Output is correct
8 Correct 8 ms 348 KB Output is correct
9 Correct 8 ms 452 KB Output is correct
10 Correct 7 ms 348 KB Output is correct
11 Correct 9 ms 460 KB Output is correct
12 Correct 10 ms 348 KB Output is correct
13 Correct 5 ms 344 KB Output is correct
14 Correct 9 ms 348 KB Output is correct
15 Correct 8 ms 348 KB Output is correct
16 Correct 8 ms 348 KB Output is correct
17 Correct 7 ms 348 KB Output is correct
18 Correct 6 ms 348 KB Output is correct
19 Correct 7 ms 500 KB Output is correct
20 Correct 5 ms 348 KB Output is correct
21 Correct 7 ms 348 KB Output is correct
22 Correct 8 ms 348 KB Output is correct
23 Correct 6 ms 348 KB Output is correct
24 Correct 7 ms 348 KB Output is correct
25 Correct 8 ms 604 KB Output is correct
26 Correct 6 ms 344 KB Output is correct
27 Correct 7 ms 348 KB Output is correct
28 Correct 8 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 3 ms 348 KB Output is correct
8 Correct 8 ms 348 KB Output is correct
9 Correct 8 ms 452 KB Output is correct
10 Correct 7 ms 348 KB Output is correct
11 Correct 9 ms 460 KB Output is correct
12 Correct 10 ms 348 KB Output is correct
13 Correct 5 ms 344 KB Output is correct
14 Correct 9 ms 348 KB Output is correct
15 Correct 8 ms 348 KB Output is correct
16 Correct 8 ms 348 KB Output is correct
17 Correct 7 ms 348 KB Output is correct
18 Correct 6 ms 348 KB Output is correct
19 Correct 7 ms 500 KB Output is correct
20 Correct 5 ms 348 KB Output is correct
21 Correct 7 ms 348 KB Output is correct
22 Correct 8 ms 348 KB Output is correct
23 Correct 6 ms 348 KB Output is correct
24 Correct 7 ms 348 KB Output is correct
25 Correct 8 ms 604 KB Output is correct
26 Correct 6 ms 344 KB Output is correct
27 Correct 7 ms 348 KB Output is correct
28 Correct 8 ms 344 KB Output is correct
29 Correct 151 ms 348 KB Output is correct
30 Correct 272 ms 1100 KB Output is correct
31 Correct 242 ms 592 KB Output is correct
32 Correct 171 ms 600 KB Output is correct
33 Correct 122 ms 604 KB Output is correct
34 Correct 267 ms 856 KB Output is correct
35 Correct 287 ms 604 KB Output is correct
36 Correct 99 ms 680 KB Output is correct
37 Correct 159 ms 648 KB Output is correct
38 Correct 182 ms 604 KB Output is correct
39 Correct 191 ms 604 KB Output is correct
40 Correct 133 ms 604 KB Output is correct
41 Correct 138 ms 600 KB Output is correct
42 Correct 146 ms 604 KB Output is correct
43 Correct 111 ms 608 KB Output is correct
44 Correct 157 ms 592 KB Output is correct
45 Correct 232 ms 596 KB Output is correct
46 Correct 224 ms 612 KB Output is correct
47 Correct 147 ms 584 KB Output is correct
48 Correct 155 ms 612 KB Output is correct
49 Correct 177 ms 604 KB Output is correct
50 Correct 229 ms 604 KB Output is correct
51 Correct 141 ms 604 KB Output is correct
52 Correct 175 ms 852 KB Output is correct
53 Correct 217 ms 588 KB Output is correct
54 Correct 245 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Execution timed out 2048 ms 23796 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 3 ms 348 KB Output is correct
8 Correct 8 ms 348 KB Output is correct
9 Correct 8 ms 452 KB Output is correct
10 Correct 7 ms 348 KB Output is correct
11 Correct 9 ms 460 KB Output is correct
12 Correct 10 ms 348 KB Output is correct
13 Correct 5 ms 344 KB Output is correct
14 Correct 9 ms 348 KB Output is correct
15 Correct 8 ms 348 KB Output is correct
16 Correct 8 ms 348 KB Output is correct
17 Correct 7 ms 348 KB Output is correct
18 Correct 6 ms 348 KB Output is correct
19 Correct 7 ms 500 KB Output is correct
20 Correct 5 ms 348 KB Output is correct
21 Correct 7 ms 348 KB Output is correct
22 Correct 8 ms 348 KB Output is correct
23 Correct 6 ms 348 KB Output is correct
24 Correct 7 ms 348 KB Output is correct
25 Correct 8 ms 604 KB Output is correct
26 Correct 6 ms 344 KB Output is correct
27 Correct 7 ms 348 KB Output is correct
28 Correct 8 ms 344 KB Output is correct
29 Execution timed out 2048 ms 23796 KB Time limit exceeded
30 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 3 ms 348 KB Output is correct
8 Correct 8 ms 348 KB Output is correct
9 Correct 8 ms 452 KB Output is correct
10 Correct 7 ms 348 KB Output is correct
11 Correct 9 ms 460 KB Output is correct
12 Correct 10 ms 348 KB Output is correct
13 Correct 5 ms 344 KB Output is correct
14 Correct 9 ms 348 KB Output is correct
15 Correct 8 ms 348 KB Output is correct
16 Correct 8 ms 348 KB Output is correct
17 Correct 7 ms 348 KB Output is correct
18 Correct 6 ms 348 KB Output is correct
19 Correct 7 ms 500 KB Output is correct
20 Correct 5 ms 348 KB Output is correct
21 Correct 7 ms 348 KB Output is correct
22 Correct 8 ms 348 KB Output is correct
23 Correct 6 ms 348 KB Output is correct
24 Correct 7 ms 348 KB Output is correct
25 Correct 8 ms 604 KB Output is correct
26 Correct 6 ms 344 KB Output is correct
27 Correct 7 ms 348 KB Output is correct
28 Correct 8 ms 344 KB Output is correct
29 Correct 151 ms 348 KB Output is correct
30 Correct 272 ms 1100 KB Output is correct
31 Correct 242 ms 592 KB Output is correct
32 Correct 171 ms 600 KB Output is correct
33 Correct 122 ms 604 KB Output is correct
34 Correct 267 ms 856 KB Output is correct
35 Correct 287 ms 604 KB Output is correct
36 Correct 99 ms 680 KB Output is correct
37 Correct 159 ms 648 KB Output is correct
38 Correct 182 ms 604 KB Output is correct
39 Correct 191 ms 604 KB Output is correct
40 Correct 133 ms 604 KB Output is correct
41 Correct 138 ms 600 KB Output is correct
42 Correct 146 ms 604 KB Output is correct
43 Correct 111 ms 608 KB Output is correct
44 Correct 157 ms 592 KB Output is correct
45 Correct 232 ms 596 KB Output is correct
46 Correct 224 ms 612 KB Output is correct
47 Correct 147 ms 584 KB Output is correct
48 Correct 155 ms 612 KB Output is correct
49 Correct 177 ms 604 KB Output is correct
50 Correct 229 ms 604 KB Output is correct
51 Correct 141 ms 604 KB Output is correct
52 Correct 175 ms 852 KB Output is correct
53 Correct 217 ms 588 KB Output is correct
54 Correct 245 ms 600 KB Output is correct
55 Execution timed out 2099 ms 23716 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 344 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 3 ms 348 KB Output is correct
8 Correct 8 ms 348 KB Output is correct
9 Correct 8 ms 452 KB Output is correct
10 Correct 7 ms 348 KB Output is correct
11 Correct 9 ms 460 KB Output is correct
12 Correct 10 ms 348 KB Output is correct
13 Correct 5 ms 344 KB Output is correct
14 Correct 9 ms 348 KB Output is correct
15 Correct 8 ms 348 KB Output is correct
16 Correct 8 ms 348 KB Output is correct
17 Correct 7 ms 348 KB Output is correct
18 Correct 6 ms 348 KB Output is correct
19 Correct 7 ms 500 KB Output is correct
20 Correct 5 ms 348 KB Output is correct
21 Correct 7 ms 348 KB Output is correct
22 Correct 8 ms 348 KB Output is correct
23 Correct 6 ms 348 KB Output is correct
24 Correct 7 ms 348 KB Output is correct
25 Correct 8 ms 604 KB Output is correct
26 Correct 6 ms 344 KB Output is correct
27 Correct 7 ms 348 KB Output is correct
28 Correct 8 ms 344 KB Output is correct
29 Correct 151 ms 348 KB Output is correct
30 Correct 272 ms 1100 KB Output is correct
31 Correct 242 ms 592 KB Output is correct
32 Correct 171 ms 600 KB Output is correct
33 Correct 122 ms 604 KB Output is correct
34 Correct 267 ms 856 KB Output is correct
35 Correct 287 ms 604 KB Output is correct
36 Correct 99 ms 680 KB Output is correct
37 Correct 159 ms 648 KB Output is correct
38 Correct 182 ms 604 KB Output is correct
39 Correct 191 ms 604 KB Output is correct
40 Correct 133 ms 604 KB Output is correct
41 Correct 138 ms 600 KB Output is correct
42 Correct 146 ms 604 KB Output is correct
43 Correct 111 ms 608 KB Output is correct
44 Correct 157 ms 592 KB Output is correct
45 Correct 232 ms 596 KB Output is correct
46 Correct 224 ms 612 KB Output is correct
47 Correct 147 ms 584 KB Output is correct
48 Correct 155 ms 612 KB Output is correct
49 Correct 177 ms 604 KB Output is correct
50 Correct 229 ms 604 KB Output is correct
51 Correct 141 ms 604 KB Output is correct
52 Correct 175 ms 852 KB Output is correct
53 Correct 217 ms 588 KB Output is correct
54 Correct 245 ms 600 KB Output is correct
55 Execution timed out 2048 ms 23796 KB Time limit exceeded
56 Halted 0 ms 0 KB -