Submission #1114335

# Submission time Handle Problem Language Result Execution time Memory
1114335 2024-11-18T15:18:36 Z LeonidCuk Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1112 ms 102592 KB
#include <bits/stdc++.h>
using namespace std;
vector<int>st,v,res;
void update(int i,int l,int r,int x,int k)
{
    if(l==r)
    {
        st[i]=k;
        return;
    }
    int m=(l+r)/2;
    if(x<=m)update(i*2,l,m,x,k);
    else update(i*2+1,m+1,r,x,k);
    st[i]=max(st[2*i],st[2*i+1]);
}
int gsum(int i,int l,int r,int tl,int tr)
{
    if(l>tr||tl>r||l>r)return 0;
    if(tl<=l&&r<=tr)return st[i];
    int m=(l+r)/2;
    return max(gsum(2*i,l,m,tl,tr),gsum(i*2+1,m+1,r,tl,tr));
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,m,a,b,c;
    cin>>n>>m;
    vector<pair<int,pair<int,int>>>q[n];
    res.resize(m);
    st.resize(4*n+1);
    for(int i=0;i<n;i++)
    {
        cin>>a;
        v.push_back(a);
    }
    for(int i=0;i<m;i++)
    {
        cin>>a>>b>>c;
        q[b-1].push_back({i,{a-1,c}});
    }
    stack<int>s;
    for(int i=0;i<n;i++)
    {
        while(!s.empty())
        {
            if(v[s.top()]<=v[i])s.pop();
            else break;
        }
        if(!s.empty())update(1,0,n-1,s.top(),v[s.top()]+v[i]);
        s.push(i);
        for(int j=0;j<q[i].size();j++)
        {
            if(gsum(1,0,n-1,q[i][j].second.first,i)<=q[i][j].second.second)res[q[i][j].first]=1;
            else res[q[i][j].first]=0;
        }
    }
    for(int i=0;i<m;i++)
    {
        cout<<res[i]<<"\n";
    }
}

Compilation message

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:52:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   52 |         for(int j=0;j<q[i].size();j++)
      |                     ~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 3 ms 592 KB Output is correct
12 Correct 3 ms 848 KB Output is correct
13 Correct 3 ms 848 KB Output is correct
14 Correct 4 ms 896 KB Output is correct
15 Correct 4 ms 848 KB Output is correct
16 Correct 3 ms 848 KB Output is correct
17 Correct 3 ms 848 KB Output is correct
18 Correct 3 ms 848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1002 ms 102592 KB Output is correct
2 Correct 1103 ms 87736 KB Output is correct
3 Correct 1030 ms 87564 KB Output is correct
4 Correct 969 ms 102532 KB Output is correct
5 Correct 926 ms 90508 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 75 ms 8688 KB Output is correct
2 Correct 68 ms 8980 KB Output is correct
3 Correct 60 ms 8656 KB Output is correct
4 Correct 66 ms 9168 KB Output is correct
5 Correct 59 ms 9268 KB Output is correct
6 Correct 49 ms 8656 KB Output is correct
7 Correct 48 ms 8676 KB Output is correct
8 Correct 56 ms 8924 KB Output is correct
9 Correct 26 ms 3760 KB Output is correct
10 Correct 53 ms 8912 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 3 ms 592 KB Output is correct
12 Correct 3 ms 848 KB Output is correct
13 Correct 3 ms 848 KB Output is correct
14 Correct 4 ms 896 KB Output is correct
15 Correct 4 ms 848 KB Output is correct
16 Correct 3 ms 848 KB Output is correct
17 Correct 3 ms 848 KB Output is correct
18 Correct 3 ms 848 KB Output is correct
19 Correct 158 ms 19668 KB Output is correct
20 Correct 185 ms 17988 KB Output is correct
21 Correct 139 ms 19140 KB Output is correct
22 Correct 146 ms 19140 KB Output is correct
23 Correct 143 ms 19920 KB Output is correct
24 Correct 112 ms 18884 KB Output is correct
25 Correct 118 ms 19652 KB Output is correct
26 Correct 129 ms 19400 KB Output is correct
27 Correct 131 ms 19332 KB Output is correct
28 Correct 142 ms 19396 KB Output is correct
29 Correct 152 ms 20932 KB Output is correct
30 Correct 160 ms 19656 KB Output is correct
31 Correct 153 ms 19800 KB Output is correct
32 Correct 147 ms 20932 KB Output is correct
33 Correct 142 ms 19652 KB Output is correct
34 Correct 124 ms 16836 KB Output is correct
35 Correct 113 ms 19740 KB Output is correct
36 Correct 108 ms 19396 KB Output is correct
37 Correct 114 ms 19140 KB Output is correct
38 Correct 107 ms 18624 KB Output is correct
39 Correct 114 ms 18372 KB Output is correct
40 Correct 93 ms 15060 KB Output is correct
41 Correct 113 ms 18964 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 336 KB Output is correct
9 Correct 1 ms 336 KB Output is correct
10 Correct 1 ms 336 KB Output is correct
11 Correct 3 ms 592 KB Output is correct
12 Correct 3 ms 848 KB Output is correct
13 Correct 3 ms 848 KB Output is correct
14 Correct 4 ms 896 KB Output is correct
15 Correct 4 ms 848 KB Output is correct
16 Correct 3 ms 848 KB Output is correct
17 Correct 3 ms 848 KB Output is correct
18 Correct 3 ms 848 KB Output is correct
19 Correct 1002 ms 102592 KB Output is correct
20 Correct 1103 ms 87736 KB Output is correct
21 Correct 1030 ms 87564 KB Output is correct
22 Correct 969 ms 102532 KB Output is correct
23 Correct 926 ms 90508 KB Output is correct
24 Correct 75 ms 8688 KB Output is correct
25 Correct 68 ms 8980 KB Output is correct
26 Correct 60 ms 8656 KB Output is correct
27 Correct 66 ms 9168 KB Output is correct
28 Correct 59 ms 9268 KB Output is correct
29 Correct 49 ms 8656 KB Output is correct
30 Correct 48 ms 8676 KB Output is correct
31 Correct 56 ms 8924 KB Output is correct
32 Correct 26 ms 3760 KB Output is correct
33 Correct 53 ms 8912 KB Output is correct
34 Correct 158 ms 19668 KB Output is correct
35 Correct 185 ms 17988 KB Output is correct
36 Correct 139 ms 19140 KB Output is correct
37 Correct 146 ms 19140 KB Output is correct
38 Correct 143 ms 19920 KB Output is correct
39 Correct 112 ms 18884 KB Output is correct
40 Correct 118 ms 19652 KB Output is correct
41 Correct 129 ms 19400 KB Output is correct
42 Correct 131 ms 19332 KB Output is correct
43 Correct 142 ms 19396 KB Output is correct
44 Correct 152 ms 20932 KB Output is correct
45 Correct 160 ms 19656 KB Output is correct
46 Correct 153 ms 19800 KB Output is correct
47 Correct 147 ms 20932 KB Output is correct
48 Correct 142 ms 19652 KB Output is correct
49 Correct 124 ms 16836 KB Output is correct
50 Correct 113 ms 19740 KB Output is correct
51 Correct 108 ms 19396 KB Output is correct
52 Correct 114 ms 19140 KB Output is correct
53 Correct 107 ms 18624 KB Output is correct
54 Correct 114 ms 18372 KB Output is correct
55 Correct 93 ms 15060 KB Output is correct
56 Correct 113 ms 18964 KB Output is correct
57 Correct 1112 ms 100156 KB Output is correct
58 Correct 1035 ms 95924 KB Output is correct
59 Correct 827 ms 94324 KB Output is correct
60 Correct 918 ms 100716 KB Output is correct
61 Correct 1035 ms 86252 KB Output is correct
62 Correct 934 ms 68972 KB Output is correct
63 Correct 653 ms 67800 KB Output is correct
64 Correct 652 ms 96052 KB Output is correct
65 Correct 841 ms 69056 KB Output is correct
66 Correct 852 ms 69044 KB Output is correct
67 Correct 827 ms 69044 KB Output is correct
68 Correct 840 ms 100460 KB Output is correct
69 Correct 896 ms 87508 KB Output is correct
70 Correct 835 ms 87024 KB Output is correct
71 Correct 808 ms 95480 KB Output is correct
72 Correct 914 ms 87232 KB Output is correct
73 Correct 592 ms 88164 KB Output is correct
74 Correct 585 ms 86372 KB Output is correct
75 Correct 545 ms 88244 KB Output is correct
76 Correct 535 ms 65368 KB Output is correct
77 Correct 546 ms 65420 KB Output is correct
78 Correct 779 ms 68792 KB Output is correct
79 Correct 557 ms 63668 KB Output is correct
80 Correct 776 ms 87376 KB Output is correct