답안 #1045343

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1045343 2024-08-05T20:51:00 Z Lobo Joker (BOI20_joker) C++17
14 / 100
2000 ms 26708 KB
#include<bits/stdc++.h>
using namespace std;
const long long inf = 1e9 + 10;
// #define int long long
#define dbl long double
#define endl '\n'
#define sc second
#define fr first
#define mp make_pair
#define pb push_back
#define all(x) x.begin(), x.end()
mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());
const int maxn = 2e5+10;
const int B = 500;
int n, m, q, col[maxn], colc[2*maxn], ansl[maxn];
vector<int> g[maxn], gc[2*maxn]; 
pair<int,int> edg[maxn];

    int cnt = 0;
bool okcol;
void dfscol(int u) {
    for(auto v : g[u]) {
        if(col[v] == -1) {
            col[v] = (col[u]^1);
            dfscol(v);
        }
        else if(col[v] != (col[u]^1)) {
            okcol = 0;
        }
    }
}
bool okcolc;
void dfscolc(int u) {
    for(auto v : gc[u]) {
        if(colc[v] == -1) {
            colc[v] = (colc[u]^1);
            dfscolc(v);
        }
        else if(colc[v] != (colc[u]^1)) {
            okcolc = 0;
        }
    }
}

void solve() {
    cin >> n >> m >> q;
    for(int i = 1; i <= m; i++) {
        int u,v;
        cin >> u >> v;
        edg[i] = mp(u,v);
    }

    int bLl = 0;
    int bLr = min(m+1,B-1);
    int bRl = 1;
    int bRr = min(m+1,B);
    while(bLl != m+1) {
        for(int i = 1; i <= n; i++) {
            g[i].clear();
            col[i] = -1;
        }
        for(int i = 1; i <= bLl-1; i++) {
            int u = edg[i].fr;
            int v = edg[i].sc;
            g[u].pb(v);
            g[v].pb(u);
        }
        for(int i = bRr+1; i <= m; i++) {
            int u = edg[i].fr;
            int v = edg[i].sc;
            g[u].pb(v);
            g[v].pb(u);
        }
        int cntcol = 0;
        okcol = 1;
        for(int i = 1; i <= n; i++) {
            if(col[i] == -1) {
                colc[cntcol] = -1;
                colc[cntcol+1] = -1;
                col[i] = cntcol;
                cntcol = cntcol+2;
                dfscol(i);
            }
        }
        int L = bLl;
        int R = bRl;

        while(L <= bLr and R <= bRr) {
            vector<int> verts;
            for(int i = bLl; i <= L; i++) {
                if(i == 0 or i == m+1) continue;
                int u = edg[i].fr; verts.pb(col[u]); verts.pb((col[u]^1));
                int v = edg[i].sc; verts.pb(col[v]); verts.pb((col[v]^1));
                gc[col[u]].pb(col[v]);
                gc[col[v]].pb(col[u]);
            }
            for(int i = R; i <= bRr; i++) {
                if(i == 0 or i == m+1) continue;
                int u = edg[i].fr; verts.pb(col[u]); verts.pb((col[u]^1));
                int v = edg[i].sc; verts.pb(col[v]); verts.pb((col[v]^1));
                gc[col[u]].pb(col[v]);
                gc[col[v]].pb(col[u]);
            }
            for(auto i : verts) {
                gc[i].pb((i^1));
            }
            okcolc = 1;
            for(auto i : verts) {
                if(colc[i] == -1) {
                    colc[i] = 0;
                    dfscolc(i);
                }
            }
            if(okcolc == 1 and okcol == 1) {
                ansl[L] = R;
                L++;
            }
            else if(R == m+1) {
                ansl[L] = inf;
                L++;
            }
            else {
                R++;
            }

            for(auto i : verts) {
                colc[i] = -1;
                gc[i].clear();
            }
        }

        bLl = min(m+1,L);
        bLr = (min(m+1,bLl+B-1));
        bRl = min(m+1,R);
        bRr = min(m+1,bRl+B-1);
    }
    // cout << cnt << endl;
    for(int i = 1; i <= q; i++) {
        int l,r;
        cin >> l >> r;
        if(ansl[l-1] <= r+1) {
            cout << "NO" << endl;
        }
        else {
            cout << "YES" << endl;
        }
    }
}

int32_t main() {
    ios::sync_with_stdio(false); cin.tie(0);

    int tt = 1;
    // cin >> tt;
    while(tt--) {
        solve();
    }

}

# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 18780 KB Output is correct
2 Correct 2 ms 18780 KB Output is correct
3 Correct 2 ms 18780 KB Output is correct
4 Correct 2 ms 18780 KB Output is correct
5 Correct 2 ms 18780 KB Output is correct
6 Correct 2 ms 18780 KB Output is correct
7 Correct 3 ms 18956 KB Output is correct
8 Correct 4 ms 18780 KB Output is correct
9 Correct 4 ms 18780 KB Output is correct
10 Correct 3 ms 18780 KB Output is correct
11 Correct 3 ms 18872 KB Output is correct
12 Correct 4 ms 18780 KB Output is correct
13 Correct 4 ms 18780 KB Output is correct
14 Correct 4 ms 18776 KB Output is correct
15 Correct 5 ms 18780 KB Output is correct
16 Correct 4 ms 18900 KB Output is correct
17 Correct 4 ms 18780 KB Output is correct
18 Correct 4 ms 18780 KB Output is correct
19 Correct 4 ms 18792 KB Output is correct
20 Correct 4 ms 18780 KB Output is correct
21 Correct 3 ms 18780 KB Output is correct
22 Correct 4 ms 18780 KB Output is correct
23 Correct 4 ms 18780 KB Output is correct
24 Correct 4 ms 18952 KB Output is correct
25 Correct 4 ms 18956 KB Output is correct
26 Correct 5 ms 18780 KB Output is correct
27 Correct 3 ms 18780 KB Output is correct
28 Correct 4 ms 18780 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 18780 KB Output is correct
2 Correct 2 ms 18780 KB Output is correct
3 Correct 2 ms 18780 KB Output is correct
4 Correct 2 ms 18780 KB Output is correct
5 Correct 2 ms 18780 KB Output is correct
6 Correct 2 ms 18780 KB Output is correct
7 Correct 3 ms 18956 KB Output is correct
8 Correct 4 ms 18780 KB Output is correct
9 Correct 4 ms 18780 KB Output is correct
10 Correct 3 ms 18780 KB Output is correct
11 Correct 3 ms 18872 KB Output is correct
12 Correct 4 ms 18780 KB Output is correct
13 Correct 4 ms 18780 KB Output is correct
14 Correct 4 ms 18776 KB Output is correct
15 Correct 5 ms 18780 KB Output is correct
16 Correct 4 ms 18900 KB Output is correct
17 Correct 4 ms 18780 KB Output is correct
18 Correct 4 ms 18780 KB Output is correct
19 Correct 4 ms 18792 KB Output is correct
20 Correct 4 ms 18780 KB Output is correct
21 Correct 3 ms 18780 KB Output is correct
22 Correct 4 ms 18780 KB Output is correct
23 Correct 4 ms 18780 KB Output is correct
24 Correct 4 ms 18952 KB Output is correct
25 Correct 4 ms 18956 KB Output is correct
26 Correct 5 ms 18780 KB Output is correct
27 Correct 3 ms 18780 KB Output is correct
28 Correct 4 ms 18780 KB Output is correct
29 Correct 34 ms 19032 KB Output is correct
30 Correct 45 ms 19072 KB Output is correct
31 Correct 52 ms 19116 KB Output is correct
32 Correct 39 ms 19068 KB Output is correct
33 Correct 32 ms 19060 KB Output is correct
34 Correct 40 ms 19036 KB Output is correct
35 Correct 52 ms 19032 KB Output is correct
36 Correct 49 ms 19084 KB Output is correct
37 Correct 50 ms 19032 KB Output is correct
38 Correct 48 ms 19036 KB Output is correct
39 Correct 43 ms 19132 KB Output is correct
40 Correct 35 ms 19032 KB Output is correct
41 Correct 33 ms 19036 KB Output is correct
42 Correct 34 ms 19072 KB Output is correct
43 Correct 33 ms 19032 KB Output is correct
44 Correct 45 ms 19036 KB Output is correct
45 Correct 45 ms 19100 KB Output is correct
46 Correct 54 ms 19032 KB Output is correct
47 Correct 47 ms 19032 KB Output is correct
48 Correct 43 ms 19116 KB Output is correct
49 Correct 51 ms 19108 KB Output is correct
50 Correct 63 ms 19032 KB Output is correct
51 Correct 35 ms 19100 KB Output is correct
52 Correct 44 ms 19124 KB Output is correct
53 Correct 44 ms 19116 KB Output is correct
54 Correct 52 ms 19036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 18780 KB Output is correct
2 Correct 2 ms 18780 KB Output is correct
3 Execution timed out 2033 ms 25260 KB Time limit exceeded
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 18780 KB Output is correct
2 Correct 2 ms 18780 KB Output is correct
3 Correct 2 ms 18780 KB Output is correct
4 Correct 2 ms 18780 KB Output is correct
5 Correct 2 ms 18780 KB Output is correct
6 Correct 2 ms 18780 KB Output is correct
7 Correct 3 ms 18956 KB Output is correct
8 Correct 4 ms 18780 KB Output is correct
9 Correct 4 ms 18780 KB Output is correct
10 Correct 3 ms 18780 KB Output is correct
11 Correct 3 ms 18872 KB Output is correct
12 Correct 4 ms 18780 KB Output is correct
13 Correct 4 ms 18780 KB Output is correct
14 Correct 4 ms 18776 KB Output is correct
15 Correct 5 ms 18780 KB Output is correct
16 Correct 4 ms 18900 KB Output is correct
17 Correct 4 ms 18780 KB Output is correct
18 Correct 4 ms 18780 KB Output is correct
19 Correct 4 ms 18792 KB Output is correct
20 Correct 4 ms 18780 KB Output is correct
21 Correct 3 ms 18780 KB Output is correct
22 Correct 4 ms 18780 KB Output is correct
23 Correct 4 ms 18780 KB Output is correct
24 Correct 4 ms 18952 KB Output is correct
25 Correct 4 ms 18956 KB Output is correct
26 Correct 5 ms 18780 KB Output is correct
27 Correct 3 ms 18780 KB Output is correct
28 Correct 4 ms 18780 KB Output is correct
29 Execution timed out 2033 ms 25260 KB Time limit exceeded
30 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 18780 KB Output is correct
2 Correct 2 ms 18780 KB Output is correct
3 Correct 2 ms 18780 KB Output is correct
4 Correct 2 ms 18780 KB Output is correct
5 Correct 2 ms 18780 KB Output is correct
6 Correct 2 ms 18780 KB Output is correct
7 Correct 3 ms 18956 KB Output is correct
8 Correct 4 ms 18780 KB Output is correct
9 Correct 4 ms 18780 KB Output is correct
10 Correct 3 ms 18780 KB Output is correct
11 Correct 3 ms 18872 KB Output is correct
12 Correct 4 ms 18780 KB Output is correct
13 Correct 4 ms 18780 KB Output is correct
14 Correct 4 ms 18776 KB Output is correct
15 Correct 5 ms 18780 KB Output is correct
16 Correct 4 ms 18900 KB Output is correct
17 Correct 4 ms 18780 KB Output is correct
18 Correct 4 ms 18780 KB Output is correct
19 Correct 4 ms 18792 KB Output is correct
20 Correct 4 ms 18780 KB Output is correct
21 Correct 3 ms 18780 KB Output is correct
22 Correct 4 ms 18780 KB Output is correct
23 Correct 4 ms 18780 KB Output is correct
24 Correct 4 ms 18952 KB Output is correct
25 Correct 4 ms 18956 KB Output is correct
26 Correct 5 ms 18780 KB Output is correct
27 Correct 3 ms 18780 KB Output is correct
28 Correct 4 ms 18780 KB Output is correct
29 Correct 34 ms 19032 KB Output is correct
30 Correct 45 ms 19072 KB Output is correct
31 Correct 52 ms 19116 KB Output is correct
32 Correct 39 ms 19068 KB Output is correct
33 Correct 32 ms 19060 KB Output is correct
34 Correct 40 ms 19036 KB Output is correct
35 Correct 52 ms 19032 KB Output is correct
36 Correct 49 ms 19084 KB Output is correct
37 Correct 50 ms 19032 KB Output is correct
38 Correct 48 ms 19036 KB Output is correct
39 Correct 43 ms 19132 KB Output is correct
40 Correct 35 ms 19032 KB Output is correct
41 Correct 33 ms 19036 KB Output is correct
42 Correct 34 ms 19072 KB Output is correct
43 Correct 33 ms 19032 KB Output is correct
44 Correct 45 ms 19036 KB Output is correct
45 Correct 45 ms 19100 KB Output is correct
46 Correct 54 ms 19032 KB Output is correct
47 Correct 47 ms 19032 KB Output is correct
48 Correct 43 ms 19116 KB Output is correct
49 Correct 51 ms 19108 KB Output is correct
50 Correct 63 ms 19032 KB Output is correct
51 Correct 35 ms 19100 KB Output is correct
52 Correct 44 ms 19124 KB Output is correct
53 Correct 44 ms 19116 KB Output is correct
54 Correct 52 ms 19036 KB Output is correct
55 Execution timed out 2053 ms 26708 KB Time limit exceeded
56 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 18780 KB Output is correct
2 Correct 2 ms 18780 KB Output is correct
3 Correct 2 ms 18780 KB Output is correct
4 Correct 2 ms 18780 KB Output is correct
5 Correct 2 ms 18780 KB Output is correct
6 Correct 2 ms 18780 KB Output is correct
7 Correct 3 ms 18956 KB Output is correct
8 Correct 4 ms 18780 KB Output is correct
9 Correct 4 ms 18780 KB Output is correct
10 Correct 3 ms 18780 KB Output is correct
11 Correct 3 ms 18872 KB Output is correct
12 Correct 4 ms 18780 KB Output is correct
13 Correct 4 ms 18780 KB Output is correct
14 Correct 4 ms 18776 KB Output is correct
15 Correct 5 ms 18780 KB Output is correct
16 Correct 4 ms 18900 KB Output is correct
17 Correct 4 ms 18780 KB Output is correct
18 Correct 4 ms 18780 KB Output is correct
19 Correct 4 ms 18792 KB Output is correct
20 Correct 4 ms 18780 KB Output is correct
21 Correct 3 ms 18780 KB Output is correct
22 Correct 4 ms 18780 KB Output is correct
23 Correct 4 ms 18780 KB Output is correct
24 Correct 4 ms 18952 KB Output is correct
25 Correct 4 ms 18956 KB Output is correct
26 Correct 5 ms 18780 KB Output is correct
27 Correct 3 ms 18780 KB Output is correct
28 Correct 4 ms 18780 KB Output is correct
29 Correct 34 ms 19032 KB Output is correct
30 Correct 45 ms 19072 KB Output is correct
31 Correct 52 ms 19116 KB Output is correct
32 Correct 39 ms 19068 KB Output is correct
33 Correct 32 ms 19060 KB Output is correct
34 Correct 40 ms 19036 KB Output is correct
35 Correct 52 ms 19032 KB Output is correct
36 Correct 49 ms 19084 KB Output is correct
37 Correct 50 ms 19032 KB Output is correct
38 Correct 48 ms 19036 KB Output is correct
39 Correct 43 ms 19132 KB Output is correct
40 Correct 35 ms 19032 KB Output is correct
41 Correct 33 ms 19036 KB Output is correct
42 Correct 34 ms 19072 KB Output is correct
43 Correct 33 ms 19032 KB Output is correct
44 Correct 45 ms 19036 KB Output is correct
45 Correct 45 ms 19100 KB Output is correct
46 Correct 54 ms 19032 KB Output is correct
47 Correct 47 ms 19032 KB Output is correct
48 Correct 43 ms 19116 KB Output is correct
49 Correct 51 ms 19108 KB Output is correct
50 Correct 63 ms 19032 KB Output is correct
51 Correct 35 ms 19100 KB Output is correct
52 Correct 44 ms 19124 KB Output is correct
53 Correct 44 ms 19116 KB Output is correct
54 Correct 52 ms 19036 KB Output is correct
55 Execution timed out 2033 ms 25260 KB Time limit exceeded
56 Halted 0 ms 0 KB -