답안 #685274

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
685274 2023-01-23T20:40:57 Z opPO Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
77 / 100
1814 ms 91696 KB
#pragma GCC optimize("O3,unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define int long long
#define f first
#define s second
#define pb push_back
#define ld long double
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define vec vector

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using oset = tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>;

mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());
const ld eps = 1e-6;
const int mod = 1e9 + 7;
const int oo = 2e9;
const ll OO = 2e18;
const int N = 1e6 + 10;
int n, q, w[N], ans[4 * N];
vec<int> s[N];

void merge(int v)
{
    vec<int> &a = s[2 * v + 1], &b = s[2 * v + 2];
    int n = sz(a), m = sz(b);
    int i = 0, j = 0;
    while (i < n || j < m)
    {
        if (i == n) s[v].pb(b[j++]);
        else if (j == m) s[v].pb(a[i++]);
        else
        {
            if (a[i] < b[j]) s[v].pb(a[i++]);
            else s[v].pb(b[j++]);
        }
    }
    ans[v] = max(ans[2 * v + 1], ans[2 * v + 2]);
    auto it = lower_bound(all(s[2 * v + 2]), s[2 * v + 1].back());
    if (it != s[2 * v + 2].begin())
    {
        --it;
        ans[v] = max(ans[v], s[2 * v + 1].back() + *it);
    }
}

void build(int v, int tl, int tr)
{
    if (tl == tr)
    {
        s[v].pb(w[tl]);
        return;
    }
    int m = (tl + tr) / 2;
    build(2 * v + 1, tl, m);
    build(2 * v + 2, m + 1, tr);
    merge(v);
}

void get(vec<int> &p, int l, int r, int v, int tl, int tr)
{
    if (tl > r || tr < l) return;
    if (tl >= l && tr <= r)
    {
        p.pb(v);
        return;
    }
    int m = (tl + tr) / 2;
    get(p, l, r, 2 * v + 1, tl, m);
    get(p, l, r, 2 * v + 2, m + 1, tr);
}

void solve()
{
    cin >> n >> q;
    for (int i = 1; i <= n; i++) cin >> w[i];
    if (n <= 2e5)
    {
        build(0, 1, n);
        while (q--)
        {
            int l, r, k;
            cin >> l >> r >> k;
            vec<int> p;
            get(p, l, r, 0, 1, n);
            int mx = 0;
            for (int i = 0; i < sz(p); i++)
            {
                mx = max(mx, ans[p[i]]);
                for (int j = i + 1; j < sz(p); j++)
                {
                    auto it = lower_bound(all(s[p[j]]), s[p[i]].back());
                    if (it != s[p[j]].begin())
                    {
                        --it;
                        mx = max(mx, s[p[i]].back() + *it);
                    }
                }
            }
            if (mx <= k) cout << 1;
            else cout << 0;
            cout << "\n";
        }
        return;
    }
    set<pii> setik;
    for (int i = 1; i <= n; i++)
    {
        int j = i + 1;
        while (j <= n && w[j] >= w[j - 1]) j++;
        j--;
        setik.insert({i, j});
        i = j;
    }
    while (q--)
    {
        int l, r, k;
        cin >> l >> r >> k;
        auto it = setik.lower_bound({l, OO});
        if (it == setik.begin()) cout << 0;
        else
        {
            --it;
            if ((*it).s >= r) cout << 1;
            else cout << 0;
        }
        cout << "\n";
    }
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 23836 KB Output is correct
2 Correct 14 ms 23800 KB Output is correct
3 Correct 15 ms 23820 KB Output is correct
4 Correct 13 ms 23764 KB Output is correct
5 Correct 14 ms 23764 KB Output is correct
6 Correct 14 ms 23892 KB Output is correct
7 Correct 14 ms 23892 KB Output is correct
8 Correct 14 ms 23892 KB Output is correct
9 Correct 13 ms 23764 KB Output is correct
10 Correct 14 ms 23892 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 23836 KB Output is correct
2 Correct 14 ms 23800 KB Output is correct
3 Correct 15 ms 23820 KB Output is correct
4 Correct 13 ms 23764 KB Output is correct
5 Correct 14 ms 23764 KB Output is correct
6 Correct 14 ms 23892 KB Output is correct
7 Correct 14 ms 23892 KB Output is correct
8 Correct 14 ms 23892 KB Output is correct
9 Correct 13 ms 23764 KB Output is correct
10 Correct 14 ms 23892 KB Output is correct
11 Correct 19 ms 24176 KB Output is correct
12 Correct 22 ms 24948 KB Output is correct
13 Correct 22 ms 25000 KB Output is correct
14 Correct 27 ms 25044 KB Output is correct
15 Correct 29 ms 25072 KB Output is correct
16 Correct 23 ms 25044 KB Output is correct
17 Correct 21 ms 24480 KB Output is correct
18 Correct 22 ms 24984 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1492 ms 75136 KB Output is correct
2 Correct 1473 ms 91696 KB Output is correct
3 Correct 1483 ms 78844 KB Output is correct
4 Correct 1536 ms 78700 KB Output is correct
5 Correct 431 ms 47416 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 564 ms 47984 KB Output is correct
2 Correct 705 ms 47828 KB Output is correct
3 Correct 389 ms 47860 KB Output is correct
4 Correct 365 ms 47964 KB Output is correct
5 Correct 334 ms 47928 KB Output is correct
6 Correct 510 ms 47932 KB Output is correct
7 Correct 508 ms 47884 KB Output is correct
8 Correct 287 ms 48064 KB Output is correct
9 Correct 67 ms 25132 KB Output is correct
10 Correct 292 ms 48044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 23836 KB Output is correct
2 Correct 14 ms 23800 KB Output is correct
3 Correct 15 ms 23820 KB Output is correct
4 Correct 13 ms 23764 KB Output is correct
5 Correct 14 ms 23764 KB Output is correct
6 Correct 14 ms 23892 KB Output is correct
7 Correct 14 ms 23892 KB Output is correct
8 Correct 14 ms 23892 KB Output is correct
9 Correct 13 ms 23764 KB Output is correct
10 Correct 14 ms 23892 KB Output is correct
11 Correct 19 ms 24176 KB Output is correct
12 Correct 22 ms 24948 KB Output is correct
13 Correct 22 ms 25000 KB Output is correct
14 Correct 27 ms 25044 KB Output is correct
15 Correct 29 ms 25072 KB Output is correct
16 Correct 23 ms 25044 KB Output is correct
17 Correct 21 ms 24480 KB Output is correct
18 Correct 22 ms 24984 KB Output is correct
19 Correct 1371 ms 72560 KB Output is correct
20 Correct 1368 ms 72560 KB Output is correct
21 Correct 1814 ms 72672 KB Output is correct
22 Correct 1791 ms 72496 KB Output is correct
23 Correct 1788 ms 72660 KB Output is correct
24 Correct 1026 ms 72792 KB Output is correct
25 Correct 1027 ms 72652 KB Output is correct
26 Correct 924 ms 72552 KB Output is correct
27 Correct 911 ms 72440 KB Output is correct
28 Correct 939 ms 72440 KB Output is correct
29 Correct 783 ms 72552 KB Output is correct
30 Correct 792 ms 72476 KB Output is correct
31 Correct 812 ms 72484 KB Output is correct
32 Correct 876 ms 72528 KB Output is correct
33 Correct 825 ms 72516 KB Output is correct
34 Correct 1265 ms 72572 KB Output is correct
35 Correct 1249 ms 72596 KB Output is correct
36 Correct 1231 ms 72700 KB Output is correct
37 Correct 1220 ms 72588 KB Output is correct
38 Correct 1224 ms 72508 KB Output is correct
39 Correct 755 ms 72428 KB Output is correct
40 Correct 415 ms 51568 KB Output is correct
41 Correct 661 ms 72464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 23836 KB Output is correct
2 Correct 14 ms 23800 KB Output is correct
3 Correct 15 ms 23820 KB Output is correct
4 Correct 13 ms 23764 KB Output is correct
5 Correct 14 ms 23764 KB Output is correct
6 Correct 14 ms 23892 KB Output is correct
7 Correct 14 ms 23892 KB Output is correct
8 Correct 14 ms 23892 KB Output is correct
9 Correct 13 ms 23764 KB Output is correct
10 Correct 14 ms 23892 KB Output is correct
11 Correct 19 ms 24176 KB Output is correct
12 Correct 22 ms 24948 KB Output is correct
13 Correct 22 ms 25000 KB Output is correct
14 Correct 27 ms 25044 KB Output is correct
15 Correct 29 ms 25072 KB Output is correct
16 Correct 23 ms 25044 KB Output is correct
17 Correct 21 ms 24480 KB Output is correct
18 Correct 22 ms 24984 KB Output is correct
19 Correct 1492 ms 75136 KB Output is correct
20 Correct 1473 ms 91696 KB Output is correct
21 Correct 1483 ms 78844 KB Output is correct
22 Correct 1536 ms 78700 KB Output is correct
23 Correct 431 ms 47416 KB Output is correct
24 Correct 564 ms 47984 KB Output is correct
25 Correct 705 ms 47828 KB Output is correct
26 Correct 389 ms 47860 KB Output is correct
27 Correct 365 ms 47964 KB Output is correct
28 Correct 334 ms 47928 KB Output is correct
29 Correct 510 ms 47932 KB Output is correct
30 Correct 508 ms 47884 KB Output is correct
31 Correct 287 ms 48064 KB Output is correct
32 Correct 67 ms 25132 KB Output is correct
33 Correct 292 ms 48044 KB Output is correct
34 Correct 1371 ms 72560 KB Output is correct
35 Correct 1368 ms 72560 KB Output is correct
36 Correct 1814 ms 72672 KB Output is correct
37 Correct 1791 ms 72496 KB Output is correct
38 Correct 1788 ms 72660 KB Output is correct
39 Correct 1026 ms 72792 KB Output is correct
40 Correct 1027 ms 72652 KB Output is correct
41 Correct 924 ms 72552 KB Output is correct
42 Correct 911 ms 72440 KB Output is correct
43 Correct 939 ms 72440 KB Output is correct
44 Correct 783 ms 72552 KB Output is correct
45 Correct 792 ms 72476 KB Output is correct
46 Correct 812 ms 72484 KB Output is correct
47 Correct 876 ms 72528 KB Output is correct
48 Correct 825 ms 72516 KB Output is correct
49 Correct 1265 ms 72572 KB Output is correct
50 Correct 1249 ms 72596 KB Output is correct
51 Correct 1231 ms 72700 KB Output is correct
52 Correct 1220 ms 72588 KB Output is correct
53 Correct 1224 ms 72508 KB Output is correct
54 Correct 755 ms 72428 KB Output is correct
55 Correct 415 ms 51568 KB Output is correct
56 Correct 661 ms 72464 KB Output is correct
57 Incorrect 1637 ms 79152 KB Output isn't correct
58 Halted 0 ms 0 KB -