Submission #746531

# Submission time Handle Problem Language Result Execution time Memory
746531 2023-05-22T16:35:15 Z Denkata Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
871 ms 109572 KB
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
const int maxn = 1e6+3;
long long i,j,p,q,n,m,k,a[maxn],Q,b[maxn];
char s[maxn];
struct Pic
{
    long long l,k,ind;
};
vector <Pic> queries[maxn];
void upd(long long p,long long val)
{
    while(p>=0)
    {
        b[p]=max(b[p],val);
        p=(p&(p+1))-1;
    }
}
long long rsq(long long p)
{
    long long sum = 0;
    while(p<=n)
    {
        sum = max(sum,b[p]);
        p = (p|(p+1));
    }
    return sum;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cin>>n>>Q;
    for(i=1;i<=n;i++)
        cin>>a[i];
    for(i=1;i<=Q;i++)
    {
        cin>>p>>q>>k;
        queries[q].push_back({p,k,i});
    }
    stack <int> st;
    for(i=1;i<=n;i++)
    {
        while(!st.empty() && a[st.top()]<=a[i])
        {
            st.pop();
        }
        if(!st.empty())
            upd(st.top(),a[st.top()]+a[i]);
        st.push(i);
        for(auto j:queries[i])
            s[j.ind] = (char)((rsq(j.l)<=j.k)+ '0');
    }
    for(i=1;i<=Q;i++)
        cout<<s[i]<<endl;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23768 KB Output is correct
2 Correct 15 ms 23704 KB Output is correct
3 Correct 13 ms 23764 KB Output is correct
4 Correct 12 ms 23764 KB Output is correct
5 Correct 12 ms 23764 KB Output is correct
6 Correct 12 ms 23740 KB Output is correct
7 Correct 12 ms 23832 KB Output is correct
8 Correct 13 ms 23764 KB Output is correct
9 Correct 15 ms 23868 KB Output is correct
10 Correct 13 ms 23764 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23768 KB Output is correct
2 Correct 15 ms 23704 KB Output is correct
3 Correct 13 ms 23764 KB Output is correct
4 Correct 12 ms 23764 KB Output is correct
5 Correct 12 ms 23764 KB Output is correct
6 Correct 12 ms 23740 KB Output is correct
7 Correct 12 ms 23832 KB Output is correct
8 Correct 13 ms 23764 KB Output is correct
9 Correct 15 ms 23868 KB Output is correct
10 Correct 13 ms 23764 KB Output is correct
11 Correct 16 ms 23948 KB Output is correct
12 Correct 14 ms 24056 KB Output is correct
13 Correct 16 ms 24060 KB Output is correct
14 Correct 15 ms 24276 KB Output is correct
15 Correct 15 ms 24120 KB Output is correct
16 Correct 15 ms 24012 KB Output is correct
17 Correct 15 ms 24084 KB Output is correct
18 Correct 14 ms 24020 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 828 ms 74904 KB Output is correct
2 Correct 805 ms 74992 KB Output is correct
3 Correct 838 ms 74912 KB Output is correct
4 Correct 826 ms 74904 KB Output is correct
5 Correct 729 ms 67024 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 64 ms 28876 KB Output is correct
2 Correct 70 ms 31016 KB Output is correct
3 Correct 57 ms 30156 KB Output is correct
4 Correct 60 ms 30072 KB Output is correct
5 Correct 68 ms 30052 KB Output is correct
6 Correct 53 ms 30080 KB Output is correct
7 Correct 49 ms 30032 KB Output is correct
8 Correct 67 ms 29876 KB Output is correct
9 Correct 49 ms 28340 KB Output is correct
10 Correct 62 ms 29924 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23768 KB Output is correct
2 Correct 15 ms 23704 KB Output is correct
3 Correct 13 ms 23764 KB Output is correct
4 Correct 12 ms 23764 KB Output is correct
5 Correct 12 ms 23764 KB Output is correct
6 Correct 12 ms 23740 KB Output is correct
7 Correct 12 ms 23832 KB Output is correct
8 Correct 13 ms 23764 KB Output is correct
9 Correct 15 ms 23868 KB Output is correct
10 Correct 13 ms 23764 KB Output is correct
11 Correct 16 ms 23948 KB Output is correct
12 Correct 14 ms 24056 KB Output is correct
13 Correct 16 ms 24060 KB Output is correct
14 Correct 15 ms 24276 KB Output is correct
15 Correct 15 ms 24120 KB Output is correct
16 Correct 15 ms 24012 KB Output is correct
17 Correct 15 ms 24084 KB Output is correct
18 Correct 14 ms 24020 KB Output is correct
19 Correct 155 ms 40684 KB Output is correct
20 Correct 177 ms 40744 KB Output is correct
21 Correct 119 ms 41028 KB Output is correct
22 Correct 123 ms 41056 KB Output is correct
23 Correct 154 ms 40976 KB Output is correct
24 Correct 115 ms 39476 KB Output is correct
25 Correct 120 ms 39524 KB Output is correct
26 Correct 169 ms 39376 KB Output is correct
27 Correct 141 ms 39368 KB Output is correct
28 Correct 136 ms 39128 KB Output is correct
29 Correct 144 ms 39048 KB Output is correct
30 Correct 177 ms 39088 KB Output is correct
31 Correct 137 ms 39064 KB Output is correct
32 Correct 147 ms 39156 KB Output is correct
33 Correct 147 ms 39156 KB Output is correct
34 Correct 111 ms 38836 KB Output is correct
35 Correct 114 ms 38844 KB Output is correct
36 Correct 101 ms 38548 KB Output is correct
37 Correct 97 ms 38572 KB Output is correct
38 Correct 104 ms 38804 KB Output is correct
39 Correct 132 ms 37628 KB Output is correct
40 Correct 105 ms 35444 KB Output is correct
41 Correct 128 ms 37376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 12 ms 23768 KB Output is correct
2 Correct 15 ms 23704 KB Output is correct
3 Correct 13 ms 23764 KB Output is correct
4 Correct 12 ms 23764 KB Output is correct
5 Correct 12 ms 23764 KB Output is correct
6 Correct 12 ms 23740 KB Output is correct
7 Correct 12 ms 23832 KB Output is correct
8 Correct 13 ms 23764 KB Output is correct
9 Correct 15 ms 23868 KB Output is correct
10 Correct 13 ms 23764 KB Output is correct
11 Correct 16 ms 23948 KB Output is correct
12 Correct 14 ms 24056 KB Output is correct
13 Correct 16 ms 24060 KB Output is correct
14 Correct 15 ms 24276 KB Output is correct
15 Correct 15 ms 24120 KB Output is correct
16 Correct 15 ms 24012 KB Output is correct
17 Correct 15 ms 24084 KB Output is correct
18 Correct 14 ms 24020 KB Output is correct
19 Correct 828 ms 74904 KB Output is correct
20 Correct 805 ms 74992 KB Output is correct
21 Correct 838 ms 74912 KB Output is correct
22 Correct 826 ms 74904 KB Output is correct
23 Correct 729 ms 67024 KB Output is correct
24 Correct 64 ms 28876 KB Output is correct
25 Correct 70 ms 31016 KB Output is correct
26 Correct 57 ms 30156 KB Output is correct
27 Correct 60 ms 30072 KB Output is correct
28 Correct 68 ms 30052 KB Output is correct
29 Correct 53 ms 30080 KB Output is correct
30 Correct 49 ms 30032 KB Output is correct
31 Correct 67 ms 29876 KB Output is correct
32 Correct 49 ms 28340 KB Output is correct
33 Correct 62 ms 29924 KB Output is correct
34 Correct 155 ms 40684 KB Output is correct
35 Correct 177 ms 40744 KB Output is correct
36 Correct 119 ms 41028 KB Output is correct
37 Correct 123 ms 41056 KB Output is correct
38 Correct 154 ms 40976 KB Output is correct
39 Correct 115 ms 39476 KB Output is correct
40 Correct 120 ms 39524 KB Output is correct
41 Correct 169 ms 39376 KB Output is correct
42 Correct 141 ms 39368 KB Output is correct
43 Correct 136 ms 39128 KB Output is correct
44 Correct 144 ms 39048 KB Output is correct
45 Correct 177 ms 39088 KB Output is correct
46 Correct 137 ms 39064 KB Output is correct
47 Correct 147 ms 39156 KB Output is correct
48 Correct 147 ms 39156 KB Output is correct
49 Correct 111 ms 38836 KB Output is correct
50 Correct 114 ms 38844 KB Output is correct
51 Correct 101 ms 38548 KB Output is correct
52 Correct 97 ms 38572 KB Output is correct
53 Correct 104 ms 38804 KB Output is correct
54 Correct 132 ms 37628 KB Output is correct
55 Correct 105 ms 35444 KB Output is correct
56 Correct 128 ms 37376 KB Output is correct
57 Correct 844 ms 108780 KB Output is correct
58 Correct 871 ms 108564 KB Output is correct
59 Correct 775 ms 109524 KB Output is correct
60 Correct 811 ms 109536 KB Output is correct
61 Correct 802 ms 109548 KB Output is correct
62 Correct 809 ms 109572 KB Output is correct
63 Correct 553 ms 101800 KB Output is correct
64 Correct 547 ms 101756 KB Output is correct
65 Correct 770 ms 101828 KB Output is correct
66 Correct 759 ms 101940 KB Output is correct
67 Correct 759 ms 101920 KB Output is correct
68 Correct 784 ms 100884 KB Output is correct
69 Correct 798 ms 100812 KB Output is correct
70 Correct 810 ms 100932 KB Output is correct
71 Correct 794 ms 101160 KB Output is correct
72 Correct 840 ms 100964 KB Output is correct
73 Correct 541 ms 95800 KB Output is correct
74 Correct 511 ms 96576 KB Output is correct
75 Correct 494 ms 95536 KB Output is correct
76 Correct 487 ms 95960 KB Output is correct
77 Correct 487 ms 95620 KB Output is correct
78 Correct 664 ms 94940 KB Output is correct
79 Correct 519 ms 81280 KB Output is correct
80 Correct 660 ms 88584 KB Output is correct