Submission #333705

# Submission time Handle Problem Language Result Execution time Memory
333705 2020-12-07T14:05:36 Z vipghn2003 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
1892 ms 94700 KB
#include<bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define se second
#define mp make_pair
using namespace std;

const int N=1e6+5;
int n,m,a[N];

struct Query
{
    int l,r,k;
}q[N];
vector<int>event[N];
vector<int>val;

int ST[4*N];

int get (int id,int l,int r,int L,int R)
{
    if (r<L||R<l) return -1e9;
    if (L<=l&&r<=R) return ST[id];
    int mid=(l+r)/2;
    return max (get (id*2,l,mid,L,R),get (id*2+1,mid+1,r,L,R));
}

void update(int id,int l,int r,int u,int x)
{
    if(r==l&&l==u)
    {
        ST[id]=max(ST[id],x);
        return;
    }
    if(u>r||u<l) return;
    int mid=(l+r)/2;
    update(id*2,l,mid,u,x);
    update(id*2+1,mid+1,r,u,x);
    ST[id]=max(ST[id*2],ST[id*2+1]);
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin>>n>>m;
    for(int i=1;i<=n;i++) cin>>a[i];
    for(int i=1;i<=m;i++)
    {
        cin>>q[i].l>>q[i].r>>q[i].k;
        event[q[i].r].push_back(i);
    }
    vector<pii>vec;
    stack<int>st;
    for(int i=1;i<=n;i++)
    {
        while(!st.empty()&&a[st.top()]<=a[i]) st.pop();
        if(!st.empty()) vec.push_back(mp(i,st.top()));
        st.push(i);
    }
    sort(vec.begin(),vec.end());
    int j=0;
    vector<int>res(m+1);
    for(int i=1;i<=n;i++)
    {
        while(j<vec.size()&&vec[j].fi<=i)
        {
            update(1,1,n,vec[j].se,a[vec[j].fi]+a[vec[j].se]);
            j++;
        }
        for(auto&id:event[i])
        {
            int l=q[id].l;
            int r=q[id].r;
            int k=q[id].k;
            if(get(1,1,n,l,n)<=k) res[id]=1;
            else res[id]=0;
        }
    }
    for(int i=1;i<=m;i++) cout<<res[i]<<'\n';
}

Compilation message

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:67:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |         while(j<vec.size()&&vec[j].fi<=i)
      |               ~^~~~~~~~~~~
sortbooks.cpp:75:17: warning: unused variable 'r' [-Wunused-variable]
   75 |             int r=q[id].r;
      |                 ^
# Verdict Execution time Memory Grader output
1 Correct 17 ms 23788 KB Output is correct
2 Correct 17 ms 23788 KB Output is correct
3 Correct 17 ms 23916 KB Output is correct
4 Correct 19 ms 23788 KB Output is correct
5 Correct 17 ms 23916 KB Output is correct
6 Correct 17 ms 23916 KB Output is correct
7 Correct 17 ms 23916 KB Output is correct
8 Correct 17 ms 23916 KB Output is correct
9 Correct 17 ms 23916 KB Output is correct
10 Correct 17 ms 23916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 23788 KB Output is correct
2 Correct 17 ms 23788 KB Output is correct
3 Correct 17 ms 23916 KB Output is correct
4 Correct 19 ms 23788 KB Output is correct
5 Correct 17 ms 23916 KB Output is correct
6 Correct 17 ms 23916 KB Output is correct
7 Correct 17 ms 23916 KB Output is correct
8 Correct 17 ms 23916 KB Output is correct
9 Correct 17 ms 23916 KB Output is correct
10 Correct 17 ms 23916 KB Output is correct
11 Correct 19 ms 24064 KB Output is correct
12 Correct 20 ms 24172 KB Output is correct
13 Correct 21 ms 24300 KB Output is correct
14 Correct 22 ms 24300 KB Output is correct
15 Correct 22 ms 24300 KB Output is correct
16 Correct 21 ms 24172 KB Output is correct
17 Correct 20 ms 24300 KB Output is correct
18 Correct 21 ms 24172 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1846 ms 82376 KB Output is correct
2 Correct 1865 ms 88392 KB Output is correct
3 Correct 1865 ms 92660 KB Output is correct
4 Correct 1892 ms 92864 KB Output is correct
5 Correct 1365 ms 79056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 158 ms 31460 KB Output is correct
2 Correct 135 ms 30864 KB Output is correct
3 Correct 126 ms 29420 KB Output is correct
4 Correct 113 ms 29572 KB Output is correct
5 Correct 120 ms 29676 KB Output is correct
6 Correct 99 ms 28652 KB Output is correct
7 Correct 107 ms 28648 KB Output is correct
8 Correct 122 ms 29924 KB Output is correct
9 Correct 62 ms 27496 KB Output is correct
10 Correct 113 ms 30032 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 23788 KB Output is correct
2 Correct 17 ms 23788 KB Output is correct
3 Correct 17 ms 23916 KB Output is correct
4 Correct 19 ms 23788 KB Output is correct
5 Correct 17 ms 23916 KB Output is correct
6 Correct 17 ms 23916 KB Output is correct
7 Correct 17 ms 23916 KB Output is correct
8 Correct 17 ms 23916 KB Output is correct
9 Correct 17 ms 23916 KB Output is correct
10 Correct 17 ms 23916 KB Output is correct
11 Correct 19 ms 24064 KB Output is correct
12 Correct 20 ms 24172 KB Output is correct
13 Correct 21 ms 24300 KB Output is correct
14 Correct 22 ms 24300 KB Output is correct
15 Correct 22 ms 24300 KB Output is correct
16 Correct 21 ms 24172 KB Output is correct
17 Correct 20 ms 24300 KB Output is correct
18 Correct 21 ms 24172 KB Output is correct
19 Correct 368 ms 41692 KB Output is correct
20 Correct 341 ms 41584 KB Output is correct
21 Correct 290 ms 39876 KB Output is correct
22 Correct 293 ms 39772 KB Output is correct
23 Correct 307 ms 39768 KB Output is correct
24 Correct 204 ms 36004 KB Output is correct
25 Correct 210 ms 35948 KB Output is correct
26 Correct 228 ms 36828 KB Output is correct
27 Correct 254 ms 36844 KB Output is correct
28 Correct 242 ms 37104 KB Output is correct
29 Correct 250 ms 37996 KB Output is correct
30 Correct 252 ms 38076 KB Output is correct
31 Correct 240 ms 38252 KB Output is correct
32 Correct 240 ms 37912 KB Output is correct
33 Correct 241 ms 37996 KB Output is correct
34 Correct 186 ms 35704 KB Output is correct
35 Correct 182 ms 35640 KB Output is correct
36 Correct 183 ms 35436 KB Output is correct
37 Correct 177 ms 35584 KB Output is correct
38 Correct 188 ms 35564 KB Output is correct
39 Correct 227 ms 37728 KB Output is correct
40 Correct 181 ms 35560 KB Output is correct
41 Correct 230 ms 36960 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 23788 KB Output is correct
2 Correct 17 ms 23788 KB Output is correct
3 Correct 17 ms 23916 KB Output is correct
4 Correct 19 ms 23788 KB Output is correct
5 Correct 17 ms 23916 KB Output is correct
6 Correct 17 ms 23916 KB Output is correct
7 Correct 17 ms 23916 KB Output is correct
8 Correct 17 ms 23916 KB Output is correct
9 Correct 17 ms 23916 KB Output is correct
10 Correct 17 ms 23916 KB Output is correct
11 Correct 19 ms 24064 KB Output is correct
12 Correct 20 ms 24172 KB Output is correct
13 Correct 21 ms 24300 KB Output is correct
14 Correct 22 ms 24300 KB Output is correct
15 Correct 22 ms 24300 KB Output is correct
16 Correct 21 ms 24172 KB Output is correct
17 Correct 20 ms 24300 KB Output is correct
18 Correct 21 ms 24172 KB Output is correct
19 Correct 1846 ms 82376 KB Output is correct
20 Correct 1865 ms 88392 KB Output is correct
21 Correct 1865 ms 92660 KB Output is correct
22 Correct 1892 ms 92864 KB Output is correct
23 Correct 1365 ms 79056 KB Output is correct
24 Correct 158 ms 31460 KB Output is correct
25 Correct 135 ms 30864 KB Output is correct
26 Correct 126 ms 29420 KB Output is correct
27 Correct 113 ms 29572 KB Output is correct
28 Correct 120 ms 29676 KB Output is correct
29 Correct 99 ms 28652 KB Output is correct
30 Correct 107 ms 28648 KB Output is correct
31 Correct 122 ms 29924 KB Output is correct
32 Correct 62 ms 27496 KB Output is correct
33 Correct 113 ms 30032 KB Output is correct
34 Correct 368 ms 41692 KB Output is correct
35 Correct 341 ms 41584 KB Output is correct
36 Correct 290 ms 39876 KB Output is correct
37 Correct 293 ms 39772 KB Output is correct
38 Correct 307 ms 39768 KB Output is correct
39 Correct 204 ms 36004 KB Output is correct
40 Correct 210 ms 35948 KB Output is correct
41 Correct 228 ms 36828 KB Output is correct
42 Correct 254 ms 36844 KB Output is correct
43 Correct 242 ms 37104 KB Output is correct
44 Correct 250 ms 37996 KB Output is correct
45 Correct 252 ms 38076 KB Output is correct
46 Correct 240 ms 38252 KB Output is correct
47 Correct 240 ms 37912 KB Output is correct
48 Correct 241 ms 37996 KB Output is correct
49 Correct 186 ms 35704 KB Output is correct
50 Correct 182 ms 35640 KB Output is correct
51 Correct 183 ms 35436 KB Output is correct
52 Correct 177 ms 35584 KB Output is correct
53 Correct 188 ms 35564 KB Output is correct
54 Correct 227 ms 37728 KB Output is correct
55 Correct 181 ms 35560 KB Output is correct
56 Correct 230 ms 36960 KB Output is correct
57 Correct 1864 ms 91244 KB Output is correct
58 Correct 1824 ms 91412 KB Output is correct
59 Correct 1715 ms 87368 KB Output is correct
60 Correct 1717 ms 87240 KB Output is correct
61 Correct 1710 ms 87352 KB Output is correct
62 Correct 1733 ms 87624 KB Output is correct
63 Correct 986 ms 64876 KB Output is correct
64 Correct 976 ms 65004 KB Output is correct
65 Correct 1265 ms 70380 KB Output is correct
66 Correct 1244 ms 70252 KB Output is correct
67 Correct 1262 ms 71148 KB Output is correct
68 Correct 1298 ms 75124 KB Output is correct
69 Correct 1299 ms 75260 KB Output is correct
70 Correct 1308 ms 74220 KB Output is correct
71 Correct 1313 ms 94700 KB Output is correct
72 Correct 1297 ms 74476 KB Output is correct
73 Correct 873 ms 64108 KB Output is correct
74 Correct 912 ms 64108 KB Output is correct
75 Correct 886 ms 64108 KB Output is correct
76 Correct 882 ms 64236 KB Output is correct
77 Correct 877 ms 64108 KB Output is correct
78 Correct 1243 ms 92968 KB Output is correct
79 Correct 870 ms 61536 KB Output is correct
80 Correct 1312 ms 90872 KB Output is correct