Submission #1211173

#TimeUsernameProblemLanguageResultExecution timeMemory
1211173fafnirComparing Plants (IOI20_plants)C++20
0 / 100
0 ms328 KiB
#include <bits/stdc++.h>

// #define LOCAL

using namespace std;

const int NMAX = 200'001;

int n,k,q;
int r[NMAX];

void init(int kl, vector<int> rl) {
    n = rl.size();
    k = kl;
    for (int i = 0; i < n; ++i) {
        r[i] = rl[i];
    }
}

// x, y: Labels of plants
//  Return:
//      1:   x taller than plant y
//     -1:   x smaller than plant y
//      0:   inconclusive
int compare_plants(int x, int y) {
    bool swapped = x > y;
    if (swapped) {swap(x,y);}


    bool rgeq = r[y];
    int idx0 = y;
    while (idx0 != x) {
        rgeq = rgeq && r[idx0];
        idx0 = (idx0+1) % n; 
    }

    bool lgeq = r[x];
    int idx1 = x;
    while (idx1 != y) {
        lgeq = lgeq && r[idx1];
        idx1 = (idx1+1) % n; 
    }

    // x > y
    if (rgeq) {
        return swapped ? -1 : 1;
    } else if (lgeq) {
        return swapped ? 1 : -1;
    }


    return 0;
}

#ifdef LOCAL

int32_t main() {

    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    int nl, kl, ql;
    cin >> nl >> kl >> ql;

    vector<int> rl(nl);
    for (auto& e : rl) cin >> e;

    init(kl, rl);

    for (int _ = 0; _ < ql; _++) {
        int x, y;
        cin >> x >> y;
        cout << compare_plants(x, y);
        if (_ < ql-1) cout << '\n';
    }

    return 0;
}

#endif
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...