답안 #1054646

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1054646 2024-08-12T11:21:39 Z ssense Joker (BOI20_joker) C++14
14 / 100
2000 ms 144364 KB
#include <iostream>
#include <algorithm>
#include <vector>
#include <array>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <chrono>
#include <random>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <iomanip>
#include <bitset>
#include <limits.h>
#include <cassert>
 
#define fr first
#define sc second
 
using namespace std;
 
#define int long long

const int N = (2e5)+5;

int p[N], sz[N], col[N];

stack<int> adj[N];

int find(int a)
{
    if(p[a] == a)
    {
        return a;
    }
    return find(p[a]);
}

int add_edge(int a, int b)
{
    int ca = find(a);
    int cb = find(b);
    if(ca == cb)
    {
        if(col[a] == col[b])
        {
            return -1;
        }
        return 1;
    }
    if(sz[ca] < sz[cb])
    {
        swap(a, b);
        swap(ca, cb);
    }
    sz[ca] += sz[cb];
    p[cb] = ca;
    if(col[a] != col[b])
    {
        while(!adj[cb].empty())
        {
            adj[ca].push(adj[cb].top());
            adj[cb].pop();
        }
        return 1;
    }
    while(!adj[cb].empty())
    {
        adj[ca].push(adj[cb].top());
        col[adj[cb].top()] = 1-col[adj[cb].top()];
        adj[cb].pop();
    }
    return 1;
}

void solve()
{
    int n, m, q;
    cin >> n >> m >> q;
    vector<pair<int, int> > e(m+1);
    for(int i = 1; i <= m; i++)
    {
        cin >> e[i].fr >> e[i].sc;
    }
    vector<int> bruh(m+1);
    for(int i = 1; i <= m; i++)
    {
        for(int j = 1; j <= n; j++)
        {
            p[j] = j;
            sz[j] = 1;
            col[j] = 0;
            while(!adj[j].empty())
            {
                adj[j].pop();
            }
            adj[j].push(j);
        }
        int ans = 1;
        // cout << "I : " << i << endl;
        for(int j = 1; j <= i-1; j++)
        {
             ans = min(ans, add_edge(e[j].fr, e[j].sc));
            //cout << e[j].fr << " " << e[j].sc << " " << add_edge(e[j].fr, e[j].sc) << endl;
        }
        // cout << "I: " << i << " " << ans << endl;
        // for(int i = 1; i <= n; i++)
        // {
        //     cout << col[i] << endl;
        // }
        // cout << "FIND 1 " << find(1) << endl;
        // cout << "SZ 1 " << sz[1] << endl;
        if(ans == -1)
        {
            bruh[i] = m;
            continue;
        }
        for(int j = m; j >= i; j--)
        {
            ans = min(ans, add_edge(e[j].fr, e[j].sc));
            if(ans == -1)
            {
                bruh[i] = j-1;
                break;
            }
        }
    }
    // for(int i = 1; i <= m; i++)
    // {
    //     cout << bruh[i] << " ";
    // }
    for(int i = 0; i < q; i++)
    {
        int l, r;
        cin >> l >> r;
        if(r <= bruh[l])
        {
            cout << "YES" << endl;
        }
        else
        {
            cout << "NO" << endl;
        }
    }
}
 
int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);
    int t = 1;
    while(t--)
    {
        solve();
    }
}
 
/*

*/
 
/*
#include <iostream>
#include <algorithm>
#include <vector>
#include <array>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <chrono>
#include <random>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <iomanip>
#include <bitset>
#include <cassert>
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 138064 KB Output is correct
2 Correct 48 ms 137936 KB Output is correct
3 Correct 44 ms 138068 KB Output is correct
4 Correct 46 ms 138064 KB Output is correct
5 Correct 42 ms 138068 KB Output is correct
6 Correct 42 ms 138076 KB Output is correct
7 Correct 44 ms 138076 KB Output is correct
8 Correct 48 ms 137916 KB Output is correct
9 Correct 43 ms 138064 KB Output is correct
10 Correct 47 ms 138084 KB Output is correct
11 Correct 43 ms 138076 KB Output is correct
12 Correct 44 ms 138068 KB Output is correct
13 Correct 45 ms 138064 KB Output is correct
14 Correct 47 ms 138068 KB Output is correct
15 Correct 47 ms 137928 KB Output is correct
16 Correct 45 ms 138044 KB Output is correct
17 Correct 49 ms 138064 KB Output is correct
18 Correct 44 ms 138040 KB Output is correct
19 Correct 45 ms 138072 KB Output is correct
20 Correct 43 ms 138068 KB Output is correct
21 Correct 47 ms 137876 KB Output is correct
22 Correct 42 ms 138064 KB Output is correct
23 Correct 45 ms 138068 KB Output is correct
24 Correct 43 ms 138064 KB Output is correct
25 Correct 43 ms 138068 KB Output is correct
26 Correct 46 ms 138052 KB Output is correct
27 Correct 48 ms 138068 KB Output is correct
28 Correct 43 ms 138072 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 138064 KB Output is correct
2 Correct 48 ms 137936 KB Output is correct
3 Correct 44 ms 138068 KB Output is correct
4 Correct 46 ms 138064 KB Output is correct
5 Correct 42 ms 138068 KB Output is correct
6 Correct 42 ms 138076 KB Output is correct
7 Correct 44 ms 138076 KB Output is correct
8 Correct 48 ms 137916 KB Output is correct
9 Correct 43 ms 138064 KB Output is correct
10 Correct 47 ms 138084 KB Output is correct
11 Correct 43 ms 138076 KB Output is correct
12 Correct 44 ms 138068 KB Output is correct
13 Correct 45 ms 138064 KB Output is correct
14 Correct 47 ms 138068 KB Output is correct
15 Correct 47 ms 137928 KB Output is correct
16 Correct 45 ms 138044 KB Output is correct
17 Correct 49 ms 138064 KB Output is correct
18 Correct 44 ms 138040 KB Output is correct
19 Correct 45 ms 138072 KB Output is correct
20 Correct 43 ms 138068 KB Output is correct
21 Correct 47 ms 137876 KB Output is correct
22 Correct 42 ms 138064 KB Output is correct
23 Correct 45 ms 138068 KB Output is correct
24 Correct 43 ms 138064 KB Output is correct
25 Correct 43 ms 138068 KB Output is correct
26 Correct 46 ms 138052 KB Output is correct
27 Correct 48 ms 138068 KB Output is correct
28 Correct 43 ms 138072 KB Output is correct
29 Correct 67 ms 138068 KB Output is correct
30 Correct 93 ms 138008 KB Output is correct
31 Correct 101 ms 138064 KB Output is correct
32 Correct 84 ms 138064 KB Output is correct
33 Correct 84 ms 138068 KB Output is correct
34 Correct 108 ms 138068 KB Output is correct
35 Correct 103 ms 138140 KB Output is correct
36 Correct 68 ms 138072 KB Output is correct
37 Correct 102 ms 138068 KB Output is correct
38 Correct 108 ms 138072 KB Output is correct
39 Correct 89 ms 138148 KB Output is correct
40 Correct 71 ms 138068 KB Output is correct
41 Correct 76 ms 137972 KB Output is correct
42 Correct 76 ms 138076 KB Output is correct
43 Correct 76 ms 138136 KB Output is correct
44 Correct 86 ms 137976 KB Output is correct
45 Correct 114 ms 138068 KB Output is correct
46 Correct 104 ms 138040 KB Output is correct
47 Correct 78 ms 138068 KB Output is correct
48 Correct 79 ms 138008 KB Output is correct
49 Correct 84 ms 137968 KB Output is correct
50 Correct 96 ms 138068 KB Output is correct
51 Correct 75 ms 138064 KB Output is correct
52 Correct 84 ms 138076 KB Output is correct
53 Correct 88 ms 138064 KB Output is correct
54 Correct 99 ms 138064 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 138064 KB Output is correct
2 Correct 48 ms 137936 KB Output is correct
3 Execution timed out 2076 ms 144212 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 138064 KB Output is correct
2 Correct 48 ms 137936 KB Output is correct
3 Correct 44 ms 138068 KB Output is correct
4 Correct 46 ms 138064 KB Output is correct
5 Correct 42 ms 138068 KB Output is correct
6 Correct 42 ms 138076 KB Output is correct
7 Correct 44 ms 138076 KB Output is correct
8 Correct 48 ms 137916 KB Output is correct
9 Correct 43 ms 138064 KB Output is correct
10 Correct 47 ms 138084 KB Output is correct
11 Correct 43 ms 138076 KB Output is correct
12 Correct 44 ms 138068 KB Output is correct
13 Correct 45 ms 138064 KB Output is correct
14 Correct 47 ms 138068 KB Output is correct
15 Correct 47 ms 137928 KB Output is correct
16 Correct 45 ms 138044 KB Output is correct
17 Correct 49 ms 138064 KB Output is correct
18 Correct 44 ms 138040 KB Output is correct
19 Correct 45 ms 138072 KB Output is correct
20 Correct 43 ms 138068 KB Output is correct
21 Correct 47 ms 137876 KB Output is correct
22 Correct 42 ms 138064 KB Output is correct
23 Correct 45 ms 138068 KB Output is correct
24 Correct 43 ms 138064 KB Output is correct
25 Correct 43 ms 138068 KB Output is correct
26 Correct 46 ms 138052 KB Output is correct
27 Correct 48 ms 138068 KB Output is correct
28 Correct 43 ms 138072 KB Output is correct
29 Execution timed out 2076 ms 144212 KB Time limit exceeded
30 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 138064 KB Output is correct
2 Correct 48 ms 137936 KB Output is correct
3 Correct 44 ms 138068 KB Output is correct
4 Correct 46 ms 138064 KB Output is correct
5 Correct 42 ms 138068 KB Output is correct
6 Correct 42 ms 138076 KB Output is correct
7 Correct 44 ms 138076 KB Output is correct
8 Correct 48 ms 137916 KB Output is correct
9 Correct 43 ms 138064 KB Output is correct
10 Correct 47 ms 138084 KB Output is correct
11 Correct 43 ms 138076 KB Output is correct
12 Correct 44 ms 138068 KB Output is correct
13 Correct 45 ms 138064 KB Output is correct
14 Correct 47 ms 138068 KB Output is correct
15 Correct 47 ms 137928 KB Output is correct
16 Correct 45 ms 138044 KB Output is correct
17 Correct 49 ms 138064 KB Output is correct
18 Correct 44 ms 138040 KB Output is correct
19 Correct 45 ms 138072 KB Output is correct
20 Correct 43 ms 138068 KB Output is correct
21 Correct 47 ms 137876 KB Output is correct
22 Correct 42 ms 138064 KB Output is correct
23 Correct 45 ms 138068 KB Output is correct
24 Correct 43 ms 138064 KB Output is correct
25 Correct 43 ms 138068 KB Output is correct
26 Correct 46 ms 138052 KB Output is correct
27 Correct 48 ms 138068 KB Output is correct
28 Correct 43 ms 138072 KB Output is correct
29 Correct 67 ms 138068 KB Output is correct
30 Correct 93 ms 138008 KB Output is correct
31 Correct 101 ms 138064 KB Output is correct
32 Correct 84 ms 138064 KB Output is correct
33 Correct 84 ms 138068 KB Output is correct
34 Correct 108 ms 138068 KB Output is correct
35 Correct 103 ms 138140 KB Output is correct
36 Correct 68 ms 138072 KB Output is correct
37 Correct 102 ms 138068 KB Output is correct
38 Correct 108 ms 138072 KB Output is correct
39 Correct 89 ms 138148 KB Output is correct
40 Correct 71 ms 138068 KB Output is correct
41 Correct 76 ms 137972 KB Output is correct
42 Correct 76 ms 138076 KB Output is correct
43 Correct 76 ms 138136 KB Output is correct
44 Correct 86 ms 137976 KB Output is correct
45 Correct 114 ms 138068 KB Output is correct
46 Correct 104 ms 138040 KB Output is correct
47 Correct 78 ms 138068 KB Output is correct
48 Correct 79 ms 138008 KB Output is correct
49 Correct 84 ms 137968 KB Output is correct
50 Correct 96 ms 138068 KB Output is correct
51 Correct 75 ms 138064 KB Output is correct
52 Correct 84 ms 138076 KB Output is correct
53 Correct 88 ms 138064 KB Output is correct
54 Correct 99 ms 138064 KB Output is correct
55 Execution timed out 2068 ms 144364 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 138064 KB Output is correct
2 Correct 48 ms 137936 KB Output is correct
3 Correct 44 ms 138068 KB Output is correct
4 Correct 46 ms 138064 KB Output is correct
5 Correct 42 ms 138068 KB Output is correct
6 Correct 42 ms 138076 KB Output is correct
7 Correct 44 ms 138076 KB Output is correct
8 Correct 48 ms 137916 KB Output is correct
9 Correct 43 ms 138064 KB Output is correct
10 Correct 47 ms 138084 KB Output is correct
11 Correct 43 ms 138076 KB Output is correct
12 Correct 44 ms 138068 KB Output is correct
13 Correct 45 ms 138064 KB Output is correct
14 Correct 47 ms 138068 KB Output is correct
15 Correct 47 ms 137928 KB Output is correct
16 Correct 45 ms 138044 KB Output is correct
17 Correct 49 ms 138064 KB Output is correct
18 Correct 44 ms 138040 KB Output is correct
19 Correct 45 ms 138072 KB Output is correct
20 Correct 43 ms 138068 KB Output is correct
21 Correct 47 ms 137876 KB Output is correct
22 Correct 42 ms 138064 KB Output is correct
23 Correct 45 ms 138068 KB Output is correct
24 Correct 43 ms 138064 KB Output is correct
25 Correct 43 ms 138068 KB Output is correct
26 Correct 46 ms 138052 KB Output is correct
27 Correct 48 ms 138068 KB Output is correct
28 Correct 43 ms 138072 KB Output is correct
29 Correct 67 ms 138068 KB Output is correct
30 Correct 93 ms 138008 KB Output is correct
31 Correct 101 ms 138064 KB Output is correct
32 Correct 84 ms 138064 KB Output is correct
33 Correct 84 ms 138068 KB Output is correct
34 Correct 108 ms 138068 KB Output is correct
35 Correct 103 ms 138140 KB Output is correct
36 Correct 68 ms 138072 KB Output is correct
37 Correct 102 ms 138068 KB Output is correct
38 Correct 108 ms 138072 KB Output is correct
39 Correct 89 ms 138148 KB Output is correct
40 Correct 71 ms 138068 KB Output is correct
41 Correct 76 ms 137972 KB Output is correct
42 Correct 76 ms 138076 KB Output is correct
43 Correct 76 ms 138136 KB Output is correct
44 Correct 86 ms 137976 KB Output is correct
45 Correct 114 ms 138068 KB Output is correct
46 Correct 104 ms 138040 KB Output is correct
47 Correct 78 ms 138068 KB Output is correct
48 Correct 79 ms 138008 KB Output is correct
49 Correct 84 ms 137968 KB Output is correct
50 Correct 96 ms 138068 KB Output is correct
51 Correct 75 ms 138064 KB Output is correct
52 Correct 84 ms 138076 KB Output is correct
53 Correct 88 ms 138064 KB Output is correct
54 Correct 99 ms 138064 KB Output is correct
55 Execution timed out 2076 ms 144212 KB Time limit exceeded
56 Halted 0 ms 0 KB -