Submission #168987

# Submission time Handle Problem Language Result Execution time Memory
168987 2019-12-17T11:17:13 Z SamAnd Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
2149 ms 102116 KB
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
const int N = 1000006, INF = 1000000009;

int n, qq;
int a[N];

vector<pair<pair<int, int>, int> > v[N];

int t[N * 4];
int laz[N * 4];

void shi(int pos)
{
    if (laz[pos] == 0)
        return;
    t[pos * 2] = max(t[pos * 2], laz[pos]);
    laz[pos * 2] = max(laz[pos * 2], laz[pos]);
    t[pos * 2 + 1] = max(t[pos * 2 + 1], laz[pos]);
    laz[pos * 2 + 1] = max(laz[pos * 2 + 1], laz[pos]);
    laz[pos] = 0;
}

void ubd(int tl, int tr, int l, int r, int y, int pos)
{
    if (l > r)
        return;
    if (tl == l && tr == r)
    {
        t[pos] = max(t[pos], y);
        laz[pos] = max(laz[pos], y);
        return;
    }
    shi(pos);
    int m = (tl + tr) / 2;
    ubd(tl, m, l, min(m, r), y, pos * 2);
    ubd(m + 1, tr, max(m + 1, l), r, y, pos * 2 + 1);
    t[pos] = max(t[pos * 2], t[pos * 2 + 1]);
}

int qry(int tl, int tr, int l, int r, int pos)
{
    if (l > r)
        return 0;
    if (tl == l && tr == r)
        return t[pos];
    shi(pos);
    int m = (tl + tr) / 2;
    return max(qry(tl, m, l, min(m, r), pos * 2),
               qry(m + 1, tr, max(m + 1, l), r, pos * 2 + 1));
}

char ans[N];
int main()
{
    //freopen("input.txt", "r", stdin);
    scanf("%d%d", &n, &qq);
    for (int i = 1; i <= n; ++i)
        scanf("%d", &a[i]);
    for (int i = 1; i <= qq; ++i)
    {
        int l, r, k;
        scanf("%d%d%d", &l, &r, &k);
        v[r].push_back(m_p(m_p(l, k), i));
    }
    stack<int> s;
    for (int i = 1; i <= n; ++i)
    {
        while (!s.empty() && a[i] >= a[s.top()])
            s.pop();
        if (!s.empty())
        {
            ubd(1, n, 1, s.top(), a[i] + a[s.top()], 1);
        }
        s.push(i);
        for (int j = 0; j < v[i].size(); ++j)
        {
            if (qry(1, n, v[i][j].first.first, i, 1) <= v[i][j].first.second)
                ans[v[i][j].second] = '1';
            else
                ans[v[i][j].second] = '0';
        }
    }
    for (int i = 1; i <= qq; ++i)
        printf("%c\n", ans[i]);
    return 0;
}

Compilation message

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:77:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j = 0; j < v[i].size(); ++j)
                         ~~^~~~~~~~~~~~~
sortbooks.cpp:58:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d", &n, &qq);
     ~~~~~^~~~~~~~~~~~~~~~~
sortbooks.cpp:60:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &a[i]);
         ~~~~~^~~~~~~~~~~~~
sortbooks.cpp:64:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d", &l, &r, &k);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 23 ms 23800 KB Output is correct
2 Correct 23 ms 23800 KB Output is correct
3 Correct 24 ms 23872 KB Output is correct
4 Correct 23 ms 23928 KB Output is correct
5 Correct 24 ms 23928 KB Output is correct
6 Correct 24 ms 23928 KB Output is correct
7 Correct 24 ms 23800 KB Output is correct
8 Correct 24 ms 23928 KB Output is correct
9 Correct 24 ms 23928 KB Output is correct
10 Correct 25 ms 23800 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 23800 KB Output is correct
2 Correct 23 ms 23800 KB Output is correct
3 Correct 24 ms 23872 KB Output is correct
4 Correct 23 ms 23928 KB Output is correct
5 Correct 24 ms 23928 KB Output is correct
6 Correct 24 ms 23928 KB Output is correct
7 Correct 24 ms 23800 KB Output is correct
8 Correct 24 ms 23928 KB Output is correct
9 Correct 24 ms 23928 KB Output is correct
10 Correct 25 ms 23800 KB Output is correct
11 Correct 27 ms 24056 KB Output is correct
12 Correct 29 ms 24124 KB Output is correct
13 Correct 29 ms 24228 KB Output is correct
14 Correct 31 ms 24316 KB Output is correct
15 Correct 30 ms 24184 KB Output is correct
16 Correct 28 ms 24184 KB Output is correct
17 Correct 45 ms 24156 KB Output is correct
18 Correct 29 ms 24244 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2149 ms 69028 KB Output is correct
2 Correct 2116 ms 101852 KB Output is correct
3 Correct 2145 ms 101964 KB Output is correct
4 Correct 2124 ms 101852 KB Output is correct
5 Correct 1547 ms 85444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 171 ms 28708 KB Output is correct
2 Correct 155 ms 29460 KB Output is correct
3 Correct 129 ms 27612 KB Output is correct
4 Correct 133 ms 27632 KB Output is correct
5 Correct 134 ms 27640 KB Output is correct
6 Correct 106 ms 27384 KB Output is correct
7 Correct 108 ms 27376 KB Output is correct
8 Correct 151 ms 28976 KB Output is correct
9 Correct 71 ms 26416 KB Output is correct
10 Correct 129 ms 29484 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 23800 KB Output is correct
2 Correct 23 ms 23800 KB Output is correct
3 Correct 24 ms 23872 KB Output is correct
4 Correct 23 ms 23928 KB Output is correct
5 Correct 24 ms 23928 KB Output is correct
6 Correct 24 ms 23928 KB Output is correct
7 Correct 24 ms 23800 KB Output is correct
8 Correct 24 ms 23928 KB Output is correct
9 Correct 24 ms 23928 KB Output is correct
10 Correct 25 ms 23800 KB Output is correct
11 Correct 27 ms 24056 KB Output is correct
12 Correct 29 ms 24124 KB Output is correct
13 Correct 29 ms 24228 KB Output is correct
14 Correct 31 ms 24316 KB Output is correct
15 Correct 30 ms 24184 KB Output is correct
16 Correct 28 ms 24184 KB Output is correct
17 Correct 45 ms 24156 KB Output is correct
18 Correct 29 ms 24244 KB Output is correct
19 Correct 365 ms 34692 KB Output is correct
20 Correct 367 ms 34560 KB Output is correct
21 Correct 330 ms 34272 KB Output is correct
22 Correct 332 ms 34168 KB Output is correct
23 Correct 315 ms 34168 KB Output is correct
24 Correct 235 ms 29944 KB Output is correct
25 Correct 234 ms 29944 KB Output is correct
26 Correct 259 ms 30252 KB Output is correct
27 Correct 259 ms 30072 KB Output is correct
28 Correct 274 ms 30300 KB Output is correct
29 Correct 293 ms 30428 KB Output is correct
30 Correct 288 ms 30456 KB Output is correct
31 Correct 279 ms 30496 KB Output is correct
32 Correct 288 ms 30396 KB Output is correct
33 Correct 280 ms 30456 KB Output is correct
34 Correct 216 ms 29532 KB Output is correct
35 Correct 218 ms 29624 KB Output is correct
36 Correct 210 ms 29504 KB Output is correct
37 Correct 212 ms 29592 KB Output is correct
38 Correct 213 ms 29616 KB Output is correct
39 Correct 258 ms 32812 KB Output is correct
40 Correct 187 ms 30640 KB Output is correct
41 Correct 258 ms 33396 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 23 ms 23800 KB Output is correct
2 Correct 23 ms 23800 KB Output is correct
3 Correct 24 ms 23872 KB Output is correct
4 Correct 23 ms 23928 KB Output is correct
5 Correct 24 ms 23928 KB Output is correct
6 Correct 24 ms 23928 KB Output is correct
7 Correct 24 ms 23800 KB Output is correct
8 Correct 24 ms 23928 KB Output is correct
9 Correct 24 ms 23928 KB Output is correct
10 Correct 25 ms 23800 KB Output is correct
11 Correct 27 ms 24056 KB Output is correct
12 Correct 29 ms 24124 KB Output is correct
13 Correct 29 ms 24228 KB Output is correct
14 Correct 31 ms 24316 KB Output is correct
15 Correct 30 ms 24184 KB Output is correct
16 Correct 28 ms 24184 KB Output is correct
17 Correct 45 ms 24156 KB Output is correct
18 Correct 29 ms 24244 KB Output is correct
19 Correct 2149 ms 69028 KB Output is correct
20 Correct 2116 ms 101852 KB Output is correct
21 Correct 2145 ms 101964 KB Output is correct
22 Correct 2124 ms 101852 KB Output is correct
23 Correct 1547 ms 85444 KB Output is correct
24 Correct 171 ms 28708 KB Output is correct
25 Correct 155 ms 29460 KB Output is correct
26 Correct 129 ms 27612 KB Output is correct
27 Correct 133 ms 27632 KB Output is correct
28 Correct 134 ms 27640 KB Output is correct
29 Correct 106 ms 27384 KB Output is correct
30 Correct 108 ms 27376 KB Output is correct
31 Correct 151 ms 28976 KB Output is correct
32 Correct 71 ms 26416 KB Output is correct
33 Correct 129 ms 29484 KB Output is correct
34 Correct 365 ms 34692 KB Output is correct
35 Correct 367 ms 34560 KB Output is correct
36 Correct 330 ms 34272 KB Output is correct
37 Correct 332 ms 34168 KB Output is correct
38 Correct 315 ms 34168 KB Output is correct
39 Correct 235 ms 29944 KB Output is correct
40 Correct 234 ms 29944 KB Output is correct
41 Correct 259 ms 30252 KB Output is correct
42 Correct 259 ms 30072 KB Output is correct
43 Correct 274 ms 30300 KB Output is correct
44 Correct 293 ms 30428 KB Output is correct
45 Correct 288 ms 30456 KB Output is correct
46 Correct 279 ms 30496 KB Output is correct
47 Correct 288 ms 30396 KB Output is correct
48 Correct 280 ms 30456 KB Output is correct
49 Correct 216 ms 29532 KB Output is correct
50 Correct 218 ms 29624 KB Output is correct
51 Correct 210 ms 29504 KB Output is correct
52 Correct 212 ms 29592 KB Output is correct
53 Correct 213 ms 29616 KB Output is correct
54 Correct 258 ms 32812 KB Output is correct
55 Correct 187 ms 30640 KB Output is correct
56 Correct 258 ms 33396 KB Output is correct
57 Correct 2106 ms 102000 KB Output is correct
58 Correct 2090 ms 102116 KB Output is correct
59 Correct 1984 ms 100408 KB Output is correct
60 Correct 2058 ms 100676 KB Output is correct
61 Correct 1998 ms 100364 KB Output is correct
62 Correct 1999 ms 100456 KB Output is correct
63 Correct 1147 ms 80120 KB Output is correct
64 Correct 1145 ms 80156 KB Output is correct
65 Correct 1473 ms 83884 KB Output is correct
66 Correct 1455 ms 83940 KB Output is correct
67 Correct 1490 ms 83904 KB Output is correct
68 Correct 1561 ms 85424 KB Output is correct
69 Correct 1576 ms 85656 KB Output is correct
70 Correct 1623 ms 85252 KB Output is correct
71 Correct 1527 ms 85360 KB Output is correct
72 Correct 1541 ms 85380 KB Output is correct
73 Correct 1049 ms 76612 KB Output is correct
74 Correct 1065 ms 77868 KB Output is correct
75 Correct 1067 ms 76616 KB Output is correct
76 Correct 1078 ms 76556 KB Output is correct
77 Correct 1053 ms 76520 KB Output is correct
78 Correct 1485 ms 88648 KB Output is correct
79 Correct 955 ms 72848 KB Output is correct
80 Correct 1510 ms 87804 KB Output is correct