Submission #502682

# Submission time Handle Problem Language Result Execution time Memory
502682 2022-01-06T12:39:54 Z tim Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
64 / 100
3000 ms 247456 KB
#include <bits/stdc++.h>

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define y1 tim
#define endl "\n"

#define sz(x) (long long)(x).size()
#define all(x) (x).begin(), (x).end()

using namespace std;

mt19937_64 rng(chrono::system_clock::now().time_since_epoch().count());

int w[1000010], mx[4000010], ans[4000010], Max, y, l, r, k, n, m;
vector <int> v[4000010];

void build (int l, int r, int x)
{
    if (r < l) return;
    if (l == r)
    {
        mx[x] = w[l];
        v[x].push_back(w[l]);
        ans[x] = 0;

        return;
    }
    build (l, (l + r) / 2, x * 2);
    build ((l + r) / 2 + 1, r, x * 2 + 1);
    mx[x] = max (mx[x * 2], mx[x * 2 + 1]);
    v[x] = v[x * 2];
    ans[x] = max (ans[x * 2], ans[x * 2 + 1]);
    int mx1 = -1;
    for (auto i = v[x * 2 + 1].begin(); i != v[x * 2 + 1].end(); i++)
    {

        if (*i < mx[x * 2]) mx1 = *i;
        v[x].push_back(*i);
    }
    sort (v[x].begin(), v[x].end());
    if (mx1 != -1) ans[x] = max (ans[x], mx[x * 2] + mx1);
}

void get (int l, int r, int tl, int tr, int x)
{
    if (r < l) return;
    if (tl > r) return;
    if (tr < l) return;
    tl = max (l, tl);
    tr = min (r, tr);
    if (l == tl and r == tr)
    {
        if (Max == 0 and y == 0)
        {
            y = ans[x];
            Max = mx[x];
        }
        else
        {
            y = max (y, ans[x]);
            auto it = lower_bound(v[x].begin(), v[x].end(), Max);
            if (it != v[x].begin())
            {
                it--;
                y = max (y, Max + *it);
            }
            Max = max (Max, mx[x]);
        }
        return;
    }
    get (l, (l + r) / 2, tl, tr, x * 2);
    get ((l + r) / 2 + 1, r, tl, tr, x * 2 + 1);
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= n; i++) cin >> w[i];
    build (1, n, 1);
    for (int i = 1; i <= m; i++)
    {
        cin >> l >> r >> k;
        y = 0;
        Max = 0;
        get (1, n, l, r, 1);
        if (y <= k) cout << 1 << endl;
        else cout << 0 << endl;
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 43 ms 94152 KB Output is correct
2 Correct 44 ms 94124 KB Output is correct
3 Correct 47 ms 94260 KB Output is correct
4 Correct 49 ms 94232 KB Output is correct
5 Correct 47 ms 94144 KB Output is correct
6 Correct 45 ms 94276 KB Output is correct
7 Correct 45 ms 94224 KB Output is correct
8 Correct 44 ms 94200 KB Output is correct
9 Correct 44 ms 94228 KB Output is correct
10 Correct 45 ms 94312 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 94152 KB Output is correct
2 Correct 44 ms 94124 KB Output is correct
3 Correct 47 ms 94260 KB Output is correct
4 Correct 49 ms 94232 KB Output is correct
5 Correct 47 ms 94144 KB Output is correct
6 Correct 45 ms 94276 KB Output is correct
7 Correct 45 ms 94224 KB Output is correct
8 Correct 44 ms 94200 KB Output is correct
9 Correct 44 ms 94228 KB Output is correct
10 Correct 45 ms 94312 KB Output is correct
11 Correct 49 ms 94420 KB Output is correct
12 Correct 48 ms 94916 KB Output is correct
13 Correct 54 ms 95004 KB Output is correct
14 Correct 55 ms 94996 KB Output is correct
15 Correct 50 ms 95044 KB Output is correct
16 Correct 53 ms 94900 KB Output is correct
17 Correct 48 ms 94832 KB Output is correct
18 Correct 48 ms 94984 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3055 ms 247456 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 309 ms 108552 KB Output is correct
2 Correct 251 ms 109408 KB Output is correct
3 Correct 199 ms 109312 KB Output is correct
4 Correct 212 ms 109352 KB Output is correct
5 Correct 214 ms 109292 KB Output is correct
6 Correct 172 ms 109312 KB Output is correct
7 Correct 189 ms 109372 KB Output is correct
8 Correct 180 ms 109348 KB Output is correct
9 Correct 82 ms 95276 KB Output is correct
10 Correct 205 ms 109352 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 94152 KB Output is correct
2 Correct 44 ms 94124 KB Output is correct
3 Correct 47 ms 94260 KB Output is correct
4 Correct 49 ms 94232 KB Output is correct
5 Correct 47 ms 94144 KB Output is correct
6 Correct 45 ms 94276 KB Output is correct
7 Correct 45 ms 94224 KB Output is correct
8 Correct 44 ms 94200 KB Output is correct
9 Correct 44 ms 94228 KB Output is correct
10 Correct 45 ms 94312 KB Output is correct
11 Correct 49 ms 94420 KB Output is correct
12 Correct 48 ms 94916 KB Output is correct
13 Correct 54 ms 95004 KB Output is correct
14 Correct 55 ms 94996 KB Output is correct
15 Correct 50 ms 95044 KB Output is correct
16 Correct 53 ms 94900 KB Output is correct
17 Correct 48 ms 94832 KB Output is correct
18 Correct 48 ms 94984 KB Output is correct
19 Correct 595 ms 124540 KB Output is correct
20 Correct 592 ms 124504 KB Output is correct
21 Correct 517 ms 124460 KB Output is correct
22 Correct 499 ms 124452 KB Output is correct
23 Correct 511 ms 124380 KB Output is correct
24 Correct 344 ms 124624 KB Output is correct
25 Correct 363 ms 124396 KB Output is correct
26 Correct 402 ms 124600 KB Output is correct
27 Correct 437 ms 124428 KB Output is correct
28 Correct 441 ms 124468 KB Output is correct
29 Correct 431 ms 124472 KB Output is correct
30 Correct 436 ms 124472 KB Output is correct
31 Correct 446 ms 124476 KB Output is correct
32 Correct 499 ms 124472 KB Output is correct
33 Correct 431 ms 124444 KB Output is correct
34 Correct 402 ms 124604 KB Output is correct
35 Correct 340 ms 124396 KB Output is correct
36 Correct 368 ms 124476 KB Output is correct
37 Correct 347 ms 124380 KB Output is correct
38 Correct 341 ms 124380 KB Output is correct
39 Correct 431 ms 124380 KB Output is correct
40 Correct 268 ms 113580 KB Output is correct
41 Correct 357 ms 124500 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 43 ms 94152 KB Output is correct
2 Correct 44 ms 94124 KB Output is correct
3 Correct 47 ms 94260 KB Output is correct
4 Correct 49 ms 94232 KB Output is correct
5 Correct 47 ms 94144 KB Output is correct
6 Correct 45 ms 94276 KB Output is correct
7 Correct 45 ms 94224 KB Output is correct
8 Correct 44 ms 94200 KB Output is correct
9 Correct 44 ms 94228 KB Output is correct
10 Correct 45 ms 94312 KB Output is correct
11 Correct 49 ms 94420 KB Output is correct
12 Correct 48 ms 94916 KB Output is correct
13 Correct 54 ms 95004 KB Output is correct
14 Correct 55 ms 94996 KB Output is correct
15 Correct 50 ms 95044 KB Output is correct
16 Correct 53 ms 94900 KB Output is correct
17 Correct 48 ms 94832 KB Output is correct
18 Correct 48 ms 94984 KB Output is correct
19 Execution timed out 3055 ms 247456 KB Time limit exceeded
20 Halted 0 ms 0 KB -