Submission #527080

# Submission time Handle Problem Language Result Execution time Memory
527080 2022-02-17T01:00:03 Z jalsol Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++11
30 / 100
608 ms 54812 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 = upper_bound(all(seg), make_pair(l, inf));
        if (it == seg.begin()) return false;

        --it;
        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 1 ms 336 KB Output is correct
2 Correct 1 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 1 ms 332 KB Output is correct
7 Correct 2 ms 236 KB Output is correct
8 Correct 22 ms 340 KB Output is correct
9 Correct 7 ms 332 KB Output is correct
10 Correct 9 ms 352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 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 1 ms 332 KB Output is correct
7 Correct 2 ms 236 KB Output is correct
8 Correct 22 ms 340 KB Output is correct
9 Correct 7 ms 332 KB Output is correct
10 Correct 9 ms 352 KB Output is correct
11 Correct 3 ms 332 KB Output is correct
12 Correct 2 ms 460 KB Output is correct
13 Correct 4 ms 460 KB Output is correct
14 Correct 3 ms 460 KB Output is correct
15 Correct 4 ms 460 KB Output is correct
16 Correct 14 ms 460 KB Output is correct
17 Correct 15 ms 460 KB Output is correct
18 Correct 12 ms 464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 565 ms 21888 KB Output is correct
2 Correct 581 ms 54812 KB Output is correct
3 Correct 608 ms 54640 KB Output is correct
4 Correct 603 ms 54716 KB Output is correct
5 Correct 467 ms 50848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 28 ms 3908 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 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 1 ms 332 KB Output is correct
7 Correct 2 ms 236 KB Output is correct
8 Correct 22 ms 340 KB Output is correct
9 Correct 7 ms 332 KB Output is correct
10 Correct 9 ms 352 KB Output is correct
11 Correct 3 ms 332 KB Output is correct
12 Correct 2 ms 460 KB Output is correct
13 Correct 4 ms 460 KB Output is correct
14 Correct 3 ms 460 KB Output is correct
15 Correct 4 ms 460 KB Output is correct
16 Correct 14 ms 460 KB Output is correct
17 Correct 15 ms 460 KB Output is correct
18 Correct 12 ms 464 KB Output is correct
19 Runtime error 75 ms 7260 KB Execution killed with signal 6
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 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 1 ms 332 KB Output is correct
7 Correct 2 ms 236 KB Output is correct
8 Correct 22 ms 340 KB Output is correct
9 Correct 7 ms 332 KB Output is correct
10 Correct 9 ms 352 KB Output is correct
11 Correct 3 ms 332 KB Output is correct
12 Correct 2 ms 460 KB Output is correct
13 Correct 4 ms 460 KB Output is correct
14 Correct 3 ms 460 KB Output is correct
15 Correct 4 ms 460 KB Output is correct
16 Correct 14 ms 460 KB Output is correct
17 Correct 15 ms 460 KB Output is correct
18 Correct 12 ms 464 KB Output is correct
19 Correct 565 ms 21888 KB Output is correct
20 Correct 581 ms 54812 KB Output is correct
21 Correct 608 ms 54640 KB Output is correct
22 Correct 603 ms 54716 KB Output is correct
23 Correct 467 ms 50848 KB Output is correct
24 Runtime error 28 ms 3908 KB Execution killed with signal 6
25 Halted 0 ms 0 KB -