답안 #168454

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
168454 2019-12-13T06:36:16 Z koste4ka Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
64 / 100
3000 ms 259172 KB
#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("-O3")

#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>

#define pb push_back
#define F first
#define S second
#define lll unsigned long long
#define lld long double

#define data sdadsd

//#define int lll

using namespace std;
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree <T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

mt19937 gen(chrono::system_clock::now().time_since_epoch().count());

const int N = 1e6 + 229;
const lll M = 1e9 + 7;
const lll M2 = 1e9 + 9;
const lll mod = 998244353;
const int rx[4] = {0, 0, -1, 1};
const int ry[4] = {-1, 1, 0, 0};
const lld eps = 1e-11;
const double pi = acos(-1.0);

int a[N];

int n, m;

vector < vector < int > > all;

vector < int > ans;

vector < int > need[N];

void prec(int v, int l, int r) {
    int best = 0;
    for (int i = l; i < min(r, n); ++i) {
        if (i > l && a[i] < best) {
            ans[v] = max(ans[v], a[i] + best);
        }
        all[v].pb(a[i]);
        best = max(best, a[i]);
    }
    sort(all[v].begin(), all[v].end());
    all[v].resize(unique(all[v].begin(), all[v].end()) - all[v].begin());
    if (l + 1 == r) {
        return;
    }
    int mid = (l + r) / 2;
    prec(v * 2, l, mid);
    prec(v * 2 + 1, mid, r);
}

void go(int v, int l, int r, int cl, int cr) {
    if (cl >= r || cr <= l) {
        return;
    }
    if (cl >= l && cr <= r) {
        need[m].pb(v);
        return;
    }
    int mid = (cl + cr) / 2;
    go(v * 2, l, r, cl, mid);
    go(v * 2 + 1, l, r, mid, cr);
}

main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    srand(time(0));
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
//    freopen("maxxor.in", "r", stdin);
//    freopen("maxxor.out", "w", stdout);
#endif
    cin >> n >> m;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    int st = 0;
    while ((1 << st) < n) {
        ++st;
    }
    ans.resize(1 << (st + 1));
    all.resize(1 << (st + 1));
    prec(1, 0, 1 << st);
    int l, r, k;
    int res;
    int best;
    int it;
    while (m--) {
        cin >> l >> r >> k;
        --l;
        go(1, l, r, 0, 1 << st);
        res = 0;
        best = 0;
        for (auto i : need[m]) {
            if (best > all[i].front()) {
                it = lower_bound(all[i].begin(), all[i].end(), best) - all[i].begin();
                --it;
                res = max(res, best + all[i][it]);
            }
            best = max(best, all[i].back());
            res = max(res, ans[i]);
        }
        cout << (res <= k) << '\n';
    }
    return 0;
}

Compilation message

sortbooks.cpp:81:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 23800 KB Output is correct
2 Correct 30 ms 23800 KB Output is correct
3 Correct 26 ms 23932 KB Output is correct
4 Correct 25 ms 23800 KB Output is correct
5 Correct 25 ms 23800 KB Output is correct
6 Correct 26 ms 23928 KB Output is correct
7 Correct 30 ms 23928 KB Output is correct
8 Correct 26 ms 23928 KB Output is correct
9 Correct 27 ms 24056 KB Output is correct
10 Correct 26 ms 23928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 23800 KB Output is correct
2 Correct 30 ms 23800 KB Output is correct
3 Correct 26 ms 23932 KB Output is correct
4 Correct 25 ms 23800 KB Output is correct
5 Correct 25 ms 23800 KB Output is correct
6 Correct 26 ms 23928 KB Output is correct
7 Correct 30 ms 23928 KB Output is correct
8 Correct 26 ms 23928 KB Output is correct
9 Correct 27 ms 24056 KB Output is correct
10 Correct 26 ms 23928 KB Output is correct
11 Correct 32 ms 24312 KB Output is correct
12 Correct 34 ms 25168 KB Output is correct
13 Correct 35 ms 25180 KB Output is correct
14 Correct 39 ms 25336 KB Output is correct
15 Correct 39 ms 25308 KB Output is correct
16 Correct 36 ms 25336 KB Output is correct
17 Correct 32 ms 24824 KB Output is correct
18 Correct 34 ms 25208 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3043 ms 259172 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 390 ms 52696 KB Output is correct
2 Correct 369 ms 55160 KB Output is correct
3 Correct 263 ms 53872 KB Output is correct
4 Correct 269 ms 53228 KB Output is correct
5 Correct 291 ms 52704 KB Output is correct
6 Correct 233 ms 56180 KB Output is correct
7 Correct 227 ms 56180 KB Output is correct
8 Correct 265 ms 51992 KB Output is correct
9 Correct 100 ms 28488 KB Output is correct
10 Correct 246 ms 51772 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 23800 KB Output is correct
2 Correct 30 ms 23800 KB Output is correct
3 Correct 26 ms 23932 KB Output is correct
4 Correct 25 ms 23800 KB Output is correct
5 Correct 25 ms 23800 KB Output is correct
6 Correct 26 ms 23928 KB Output is correct
7 Correct 30 ms 23928 KB Output is correct
8 Correct 26 ms 23928 KB Output is correct
9 Correct 27 ms 24056 KB Output is correct
10 Correct 26 ms 23928 KB Output is correct
11 Correct 32 ms 24312 KB Output is correct
12 Correct 34 ms 25168 KB Output is correct
13 Correct 35 ms 25180 KB Output is correct
14 Correct 39 ms 25336 KB Output is correct
15 Correct 39 ms 25308 KB Output is correct
16 Correct 36 ms 25336 KB Output is correct
17 Correct 32 ms 24824 KB Output is correct
18 Correct 34 ms 25208 KB Output is correct
19 Correct 882 ms 83920 KB Output is correct
20 Correct 890 ms 83744 KB Output is correct
21 Correct 829 ms 89384 KB Output is correct
22 Correct 828 ms 89524 KB Output is correct
23 Correct 816 ms 89504 KB Output is correct
24 Correct 513 ms 89372 KB Output is correct
25 Correct 502 ms 89200 KB Output is correct
26 Correct 584 ms 88304 KB Output is correct
27 Correct 548 ms 88176 KB Output is correct
28 Correct 561 ms 87484 KB Output is correct
29 Correct 565 ms 83596 KB Output is correct
30 Correct 594 ms 83696 KB Output is correct
31 Correct 568 ms 84336 KB Output is correct
32 Correct 575 ms 84396 KB Output is correct
33 Correct 567 ms 84388 KB Output is correct
34 Correct 461 ms 91476 KB Output is correct
35 Correct 459 ms 91516 KB Output is correct
36 Correct 462 ms 91644 KB Output is correct
37 Correct 462 ms 91632 KB Output is correct
38 Correct 470 ms 91736 KB Output is correct
39 Correct 587 ms 82992 KB Output is correct
40 Correct 368 ms 60392 KB Output is correct
41 Correct 487 ms 81632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 23800 KB Output is correct
2 Correct 30 ms 23800 KB Output is correct
3 Correct 26 ms 23932 KB Output is correct
4 Correct 25 ms 23800 KB Output is correct
5 Correct 25 ms 23800 KB Output is correct
6 Correct 26 ms 23928 KB Output is correct
7 Correct 30 ms 23928 KB Output is correct
8 Correct 26 ms 23928 KB Output is correct
9 Correct 27 ms 24056 KB Output is correct
10 Correct 26 ms 23928 KB Output is correct
11 Correct 32 ms 24312 KB Output is correct
12 Correct 34 ms 25168 KB Output is correct
13 Correct 35 ms 25180 KB Output is correct
14 Correct 39 ms 25336 KB Output is correct
15 Correct 39 ms 25308 KB Output is correct
16 Correct 36 ms 25336 KB Output is correct
17 Correct 32 ms 24824 KB Output is correct
18 Correct 34 ms 25208 KB Output is correct
19 Execution timed out 3043 ms 259172 KB Time limit exceeded
20 Halted 0 ms 0 KB -