Submission #1040465

# Submission time Handle Problem Language Result Execution time Memory
1040465 2024-08-01T05:17:44 Z vjudge1 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
816 ms 67672 KB
#include <bits/stdc++.h>
#define fi(i, a, b) for( int i = a; i <= b; i++ )
#define fid(i, a, b) for( int i = a; i >= b; i-- )
#define getbit(x, i) ((x>>i)&1)
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define pli pair<ll,int>
#define pll pair<ll,ll>
#define st first
#define nd second
#define mp make_pair
#define HTManh ""
#define maxn 100009
#define endl '\n'
using namespace std;

int n, q;
ll a[1000009];
struct dl
{
    int vt;
    int gt;
    int id;
};
vector<dl> tv[1000009];

int s[1000009], top;

int st[4000009];

void update(int vt, int gt, int goc = 1, int l = 1, int r = n)
{
    if (vt < l || vt > r) return;
    if (l == r)
    {
        st[goc] = gt;
        return;
    }
    int mid = (l+r)/2;
    update(vt,gt,goc*2,l,mid);
    update(vt,gt,goc*2+1,mid+1,r);
    st[goc] = max(st[goc*2], st[goc*2+1]);
}

int get(int d, int c, int goc = 1, int l = 1, int r = n)
{
    if (c < l || d > r) return -1;
    if (d <= l && r <= c) return st[goc];
    int mid = (l+r)/2;
    return max(get(d,c,goc*2,l,mid), get(d,c,goc*2+1,mid+1,r));
}

bool kq[1000009];

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(NULL); cout.tie(NULL);
	if (fopen(HTManh".inp", "r"))
    {
        freopen(HTManh".inp", "r", stdin);
        freopen(HTManh".out", "w", stdout);
    }

    cin >> n >> q;
    fi(i,1,n) cin >> a[i];
    fi(i,1,q)
    {
        int l, r, gt;
        cin >> l >> r >> gt;
        tv[r].pb({l,gt,i});
    }
    fi(i,1,n)
    {
        while(top > 0 && a[s[top]] <= a[i]) top--;
        update(s[top], a[s[top]] + a[i]);
        s[++top] = i;
        for(dl tg: tv[i])
        {
            int vt = tg.vt, gt = tg.gt, id = tg.id;
            //cout << id  << " " << get(vt, i) << endl;
            kq[id] = (get(vt, i) <= gt);
        }
    }
    fi(i,1,q) cout << kq[i] << endl;
}

Compilation message

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:62:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   62 |         freopen(HTManh".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:63:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   63 |         freopen(HTManh".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 29020 KB Output is correct
2 Correct 3 ms 26972 KB Output is correct
3 Correct 5 ms 29020 KB Output is correct
4 Correct 4 ms 29016 KB Output is correct
5 Correct 4 ms 29020 KB Output is correct
6 Correct 4 ms 29020 KB Output is correct
7 Correct 4 ms 29020 KB Output is correct
8 Correct 4 ms 26972 KB Output is correct
9 Correct 3 ms 26972 KB Output is correct
10 Correct 4 ms 26972 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 29020 KB Output is correct
2 Correct 3 ms 26972 KB Output is correct
3 Correct 5 ms 29020 KB Output is correct
4 Correct 4 ms 29016 KB Output is correct
5 Correct 4 ms 29020 KB Output is correct
6 Correct 4 ms 29020 KB Output is correct
7 Correct 4 ms 29020 KB Output is correct
8 Correct 4 ms 26972 KB Output is correct
9 Correct 3 ms 26972 KB Output is correct
10 Correct 4 ms 26972 KB Output is correct
11 Correct 5 ms 29276 KB Output is correct
12 Correct 5 ms 29268 KB Output is correct
13 Correct 6 ms 29276 KB Output is correct
14 Correct 6 ms 29136 KB Output is correct
15 Correct 6 ms 29276 KB Output is correct
16 Correct 6 ms 27236 KB Output is correct
17 Correct 5 ms 27212 KB Output is correct
18 Correct 6 ms 27208 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 779 ms 66396 KB Output is correct
2 Correct 773 ms 66556 KB Output is correct
3 Correct 816 ms 66396 KB Output is correct
4 Correct 774 ms 67672 KB Output is correct
5 Correct 661 ms 58192 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 57 ms 31568 KB Output is correct
2 Correct 54 ms 31172 KB Output is correct
3 Correct 51 ms 29268 KB Output is correct
4 Correct 50 ms 29520 KB Output is correct
5 Correct 48 ms 29520 KB Output is correct
6 Correct 40 ms 31000 KB Output is correct
7 Correct 44 ms 31064 KB Output is correct
8 Correct 44 ms 29708 KB Output is correct
9 Correct 23 ms 28692 KB Output is correct
10 Correct 43 ms 29212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 29020 KB Output is correct
2 Correct 3 ms 26972 KB Output is correct
3 Correct 5 ms 29020 KB Output is correct
4 Correct 4 ms 29016 KB Output is correct
5 Correct 4 ms 29020 KB Output is correct
6 Correct 4 ms 29020 KB Output is correct
7 Correct 4 ms 29020 KB Output is correct
8 Correct 4 ms 26972 KB Output is correct
9 Correct 3 ms 26972 KB Output is correct
10 Correct 4 ms 26972 KB Output is correct
11 Correct 5 ms 29276 KB Output is correct
12 Correct 5 ms 29268 KB Output is correct
13 Correct 6 ms 29276 KB Output is correct
14 Correct 6 ms 29136 KB Output is correct
15 Correct 6 ms 29276 KB Output is correct
16 Correct 6 ms 27236 KB Output is correct
17 Correct 5 ms 27212 KB Output is correct
18 Correct 6 ms 27208 KB Output is correct
19 Correct 125 ms 37972 KB Output is correct
20 Correct 129 ms 37964 KB Output is correct
21 Correct 119 ms 37456 KB Output is correct
22 Correct 114 ms 37376 KB Output is correct
23 Correct 113 ms 37460 KB Output is correct
24 Correct 94 ms 33360 KB Output is correct
25 Correct 92 ms 33364 KB Output is correct
26 Correct 99 ms 33520 KB Output is correct
27 Correct 100 ms 33868 KB Output is correct
28 Correct 98 ms 33592 KB Output is correct
29 Correct 119 ms 34004 KB Output is correct
30 Correct 106 ms 33872 KB Output is correct
31 Correct 106 ms 33872 KB Output is correct
32 Correct 118 ms 33872 KB Output is correct
33 Correct 107 ms 33876 KB Output is correct
34 Correct 103 ms 35072 KB Output is correct
35 Correct 86 ms 35156 KB Output is correct
36 Correct 84 ms 35160 KB Output is correct
37 Correct 85 ms 35152 KB Output is correct
38 Correct 88 ms 35152 KB Output is correct
39 Correct 96 ms 34308 KB Output is correct
40 Correct 72 ms 31148 KB Output is correct
41 Correct 94 ms 33544 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 29020 KB Output is correct
2 Correct 3 ms 26972 KB Output is correct
3 Correct 5 ms 29020 KB Output is correct
4 Correct 4 ms 29016 KB Output is correct
5 Correct 4 ms 29020 KB Output is correct
6 Correct 4 ms 29020 KB Output is correct
7 Correct 4 ms 29020 KB Output is correct
8 Correct 4 ms 26972 KB Output is correct
9 Correct 3 ms 26972 KB Output is correct
10 Correct 4 ms 26972 KB Output is correct
11 Correct 5 ms 29276 KB Output is correct
12 Correct 5 ms 29268 KB Output is correct
13 Correct 6 ms 29276 KB Output is correct
14 Correct 6 ms 29136 KB Output is correct
15 Correct 6 ms 29276 KB Output is correct
16 Correct 6 ms 27236 KB Output is correct
17 Correct 5 ms 27212 KB Output is correct
18 Correct 6 ms 27208 KB Output is correct
19 Correct 779 ms 66396 KB Output is correct
20 Correct 773 ms 66556 KB Output is correct
21 Correct 816 ms 66396 KB Output is correct
22 Correct 774 ms 67672 KB Output is correct
23 Correct 661 ms 58192 KB Output is correct
24 Correct 57 ms 31568 KB Output is correct
25 Correct 54 ms 31172 KB Output is correct
26 Correct 51 ms 29268 KB Output is correct
27 Correct 50 ms 29520 KB Output is correct
28 Correct 48 ms 29520 KB Output is correct
29 Correct 40 ms 31000 KB Output is correct
30 Correct 44 ms 31064 KB Output is correct
31 Correct 44 ms 29708 KB Output is correct
32 Correct 23 ms 28692 KB Output is correct
33 Correct 43 ms 29212 KB Output is correct
34 Correct 125 ms 37972 KB Output is correct
35 Correct 129 ms 37964 KB Output is correct
36 Correct 119 ms 37456 KB Output is correct
37 Correct 114 ms 37376 KB Output is correct
38 Correct 113 ms 37460 KB Output is correct
39 Correct 94 ms 33360 KB Output is correct
40 Correct 92 ms 33364 KB Output is correct
41 Correct 99 ms 33520 KB Output is correct
42 Correct 100 ms 33868 KB Output is correct
43 Correct 98 ms 33592 KB Output is correct
44 Correct 119 ms 34004 KB Output is correct
45 Correct 106 ms 33872 KB Output is correct
46 Correct 106 ms 33872 KB Output is correct
47 Correct 118 ms 33872 KB Output is correct
48 Correct 107 ms 33876 KB Output is correct
49 Correct 103 ms 35072 KB Output is correct
50 Correct 86 ms 35156 KB Output is correct
51 Correct 84 ms 35160 KB Output is correct
52 Correct 85 ms 35152 KB Output is correct
53 Correct 88 ms 35152 KB Output is correct
54 Correct 96 ms 34308 KB Output is correct
55 Correct 72 ms 31148 KB Output is correct
56 Correct 94 ms 33544 KB Output is correct
57 Correct 795 ms 66060 KB Output is correct
58 Correct 749 ms 65976 KB Output is correct
59 Correct 709 ms 64592 KB Output is correct
60 Correct 682 ms 65616 KB Output is correct
61 Correct 685 ms 64592 KB Output is correct
62 Correct 691 ms 64596 KB Output is correct
63 Correct 456 ms 54868 KB Output is correct
64 Correct 471 ms 54788 KB Output is correct
65 Correct 553 ms 56232 KB Output is correct
66 Correct 571 ms 56144 KB Output is correct
67 Correct 605 ms 56404 KB Output is correct
68 Correct 659 ms 57848 KB Output is correct
69 Correct 646 ms 57688 KB Output is correct
70 Correct 627 ms 57428 KB Output is correct
71 Correct 594 ms 57428 KB Output is correct
72 Correct 602 ms 57348 KB Output is correct
73 Correct 434 ms 55800 KB Output is correct
74 Correct 434 ms 55636 KB Output is correct
75 Correct 422 ms 55760 KB Output is correct
76 Correct 432 ms 55632 KB Output is correct
77 Correct 439 ms 55340 KB Output is correct
78 Correct 548 ms 59648 KB Output is correct
79 Correct 407 ms 52720 KB Output is correct
80 Correct 537 ms 57592 KB Output is correct