Submission #527079

# Submission time Handle Problem Language Result Execution time Memory
527079 2022-02-17T00:48:40 Z jalsol Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++11
17 / 100
585 ms 21776 KB
#include <bits/stdc++.h>

using namespace std;

#define Task ""

struct __Init__ {
    __Init__() {
        cin.tie(nullptr)->sync_with_stdio(false);
        if (fopen(Task".inp", "r")) {
            freopen(Task".inp", "r", stdin);
            freopen(Task".out", "w", stdout); }
    }
} __init__;

using ll = long long;

#ifdef LOCAL
#define debug(x) cerr << "[" #x " = " << x << "]\n";
#else
#define debug(...)
#endif // LOCAL

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define fi first
#define se second

#define For(i, l, r) for (int i = (l); i <= (r); ++i)
#define Ford(i, r, l) for (int i = (r); i >= (l); --i)
#define Rep(i, n) For (i, 0, (n) - 1)
#define Repd(i, n) Ford (i, (n) - 1, 0)

template<class C> int isz(const C& c) { return c.size(); }
template<class T> bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template<class T> bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }

constexpr int eps = 1e-9;
constexpr int inf = 1e9;
constexpr ll linf = 1e18;

// =============================================================================

constexpr int maxN = 1e6 + 5;

int n, nq;
int a[maxN];
int ql[maxN];
int qr[maxN];
int qk[maxN];

struct Sub1 {
    bool test(int l, int r, int k) {
        For (i, l, r) {
            For (j, i + 1, r) {
                if (a[i] > a[j] && a[i] + a[j] > k) {
                    return false;
                }
            }
        }

        return true;
    }

    void solve() {
        For (i, 1, nq) {
            cout << test(ql[i], qr[i], qk[i]) << '\n';
        }
    }
};

struct Sub2 {
    bool test(int l, int r, int k) {
        int mx = a[l];

        For (i, l + 1, r) {
            if (mx > a[i] && mx + a[i] > k) return false;
            chmax(mx, a[i]);
        }

        return true;
    }

    void solve() {
        For (i, 1, nq) {
            cout << test(ql[i], qr[i], qk[i]) << '\n';
        }
    }
};

struct Sub3 {
    vector<pair<int, int>> seg;

    bool test(int l, int r) {
        auto it = lower_bound(all(seg), make_pair(l, -1));
        return r <= it->se;
    }

    void solve() {
        seg.reserve(n);

        For (i, 1, n) {
            int j = i;

            while (j + 1 <= n && a[j] <= a[j + 1]) {
                ++j;
            }

            seg.emplace_back(i, j);
            i = j;
        }

        For (i, 1, nq) {
            cout << test(ql[i], qr[i]) << '\n';
        }
    }
};

signed main() {
    cin >> n >> nq;
    For (i, 1, n) cin >> a[i];

    For (i, 1, nq) {
        cin >> ql[i] >> qr[i] >> qk[i];
    }

    bool sub3 = true;
    {
        int mn = *min_element(a + 1, a + n + 1);
        For (i, 1, nq) {
            sub3 &= (qk[i] < mn);
        }
    }

#define SUB(x) \
    Sub##x* sol = new Sub##x{}; \
    sol->solve(); delete sol

    if (n <= 500 && nq <= 500) {
        SUB(1);
    } else if (n <= 5000 && nq <= 5000) {
        SUB(2);
    } else if (sub3) {
        SUB(3);
    } else {
        assert(false);
    }
}

/*

*/

Compilation message

sortbooks.cpp: In constructor '__Init__::__Init__()':
sortbooks.cpp:11:20: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   11 |             freopen(Task".inp", "r", stdin);
      |             ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:12:20: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |             freopen(Task".out", "w", stdout); }
      |             ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 27 ms 348 KB Output is correct
9 Correct 8 ms 332 KB Output is correct
10 Correct 9 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 27 ms 348 KB Output is correct
9 Correct 8 ms 332 KB Output is correct
10 Correct 9 ms 348 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 2 ms 440 KB Output is correct
13 Correct 2 ms 412 KB Output is correct
14 Correct 3 ms 460 KB Output is correct
15 Correct 3 ms 460 KB Output is correct
16 Correct 13 ms 528 KB Output is correct
17 Correct 13 ms 524 KB Output is correct
18 Correct 11 ms 464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 585 ms 21776 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 28 ms 3660 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 27 ms 348 KB Output is correct
9 Correct 8 ms 332 KB Output is correct
10 Correct 9 ms 348 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 2 ms 440 KB Output is correct
13 Correct 2 ms 412 KB Output is correct
14 Correct 3 ms 460 KB Output is correct
15 Correct 3 ms 460 KB Output is correct
16 Correct 13 ms 528 KB Output is correct
17 Correct 13 ms 524 KB Output is correct
18 Correct 11 ms 464 KB Output is correct
19 Runtime error 76 ms 13472 KB Execution killed with signal 6
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 332 KB Output is correct
5 Correct 1 ms 332 KB Output is correct
6 Correct 2 ms 332 KB Output is correct
7 Correct 2 ms 332 KB Output is correct
8 Correct 27 ms 348 KB Output is correct
9 Correct 8 ms 332 KB Output is correct
10 Correct 9 ms 348 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 2 ms 440 KB Output is correct
13 Correct 2 ms 412 KB Output is correct
14 Correct 3 ms 460 KB Output is correct
15 Correct 3 ms 460 KB Output is correct
16 Correct 13 ms 528 KB Output is correct
17 Correct 13 ms 524 KB Output is correct
18 Correct 11 ms 464 KB Output is correct
19 Incorrect 585 ms 21776 KB Output isn't correct
20 Halted 0 ms 0 KB -