답안 #168990

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
168990 2019-12-17T11:21:22 Z SamAnd Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
2028 ms 72780 KB
#include <bits/stdc++.h>
using namespace std;
#define m_p make_pair
const int N = 1000006, INF = 1000000009;

int ka()
{
    int x = 0;
    while (1)
    {
        char y = getchar();
        if ('0' <= y && y <= '9')
            x = (x * 10) + (y - '0');
        else
            return x;
    }
}

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);
    n = ka();
    qq = ka();
    for (int i = 1; i <= n; ++i)
        a[i] = ka();
    for (int i = 1; i <= qq; ++i)
    {
        int l, r, k;
        l = ka();
        r = ka();
        k = ka();
        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)
    {
        putchar(ans[i]);
        putchar('\n');
    }
    return 0;
}

Compilation message

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:93:27: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (int j = 0; j < v[i].size(); ++j)
                         ~~^~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 23800 KB Output is correct
2 Correct 22 ms 23800 KB Output is correct
3 Correct 23 ms 23928 KB Output is correct
4 Correct 23 ms 23800 KB Output is correct
5 Correct 23 ms 23800 KB Output is correct
6 Correct 24 ms 23928 KB Output is correct
7 Correct 24 ms 23928 KB Output is correct
8 Correct 24 ms 23928 KB Output is correct
9 Correct 23 ms 23928 KB Output is correct
10 Correct 23 ms 23928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 23800 KB Output is correct
2 Correct 22 ms 23800 KB Output is correct
3 Correct 23 ms 23928 KB Output is correct
4 Correct 23 ms 23800 KB Output is correct
5 Correct 23 ms 23800 KB Output is correct
6 Correct 24 ms 23928 KB Output is correct
7 Correct 24 ms 23928 KB Output is correct
8 Correct 24 ms 23928 KB Output is correct
9 Correct 23 ms 23928 KB Output is correct
10 Correct 23 ms 23928 KB Output is correct
11 Correct 25 ms 24056 KB Output is correct
12 Correct 27 ms 24184 KB Output is correct
13 Correct 27 ms 24184 KB Output is correct
14 Correct 28 ms 24312 KB Output is correct
15 Correct 28 ms 24184 KB Output is correct
16 Correct 26 ms 24184 KB Output is correct
17 Correct 26 ms 24184 KB Output is correct
18 Correct 26 ms 24188 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1865 ms 72780 KB Output is correct
2 Correct 1933 ms 69248 KB Output is correct
3 Correct 2028 ms 69100 KB Output is correct
4 Correct 1933 ms 69064 KB Output is correct
5 Correct 1437 ms 52792 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 146 ms 30840 KB Output is correct
2 Correct 133 ms 30448 KB Output is correct
3 Correct 112 ms 28508 KB Output is correct
4 Correct 110 ms 28536 KB Output is correct
5 Correct 113 ms 28664 KB Output is correct
6 Correct 92 ms 28152 KB Output is correct
7 Correct 91 ms 28108 KB Output is correct
8 Correct 113 ms 29712 KB Output is correct
9 Correct 59 ms 26928 KB Output is correct
10 Correct 112 ms 30000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 23800 KB Output is correct
2 Correct 22 ms 23800 KB Output is correct
3 Correct 23 ms 23928 KB Output is correct
4 Correct 23 ms 23800 KB Output is correct
5 Correct 23 ms 23800 KB Output is correct
6 Correct 24 ms 23928 KB Output is correct
7 Correct 24 ms 23928 KB Output is correct
8 Correct 24 ms 23928 KB Output is correct
9 Correct 23 ms 23928 KB Output is correct
10 Correct 23 ms 23928 KB Output is correct
11 Correct 25 ms 24056 KB Output is correct
12 Correct 27 ms 24184 KB Output is correct
13 Correct 27 ms 24184 KB Output is correct
14 Correct 28 ms 24312 KB Output is correct
15 Correct 28 ms 24184 KB Output is correct
16 Correct 26 ms 24184 KB Output is correct
17 Correct 26 ms 24184 KB Output is correct
18 Correct 26 ms 24188 KB Output is correct
19 Correct 330 ms 36552 KB Output is correct
20 Correct 332 ms 36680 KB Output is correct
21 Correct 290 ms 36216 KB Output is correct
22 Correct 287 ms 36344 KB Output is correct
23 Correct 287 ms 36216 KB Output is correct
24 Correct 212 ms 32544 KB Output is correct
25 Correct 213 ms 32248 KB Output is correct
26 Correct 231 ms 32376 KB Output is correct
27 Correct 233 ms 32376 KB Output is correct
28 Correct 237 ms 32632 KB Output is correct
29 Correct 249 ms 32760 KB Output is correct
30 Correct 252 ms 32960 KB Output is correct
31 Correct 251 ms 32888 KB Output is correct
32 Correct 258 ms 32744 KB Output is correct
33 Correct 265 ms 32632 KB Output is correct
34 Correct 200 ms 31480 KB Output is correct
35 Correct 202 ms 31740 KB Output is correct
36 Correct 198 ms 31992 KB Output is correct
37 Correct 197 ms 31992 KB Output is correct
38 Correct 200 ms 31992 KB Output is correct
39 Correct 232 ms 34860 KB Output is correct
40 Correct 166 ms 32936 KB Output is correct
41 Correct 232 ms 34856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 23800 KB Output is correct
2 Correct 22 ms 23800 KB Output is correct
3 Correct 23 ms 23928 KB Output is correct
4 Correct 23 ms 23800 KB Output is correct
5 Correct 23 ms 23800 KB Output is correct
6 Correct 24 ms 23928 KB Output is correct
7 Correct 24 ms 23928 KB Output is correct
8 Correct 24 ms 23928 KB Output is correct
9 Correct 23 ms 23928 KB Output is correct
10 Correct 23 ms 23928 KB Output is correct
11 Correct 25 ms 24056 KB Output is correct
12 Correct 27 ms 24184 KB Output is correct
13 Correct 27 ms 24184 KB Output is correct
14 Correct 28 ms 24312 KB Output is correct
15 Correct 28 ms 24184 KB Output is correct
16 Correct 26 ms 24184 KB Output is correct
17 Correct 26 ms 24184 KB Output is correct
18 Correct 26 ms 24188 KB Output is correct
19 Correct 1865 ms 72780 KB Output is correct
20 Correct 1933 ms 69248 KB Output is correct
21 Correct 2028 ms 69100 KB Output is correct
22 Correct 1933 ms 69064 KB Output is correct
23 Correct 1437 ms 52792 KB Output is correct
24 Correct 146 ms 30840 KB Output is correct
25 Correct 133 ms 30448 KB Output is correct
26 Correct 112 ms 28508 KB Output is correct
27 Correct 110 ms 28536 KB Output is correct
28 Correct 113 ms 28664 KB Output is correct
29 Correct 92 ms 28152 KB Output is correct
30 Correct 91 ms 28108 KB Output is correct
31 Correct 113 ms 29712 KB Output is correct
32 Correct 59 ms 26928 KB Output is correct
33 Correct 112 ms 30000 KB Output is correct
34 Correct 330 ms 36552 KB Output is correct
35 Correct 332 ms 36680 KB Output is correct
36 Correct 290 ms 36216 KB Output is correct
37 Correct 287 ms 36344 KB Output is correct
38 Correct 287 ms 36216 KB Output is correct
39 Correct 212 ms 32544 KB Output is correct
40 Correct 213 ms 32248 KB Output is correct
41 Correct 231 ms 32376 KB Output is correct
42 Correct 233 ms 32376 KB Output is correct
43 Correct 237 ms 32632 KB Output is correct
44 Correct 249 ms 32760 KB Output is correct
45 Correct 252 ms 32960 KB Output is correct
46 Correct 251 ms 32888 KB Output is correct
47 Correct 258 ms 32744 KB Output is correct
48 Correct 265 ms 32632 KB Output is correct
49 Correct 200 ms 31480 KB Output is correct
50 Correct 202 ms 31740 KB Output is correct
51 Correct 198 ms 31992 KB Output is correct
52 Correct 197 ms 31992 KB Output is correct
53 Correct 200 ms 31992 KB Output is correct
54 Correct 232 ms 34860 KB Output is correct
55 Correct 166 ms 32936 KB Output is correct
56 Correct 232 ms 34856 KB Output is correct
57 Correct 1916 ms 68604 KB Output is correct
58 Correct 1949 ms 68516 KB Output is correct
59 Correct 1829 ms 67192 KB Output is correct
60 Correct 1868 ms 68060 KB Output is correct
61 Correct 1819 ms 67192 KB Output is correct
62 Correct 1801 ms 68064 KB Output is correct
63 Correct 1030 ms 48632 KB Output is correct
64 Correct 1065 ms 48632 KB Output is correct
65 Correct 1330 ms 51336 KB Output is correct
66 Correct 1328 ms 50424 KB Output is correct
67 Correct 1340 ms 50652 KB Output is correct
68 Correct 1390 ms 52088 KB Output is correct
69 Correct 1386 ms 52644 KB Output is correct
70 Correct 1385 ms 51752 KB Output is correct
71 Correct 1413 ms 51884 KB Output is correct
72 Correct 1369 ms 52248 KB Output is correct
73 Correct 976 ms 46712 KB Output is correct
74 Correct 986 ms 46840 KB Output is correct
75 Correct 977 ms 47136 KB Output is correct
76 Correct 966 ms 46544 KB Output is correct
77 Correct 971 ms 46808 KB Output is correct
78 Correct 1322 ms 61728 KB Output is correct
79 Correct 846 ms 50624 KB Output is correct
80 Correct 1317 ms 63252 KB Output is correct