답안 #1038357

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1038357 2024-07-29T17:30:00 Z amine_aroua Joker (BOI20_joker) C++17
14 / 100
2000 ms 16856 KB
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx2")
vector<pair<int ,int>> edges;
struct DSU
{
    vector<int> e;
    vector<int> col;
    vector<vector<int>> children;
    bool bip;
    vector<vector<int>> hist;
    void init(int n)
    {
        bip = 1;
        e.assign(n , -1);
        col.assign(n , 0);
        children.assign(n , {});
        for(int i = 0 ; i < n ;i++)
        {
            e[i] = i;
            children[i].push_back(i);
        }
    }
    int get(int x)
    {
        return e[x];
    }
    bool is_bip()
    {
        return bip;
    }
    void unite(int u , int v)
    {
        if(u == v)
            return ;
        bool same_col = col[u] == col[v];
        u = get(u) , v = get(v);
        if(u == v)
        {
            hist.push_back({-1 , -1,-1 ,same_col ,bip});
            if(same_col)
            {
                bip = 0;
            }
            return ;
        }
        if((int)children[u].size() < (int)children[v].size())
        {
            swap(u , v);
        }
        hist.push_back({u , v, (int)children[v].size(),same_col, bip});
        while(!children[v].empty())
        {
            auto node = children[v].back();
            children[v].pop_back();
            e[node] = u;
            col[node]^=same_col;
            children[u].push_back(node);
        }
    }
    void roll_back()
    {
        auto last = hist.back();
        hist.pop_back();
        if(last[0] == -1)
        {
            bip = last.back();
        }
        else
        {
            for(int i = 0 ; i < last[2] ; i++)
            {
                auto tp = children[last[0]].back();
                children[last[0]].pop_back();
                e[tp] = last[1];
                children[last[1]].push_back(tp);
                col[tp]^=last[3];
            }
        }
    }
    void roll_back(int x)
    {
        while (x--)
        {
            roll_back();
        }
        
    }
    void clear()
    {
        roll_back((int)hist.size());
    }
}dsu;
int n , m , q;
vector<int> nxt;
void solve(int l , int r , int optl , int optr)
{
    if(l > r)
        return ;
    int mid = (l + r)/2;
    int ops = 0;
    for(int i = l ; i < mid ; i++)
    {
        ops++;
        dsu.unite(edges[i].first , edges[i].second);
    }
    int opt = optr;
    for(int i = optr ; i >= max(mid , optl) ; i--)
    {
        if(!dsu.is_bip())
        {
            break;
        }
        opt = i;
        if(i < m)
        {
            ops++;
            dsu.unite(edges[i].first , edges[i].second);
        }
    }
    nxt[mid] = opt;
    dsu.roll_back(ops);
    ops = 0;
    for(int i = opt + 1 ; i <= optr ;i++)
    {
        if(i < m)
        {
            dsu.unite(edges[i].first , edges[i].second);
            ops++;
        }
    }
    solve(l , mid - 1 , optl , opt);
    dsu.roll_back(ops);
    ops = 0;
    for(int i = l ; i <= mid ; i++)
    {
        ops++;
        dsu.unite(edges[i].first , edges[i].second);
    }
    solve(mid + 1 , r , opt , optr);
    dsu.roll_back(ops);
    ops = 0;
}
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n>>m>>q;
    nxt.assign(m , m);
    dsu.init(n);
    for(int i = 0 ; i < m ; i++)
    {
        int u , v;
        cin>>u>>v;
        u-- , v--;
        edges.push_back({u , v});
    }
    solve(0 , m - 1 , 0 , m);
    for(int i = 0 ; i< q; i++)
    {
        int l , r;
        cin>>l>>r;
        l-- , r--;
        if(nxt[l] <= r)
        {
            cout<<"NO\n";
        }
        else
        {
            cout<<"YES\n";
        }
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 376 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 480 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 376 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 480 KB Output is correct
29 Correct 3 ms 600 KB Output is correct
30 Correct 3 ms 604 KB Output is correct
31 Correct 3 ms 604 KB Output is correct
32 Correct 2 ms 604 KB Output is correct
33 Correct 2 ms 604 KB Output is correct
34 Correct 3 ms 600 KB Output is correct
35 Correct 4 ms 604 KB Output is correct
36 Correct 6 ms 600 KB Output is correct
37 Correct 4 ms 604 KB Output is correct
38 Correct 9 ms 760 KB Output is correct
39 Correct 2 ms 604 KB Output is correct
40 Correct 2 ms 604 KB Output is correct
41 Correct 3 ms 604 KB Output is correct
42 Correct 4 ms 640 KB Output is correct
43 Correct 2 ms 604 KB Output is correct
44 Correct 3 ms 604 KB Output is correct
45 Correct 3 ms 604 KB Output is correct
46 Correct 3 ms 604 KB Output is correct
47 Correct 2 ms 604 KB Output is correct
48 Correct 3 ms 604 KB Output is correct
49 Correct 3 ms 696 KB Output is correct
50 Correct 3 ms 604 KB Output is correct
51 Correct 3 ms 604 KB Output is correct
52 Correct 4 ms 604 KB Output is correct
53 Correct 3 ms 604 KB Output is correct
54 Correct 4 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Execution timed out 2077 ms 16528 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 376 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 480 KB Output is correct
29 Execution timed out 2077 ms 16528 KB Time limit exceeded
30 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 376 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 480 KB Output is correct
29 Correct 3 ms 600 KB Output is correct
30 Correct 3 ms 604 KB Output is correct
31 Correct 3 ms 604 KB Output is correct
32 Correct 2 ms 604 KB Output is correct
33 Correct 2 ms 604 KB Output is correct
34 Correct 3 ms 600 KB Output is correct
35 Correct 4 ms 604 KB Output is correct
36 Correct 6 ms 600 KB Output is correct
37 Correct 4 ms 604 KB Output is correct
38 Correct 9 ms 760 KB Output is correct
39 Correct 2 ms 604 KB Output is correct
40 Correct 2 ms 604 KB Output is correct
41 Correct 3 ms 604 KB Output is correct
42 Correct 4 ms 640 KB Output is correct
43 Correct 2 ms 604 KB Output is correct
44 Correct 3 ms 604 KB Output is correct
45 Correct 3 ms 604 KB Output is correct
46 Correct 3 ms 604 KB Output is correct
47 Correct 2 ms 604 KB Output is correct
48 Correct 3 ms 604 KB Output is correct
49 Correct 3 ms 696 KB Output is correct
50 Correct 3 ms 604 KB Output is correct
51 Correct 3 ms 604 KB Output is correct
52 Correct 4 ms 604 KB Output is correct
53 Correct 3 ms 604 KB Output is correct
54 Correct 4 ms 604 KB Output is correct
55 Execution timed out 2043 ms 16856 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 376 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 1 ms 348 KB Output is correct
14 Correct 1 ms 348 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 1 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 344 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 0 ms 348 KB Output is correct
28 Correct 0 ms 480 KB Output is correct
29 Correct 3 ms 600 KB Output is correct
30 Correct 3 ms 604 KB Output is correct
31 Correct 3 ms 604 KB Output is correct
32 Correct 2 ms 604 KB Output is correct
33 Correct 2 ms 604 KB Output is correct
34 Correct 3 ms 600 KB Output is correct
35 Correct 4 ms 604 KB Output is correct
36 Correct 6 ms 600 KB Output is correct
37 Correct 4 ms 604 KB Output is correct
38 Correct 9 ms 760 KB Output is correct
39 Correct 2 ms 604 KB Output is correct
40 Correct 2 ms 604 KB Output is correct
41 Correct 3 ms 604 KB Output is correct
42 Correct 4 ms 640 KB Output is correct
43 Correct 2 ms 604 KB Output is correct
44 Correct 3 ms 604 KB Output is correct
45 Correct 3 ms 604 KB Output is correct
46 Correct 3 ms 604 KB Output is correct
47 Correct 2 ms 604 KB Output is correct
48 Correct 3 ms 604 KB Output is correct
49 Correct 3 ms 696 KB Output is correct
50 Correct 3 ms 604 KB Output is correct
51 Correct 3 ms 604 KB Output is correct
52 Correct 4 ms 604 KB Output is correct
53 Correct 3 ms 604 KB Output is correct
54 Correct 4 ms 604 KB Output is correct
55 Execution timed out 2077 ms 16528 KB Time limit exceeded
56 Halted 0 ms 0 KB -