Submission #866612

# Submission time Handle Problem Language Result Execution time Memory
866612 2023-10-26T13:57:35 Z fanwen Alternating Heights (CCO22_day1problem1) C++17
25 / 25
196 ms 13940 KB
/**
 *      author : pham van sam 
 *      created : 26.10.2023 20:29:38
 **/

#include <bits/stdc++.h>

using namespace std;

#define MASK(x) (1LL << (x))
#define BIT(x, i) (((x) >> (i)) & 1)
#define ALL(x) (x).begin(), (x).end()
#define REP(i, n) for (int i = 0, _n = n; i < _n; ++i)
#define FOR(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
#define FORE(i, a, b) for (int i = (a), _b = (b); i < _b; ++i)
#define debug(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define file(name) if (fopen(name".inp", "r")) { freopen(name".inp", "r", stdin); freopen(name".out", "w", stdout); }

template <class A, class B> bool minimize(A &a, B b)  { if (a > b) { a = b; return true; } return false; }
template <class A, class B> bool maximize(A &a, B b)  { if (a < b) { a = b; return true; } return false; }

const int MAXN = 3e3 + 5;

int N, K, Q, A[MAXN], res[MAXN], deg_in[MAXN], vis[MAXN], exist[MAXN];
vector <int> adj[MAXN];

void dfs(int u, int &ok) {
    vis[u] = 1;
    for (auto v : adj[u]) if(vis[v] < 2) {
        if(vis[v] == 1) {
            ok = 0;
            return;
        } else {
            dfs(v, ok);
        }
    }
    vis[u] = 2;
}

bool not_cycles(int l, int r) {
    fill(adj + 1, adj + K + 1, vector <int>());
    fill(deg_in + 1, deg_in + K + 1, 0);
    fill(vis + 1, vis + K + 1, 0);
    fill(exist + 1, exist + K + 1, 0);

    FOR(i, l, r) {
        exist[A[i]] = 1;
        if(i & 1) {
            if(i + 1 <= r) {
                adj[A[i]].push_back(A[i + 1]);
                deg_in[A[i + 1]]++;
            }
            if(i - 1 >= l) {
                adj[A[i]].push_back(A[i - 1]);
                deg_in[A[i - 1]]++;
            }
        } 
        // if(l == 2 && r == 4) {
        //     if(i % 2 == 1 && i + 1 <= r) {
        //         cout << A[i] << " " << A[i + 1] << '\n';
        //     }
        //     if(i % 2 == 0 && i - 1 >= l) {
        //         cout << A[i] << " " << A[i - 1] << '\n';
        //     }
        // }
    }

    FOR(i, 1, K) if(exist[i] && !deg_in[i]) {
        int oke = true;
        dfs(i, oke);
        if(!oke) return false;
    }

    FOR(i, 1, K) if(exist[i] && !vis[i]) return false;
    return true;
}

void you_make_it(void) {
    cin >> N >> K >> Q;
    FOR(i, 1, N) cin >> A[i];

    int j = 1;
    FOR(i, 1, N) {
        while(j <= N && not_cycles(i, j)) ++j;
        res[i] = j;
        // cout << res[i] << " \n"[i == N];
    }
    while(Q--) {
        int l, r; cin >> l >> r;
        cout << (res[l] <= r ? "NO\n" : "YES\n");
    }
}

signed main() {

#ifdef LOCAL
    freopen("TASK.inp", "r", stdin);
    freopen("TASK.out", "w", stdout);
#endif
    auto start_time = chrono::steady_clock::now();

    cin.tie(0), cout.tie(0) -> sync_with_stdio(0);

    you_make_it();

    auto end_time = chrono::steady_clock::now();

    cerr << "\nExecution time : " << chrono::duration_cast <chrono::milliseconds> (end_time - start_time).count() << "[ms]" << endl;

    return (0 ^ 0);
}

// Dream it. Wish it. Do it.
# Verdict Execution time Memory Grader output
1 Correct 132 ms 12880 KB Output is correct
2 Correct 132 ms 12788 KB Output is correct
3 Correct 133 ms 12788 KB Output is correct
4 Correct 96 ms 7320 KB Output is correct
5 Correct 114 ms 9788 KB Output is correct
6 Correct 133 ms 12884 KB Output is correct
7 Correct 133 ms 12720 KB Output is correct
8 Correct 132 ms 12820 KB Output is correct
9 Correct 160 ms 12884 KB Output is correct
10 Correct 154 ms 13232 KB Output is correct
11 Correct 148 ms 13920 KB Output is correct
12 Correct 170 ms 13124 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 123 ms 11244 KB Output is correct
2 Correct 122 ms 11040 KB Output is correct
3 Correct 125 ms 11160 KB Output is correct
4 Correct 101 ms 8368 KB Output is correct
5 Correct 111 ms 9372 KB Output is correct
6 Correct 121 ms 11088 KB Output is correct
7 Correct 123 ms 11024 KB Output is correct
8 Correct 129 ms 11088 KB Output is correct
9 Correct 125 ms 11608 KB Output is correct
10 Correct 122 ms 12116 KB Output is correct
11 Correct 124 ms 12112 KB Output is correct
12 Correct 0 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 44 ms 640 KB Output is correct
3 Correct 49 ms 612 KB Output is correct
4 Correct 1 ms 600 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 29 ms 624 KB Output is correct
8 Correct 55 ms 856 KB Output is correct
9 Correct 66 ms 632 KB Output is correct
10 Correct 45 ms 604 KB Output is correct
11 Correct 64 ms 604 KB Output is correct
12 Correct 37 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 132 ms 12880 KB Output is correct
2 Correct 132 ms 12788 KB Output is correct
3 Correct 133 ms 12788 KB Output is correct
4 Correct 96 ms 7320 KB Output is correct
5 Correct 114 ms 9788 KB Output is correct
6 Correct 133 ms 12884 KB Output is correct
7 Correct 133 ms 12720 KB Output is correct
8 Correct 132 ms 12820 KB Output is correct
9 Correct 160 ms 12884 KB Output is correct
10 Correct 154 ms 13232 KB Output is correct
11 Correct 148 ms 13920 KB Output is correct
12 Correct 170 ms 13124 KB Output is correct
13 Correct 123 ms 11244 KB Output is correct
14 Correct 122 ms 11040 KB Output is correct
15 Correct 125 ms 11160 KB Output is correct
16 Correct 101 ms 8368 KB Output is correct
17 Correct 111 ms 9372 KB Output is correct
18 Correct 121 ms 11088 KB Output is correct
19 Correct 123 ms 11024 KB Output is correct
20 Correct 129 ms 11088 KB Output is correct
21 Correct 125 ms 11608 KB Output is correct
22 Correct 122 ms 12116 KB Output is correct
23 Correct 124 ms 12112 KB Output is correct
24 Correct 0 ms 344 KB Output is correct
25 Correct 0 ms 348 KB Output is correct
26 Correct 44 ms 640 KB Output is correct
27 Correct 49 ms 612 KB Output is correct
28 Correct 1 ms 600 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 29 ms 624 KB Output is correct
32 Correct 55 ms 856 KB Output is correct
33 Correct 66 ms 632 KB Output is correct
34 Correct 45 ms 604 KB Output is correct
35 Correct 64 ms 604 KB Output is correct
36 Correct 37 ms 604 KB Output is correct
37 Correct 195 ms 13572 KB Output is correct
38 Correct 178 ms 13304 KB Output is correct
39 Correct 133 ms 13076 KB Output is correct
40 Correct 110 ms 8320 KB Output is correct
41 Correct 115 ms 9876 KB Output is correct
42 Correct 168 ms 13396 KB Output is correct
43 Correct 180 ms 13692 KB Output is correct
44 Correct 158 ms 13436 KB Output is correct
45 Correct 196 ms 13904 KB Output is correct
46 Correct 193 ms 13908 KB Output is correct
47 Correct 191 ms 13940 KB Output is correct