답안 #527078

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
527078 2022-02-17T00:47:41 Z jalsol Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++11
8 / 100
580 ms 21980 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] > 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); }
      |             ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 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 324 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 328 KB Output is correct
8 Correct 21 ms 360 KB Output is correct
9 Correct 7 ms 332 KB Output is correct
10 Correct 9 ms 324 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 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 324 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 328 KB Output is correct
8 Correct 21 ms 360 KB Output is correct
9 Correct 7 ms 332 KB Output is correct
10 Correct 9 ms 324 KB Output is correct
11 Incorrect 2 ms 456 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 580 ms 21980 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 29 ms 3756 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 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 324 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 328 KB Output is correct
8 Correct 21 ms 360 KB Output is correct
9 Correct 7 ms 332 KB Output is correct
10 Correct 9 ms 324 KB Output is correct
11 Incorrect 2 ms 456 KB Output isn't correct
12 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 332 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 324 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 328 KB Output is correct
8 Correct 21 ms 360 KB Output is correct
9 Correct 7 ms 332 KB Output is correct
10 Correct 9 ms 324 KB Output is correct
11 Incorrect 2 ms 456 KB Output isn't correct
12 Halted 0 ms 0 KB -