Submission #993274

# Submission time Handle Problem Language Result Execution time Memory
993274 2024-06-05T13:20:30 Z simona1230 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1750 ms 75440 KB
#include <bits/stdc++.h>

using namespace std;

void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}

long long n,m,a[1000001];

void read()
{
    cin>>n>>m;
    for(long long i=1;i<=n;i++)
        cin>>a[i];
}

int p[1000001];

void prec()
{
    stack<int> s;
    for(int i=1;i<=n;i++)
    {
        while(s.size()&&a[s.top()]<=a[i])
            s.pop();

        if(s.size())
            p[i]=s.top();
        s.push(i);
    }
}

struct query
{
    int l,r,k,i;
    query(){}
    query(int _l,int _r,int _k,int _i)
    {
        l=_l;
        r=_r;
        k=_k;
        i=_i;
    }

    bool operator<(const query&q)const
    {
        return r<q.r;
    }
};
query q[1000001];
int f[1000001];
int t[4000001];

void update(int i,int l,int r,int idx,int val)
{
    if(l==r)
    {
        t[i]=max(t[i],val);
        return;
    }

    int md=(l+r)/2;
    if(idx<=md)update(i*2,l,md,idx,val);
    else update(i*2+1,md+1,r,idx,val);

    t[i]=max(t[i*2],t[i*2+1]);
}

int query(int i,int l,int r,int ql,int qr)
{
    if(ql>qr)return 0;
    if(ql<=l&&r<=qr)return t[i];
    int md=(l+r)/2;
    return max(query(i*2,l,md,ql,min(md,qr)),query(i*2+1,md+1,r,max(md+1,ql),qr));
}


void solve()
{
    for(int i=1;i<=m;i++)
    {
        int l,r,k;
        cin>>l>>r>>k;
        q[i]={l,r,k,i};
    }
    sort(q+1,q+m+1);

    for(int i=1;i<=m;i++)
    {
        for(int j=q[i-1].r+1;j<=q[i].r;j++)
            if(p[j])update(1,1,n,p[j],a[p[j]]+a[j]);

        int ans=query(1,1,n,q[i].l,q[i].r);
        if(ans<=q[i].k)f[q[i].i]=1;
        else f[q[i].i]=0;
    }

    for(int i=1;i<=m;i++)
        cout<<f[i]<<endl;
}

int main()
{
    speed();
    read();
    prec();
    solve();

    return 0;
}
/*
5 0
11 5 4 10 8
*/
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 2512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 2512 KB Output is correct
11 Correct 5 ms 604 KB Output is correct
12 Correct 5 ms 728 KB Output is correct
13 Correct 5 ms 588 KB Output is correct
14 Correct 8 ms 2896 KB Output is correct
15 Correct 8 ms 860 KB Output is correct
16 Correct 7 ms 604 KB Output is correct
17 Correct 7 ms 860 KB Output is correct
18 Correct 7 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1750 ms 62952 KB Output is correct
2 Correct 1626 ms 75044 KB Output is correct
3 Correct 1680 ms 74492 KB Output is correct
4 Correct 1679 ms 74608 KB Output is correct
5 Correct 1549 ms 64588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 150 ms 8020 KB Output is correct
2 Correct 157 ms 4836 KB Output is correct
3 Correct 142 ms 4432 KB Output is correct
4 Correct 142 ms 5224 KB Output is correct
5 Correct 143 ms 5212 KB Output is correct
6 Correct 146 ms 5204 KB Output is correct
7 Correct 139 ms 7248 KB Output is correct
8 Correct 140 ms 7316 KB Output is correct
9 Correct 116 ms 3924 KB Output is correct
10 Correct 136 ms 5200 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 2512 KB Output is correct
11 Correct 5 ms 604 KB Output is correct
12 Correct 5 ms 728 KB Output is correct
13 Correct 5 ms 588 KB Output is correct
14 Correct 8 ms 2896 KB Output is correct
15 Correct 8 ms 860 KB Output is correct
16 Correct 7 ms 604 KB Output is correct
17 Correct 7 ms 860 KB Output is correct
18 Correct 7 ms 604 KB Output is correct
19 Correct 321 ms 15700 KB Output is correct
20 Correct 319 ms 17748 KB Output is correct
21 Correct 312 ms 17472 KB Output is correct
22 Correct 321 ms 19284 KB Output is correct
23 Correct 310 ms 19356 KB Output is correct
24 Correct 294 ms 15956 KB Output is correct
25 Correct 290 ms 15952 KB Output is correct
26 Correct 298 ms 16076 KB Output is correct
27 Correct 299 ms 16212 KB Output is correct
28 Correct 299 ms 16312 KB Output is correct
29 Correct 308 ms 16380 KB Output is correct
30 Correct 301 ms 16340 KB Output is correct
31 Correct 307 ms 16500 KB Output is correct
32 Correct 297 ms 16216 KB Output is correct
33 Correct 306 ms 16332 KB Output is correct
34 Correct 292 ms 16960 KB Output is correct
35 Correct 284 ms 16976 KB Output is correct
36 Correct 284 ms 14168 KB Output is correct
37 Correct 288 ms 12308 KB Output is correct
38 Correct 294 ms 12368 KB Output is correct
39 Correct 288 ms 12364 KB Output is correct
40 Correct 271 ms 10320 KB Output is correct
41 Correct 283 ms 11344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 2392 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 2512 KB Output is correct
11 Correct 5 ms 604 KB Output is correct
12 Correct 5 ms 728 KB Output is correct
13 Correct 5 ms 588 KB Output is correct
14 Correct 8 ms 2896 KB Output is correct
15 Correct 8 ms 860 KB Output is correct
16 Correct 7 ms 604 KB Output is correct
17 Correct 7 ms 860 KB Output is correct
18 Correct 7 ms 604 KB Output is correct
19 Correct 1750 ms 62952 KB Output is correct
20 Correct 1626 ms 75044 KB Output is correct
21 Correct 1680 ms 74492 KB Output is correct
22 Correct 1679 ms 74608 KB Output is correct
23 Correct 1549 ms 64588 KB Output is correct
24 Correct 150 ms 8020 KB Output is correct
25 Correct 157 ms 4836 KB Output is correct
26 Correct 142 ms 4432 KB Output is correct
27 Correct 142 ms 5224 KB Output is correct
28 Correct 143 ms 5212 KB Output is correct
29 Correct 146 ms 5204 KB Output is correct
30 Correct 139 ms 7248 KB Output is correct
31 Correct 140 ms 7316 KB Output is correct
32 Correct 116 ms 3924 KB Output is correct
33 Correct 136 ms 5200 KB Output is correct
34 Correct 321 ms 15700 KB Output is correct
35 Correct 319 ms 17748 KB Output is correct
36 Correct 312 ms 17472 KB Output is correct
37 Correct 321 ms 19284 KB Output is correct
38 Correct 310 ms 19356 KB Output is correct
39 Correct 294 ms 15956 KB Output is correct
40 Correct 290 ms 15952 KB Output is correct
41 Correct 298 ms 16076 KB Output is correct
42 Correct 299 ms 16212 KB Output is correct
43 Correct 299 ms 16312 KB Output is correct
44 Correct 308 ms 16380 KB Output is correct
45 Correct 301 ms 16340 KB Output is correct
46 Correct 307 ms 16500 KB Output is correct
47 Correct 297 ms 16216 KB Output is correct
48 Correct 306 ms 16332 KB Output is correct
49 Correct 292 ms 16960 KB Output is correct
50 Correct 284 ms 16976 KB Output is correct
51 Correct 284 ms 14168 KB Output is correct
52 Correct 288 ms 12308 KB Output is correct
53 Correct 294 ms 12368 KB Output is correct
54 Correct 288 ms 12364 KB Output is correct
55 Correct 271 ms 10320 KB Output is correct
56 Correct 283 ms 11344 KB Output is correct
57 Correct 1688 ms 75380 KB Output is correct
58 Correct 1671 ms 75440 KB Output is correct
59 Correct 1662 ms 75316 KB Output is correct
60 Correct 1682 ms 75324 KB Output is correct
61 Correct 1701 ms 75092 KB Output is correct
62 Correct 1679 ms 75348 KB Output is correct
63 Correct 1497 ms 61332 KB Output is correct
64 Correct 1518 ms 61364 KB Output is correct
65 Correct 1562 ms 63252 KB Output is correct
66 Correct 1581 ms 62948 KB Output is correct
67 Correct 1574 ms 63060 KB Output is correct
68 Correct 1555 ms 63372 KB Output is correct
69 Correct 1556 ms 63316 KB Output is correct
70 Correct 1552 ms 63196 KB Output is correct
71 Correct 1609 ms 63312 KB Output is correct
72 Correct 1589 ms 63316 KB Output is correct
73 Correct 1535 ms 59732 KB Output is correct
74 Correct 1551 ms 60632 KB Output is correct
75 Correct 1615 ms 59948 KB Output is correct
76 Correct 1529 ms 59920 KB Output is correct
77 Correct 1483 ms 59820 KB Output is correct
78 Correct 1505 ms 61096 KB Output is correct
79 Correct 1353 ms 49040 KB Output is correct
80 Correct 1475 ms 57228 KB Output is correct