Submission #162787

# Submission time Handle Problem Language Result Execution time Memory
162787 2019-11-09T17:45:57 Z abacaba Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
1053 ms 68024 KB
#include <chrono>
#include <random>
#include <iostream>
#include <string>
#include <unordered_map>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <stdio.h>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <deque>
#include <cassert>
#include <stack>
using namespace std;

#define max3(a, b, c) max(a, max(b, c))
#define min3(a, b, c) min(a, min(b, c))
#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define ll long long
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>
#define tm abc

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int mod = 1e9 + 7;
const int inf = 1e9;
const int N = 1e6 + 15;
int n, m, sz, a[N], st[N], ans[N], t[N << 1];
bool output[N];

struct query {
    int l, r, k, ind;
    bool operator < (const query &b) const {
        return r < b.r;
    }
} qs[N];

inline void update(int i, int val) {
    i += n;
    for(t[i] = max(t[i], val); i > 1; i >>= 1)
        t[i >> 1] = max(t[i >> 1], val);
}

inline int get(int l, int r) {
    int res = 0;
    for(l += n, r += n + 1; l < r; l >>= 1, r >>= 1) {
        if(l & 1)
            res = max(res, t[l++]);
        if(r & 1)
            res = max(res, t[--r]);
    }
    return res;
}

main() {
    scanf("%d%d", &n, &m);
    for(int i = 1; i <= n; ++i)
        scanf("%d", &a[i]);
    for(int i = 1; i <= m; ++i) {
        scanf("%d%d%d", &qs[i].l, &qs[i].r, &qs[i].k);
        qs[i].ind = i;
    }
    sort(qs + 1, qs + 1 + m);
    int i = 1, j = 1;
    for(; i <= n; ++i) {
        while(sz && a[st[sz - 1]] <= a[i])
            --sz;
        if(sz) {
            int ind_nearest = st[sz - 1];
            int sum = a[ind_nearest] + a[i];

            while(j <= m && qs[j].r < i) {
                ans[qs[j].ind] = max(ans[qs[j].ind], get(qs[j].l, n));
                ++j;
            }
            update(ind_nearest, sum);
        }
        st[sz++] = i;
    }
    while(j <= m) {
        ans[qs[j].ind] = max(ans[qs[j].ind], get(qs[j].l, n));
        ++j;
    }
    for(int i = 1; i <= m; ++i)
        if(ans[qs[i].ind] <= qs[i].k)
            output[qs[i].ind] = true;
    for(int i = 1; i <= m; ++i)
        puts(output[i] ? "1" : "0");
    return 0;
}

Compilation message

sortbooks.cpp:72:6: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
 main() {
      ^
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:73:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &m);
     ~~~~~^~~~~~~~~~~~~~~~
sortbooks.cpp:75:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &a[i]);
         ~~~~~^~~~~~~~~~~~~
sortbooks.cpp:77:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d", &qs[i].l, &qs[i].r, &qs[i].k);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 424 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 424 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 4 ms 504 KB Output is correct
12 Correct 5 ms 632 KB Output is correct
13 Correct 5 ms 632 KB Output is correct
14 Correct 6 ms 760 KB Output is correct
15 Correct 13 ms 632 KB Output is correct
16 Correct 5 ms 632 KB Output is correct
17 Correct 5 ms 632 KB Output is correct
18 Correct 5 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1012 ms 34372 KB Output is correct
2 Correct 1052 ms 66752 KB Output is correct
3 Correct 1053 ms 66544 KB Output is correct
4 Correct 1033 ms 66596 KB Output is correct
5 Correct 900 ms 59748 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 77 ms 5752 KB Output is correct
2 Correct 74 ms 5752 KB Output is correct
3 Correct 70 ms 4984 KB Output is correct
4 Correct 73 ms 4984 KB Output is correct
5 Correct 72 ms 5112 KB Output is correct
6 Correct 60 ms 4856 KB Output is correct
7 Correct 60 ms 4856 KB Output is correct
8 Correct 65 ms 4728 KB Output is correct
9 Correct 44 ms 3960 KB Output is correct
10 Correct 65 ms 4728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 424 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 4 ms 504 KB Output is correct
12 Correct 5 ms 632 KB Output is correct
13 Correct 5 ms 632 KB Output is correct
14 Correct 6 ms 760 KB Output is correct
15 Correct 13 ms 632 KB Output is correct
16 Correct 5 ms 632 KB Output is correct
17 Correct 5 ms 632 KB Output is correct
18 Correct 5 ms 632 KB Output is correct
19 Correct 189 ms 13940 KB Output is correct
20 Correct 187 ms 13944 KB Output is correct
21 Correct 170 ms 13688 KB Output is correct
22 Correct 171 ms 13692 KB Output is correct
23 Correct 177 ms 13688 KB Output is correct
24 Correct 159 ms 12024 KB Output is correct
25 Correct 155 ms 12216 KB Output is correct
26 Correct 163 ms 12220 KB Output is correct
27 Correct 162 ms 12132 KB Output is correct
28 Correct 167 ms 12152 KB Output is correct
29 Correct 184 ms 12312 KB Output is correct
30 Correct 171 ms 12280 KB Output is correct
31 Correct 170 ms 12368 KB Output is correct
32 Correct 169 ms 12280 KB Output is correct
33 Correct 172 ms 12252 KB Output is correct
34 Correct 144 ms 11980 KB Output is correct
35 Correct 142 ms 11872 KB Output is correct
36 Correct 140 ms 11716 KB Output is correct
37 Correct 143 ms 11768 KB Output is correct
38 Correct 143 ms 11924 KB Output is correct
39 Correct 152 ms 11660 KB Output is correct
40 Correct 125 ms 9900 KB Output is correct
41 Correct 141 ms 10588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 376 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 424 KB Output is correct
8 Correct 2 ms 376 KB Output is correct
9 Correct 2 ms 376 KB Output is correct
10 Correct 2 ms 376 KB Output is correct
11 Correct 4 ms 504 KB Output is correct
12 Correct 5 ms 632 KB Output is correct
13 Correct 5 ms 632 KB Output is correct
14 Correct 6 ms 760 KB Output is correct
15 Correct 13 ms 632 KB Output is correct
16 Correct 5 ms 632 KB Output is correct
17 Correct 5 ms 632 KB Output is correct
18 Correct 5 ms 632 KB Output is correct
19 Correct 1012 ms 34372 KB Output is correct
20 Correct 1052 ms 66752 KB Output is correct
21 Correct 1053 ms 66544 KB Output is correct
22 Correct 1033 ms 66596 KB Output is correct
23 Correct 900 ms 59748 KB Output is correct
24 Correct 77 ms 5752 KB Output is correct
25 Correct 74 ms 5752 KB Output is correct
26 Correct 70 ms 4984 KB Output is correct
27 Correct 73 ms 4984 KB Output is correct
28 Correct 72 ms 5112 KB Output is correct
29 Correct 60 ms 4856 KB Output is correct
30 Correct 60 ms 4856 KB Output is correct
31 Correct 65 ms 4728 KB Output is correct
32 Correct 44 ms 3960 KB Output is correct
33 Correct 65 ms 4728 KB Output is correct
34 Correct 189 ms 13940 KB Output is correct
35 Correct 187 ms 13944 KB Output is correct
36 Correct 170 ms 13688 KB Output is correct
37 Correct 171 ms 13692 KB Output is correct
38 Correct 177 ms 13688 KB Output is correct
39 Correct 159 ms 12024 KB Output is correct
40 Correct 155 ms 12216 KB Output is correct
41 Correct 163 ms 12220 KB Output is correct
42 Correct 162 ms 12132 KB Output is correct
43 Correct 167 ms 12152 KB Output is correct
44 Correct 184 ms 12312 KB Output is correct
45 Correct 171 ms 12280 KB Output is correct
46 Correct 170 ms 12368 KB Output is correct
47 Correct 169 ms 12280 KB Output is correct
48 Correct 172 ms 12252 KB Output is correct
49 Correct 144 ms 11980 KB Output is correct
50 Correct 142 ms 11872 KB Output is correct
51 Correct 140 ms 11716 KB Output is correct
52 Correct 143 ms 11768 KB Output is correct
53 Correct 143 ms 11924 KB Output is correct
54 Correct 152 ms 11660 KB Output is correct
55 Correct 125 ms 9900 KB Output is correct
56 Correct 141 ms 10588 KB Output is correct
57 Correct 1033 ms 64788 KB Output is correct
58 Correct 1022 ms 57028 KB Output is correct
59 Correct 1000 ms 68024 KB Output is correct
60 Correct 998 ms 48184 KB Output is correct
61 Correct 993 ms 50444 KB Output is correct
62 Correct 1002 ms 57432 KB Output is correct
63 Correct 816 ms 58740 KB Output is correct
64 Correct 805 ms 39456 KB Output is correct
65 Correct 899 ms 58408 KB Output is correct
66 Correct 896 ms 60280 KB Output is correct
67 Correct 897 ms 60396 KB Output is correct
68 Correct 909 ms 60484 KB Output is correct
69 Correct 909 ms 60460 KB Output is correct
70 Correct 1036 ms 60368 KB Output is correct
71 Correct 917 ms 60348 KB Output is correct
72 Correct 922 ms 60404 KB Output is correct
73 Correct 720 ms 57132 KB Output is correct
74 Correct 789 ms 58012 KB Output is correct
75 Correct 715 ms 57044 KB Output is correct
76 Correct 713 ms 57040 KB Output is correct
77 Correct 716 ms 56948 KB Output is correct
78 Correct 836 ms 56944 KB Output is correct
79 Correct 642 ms 47608 KB Output is correct
80 Correct 765 ms 51532 KB Output is correct