Submission #802473

# Submission time Handle Problem Language Result Execution time Memory
802473 2023-08-02T12:26:29 Z Ahmed57 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
64 / 100
1094 ms 80188 KB
#include<bits/stdc++.h>

using namespace std;
struct query{
    int id,l,r,mood;
};
bool comp(query a, query b){
    return a.l>b.l;
}
//BIT Fenwick tree
int n ;
long long bit[200001]={0};
void add(int e,long long v){
    while(e<=n){
        bit[e] = max(bit[e],v);
        e+=e&-e;
    }
}
long long sum(int e){
    long long res = 0;
    while(e>=1){
        res=max(res,bit[e]);
        e -= e&-e;
    }
    return res;
}
//end BIT
int main(){
	int q;
	cin>>n>>q;
	int arr[n+1];
    for(int i = 1;i<=n;i++)cin>>arr[i];
    vector<query> v;
    for(int i = 1;i<=q;i++){
        query tmp;
        cin>>tmp.l>>tmp.r>>tmp.mood;
        tmp.id = i;
        v.push_back(tmp);
    }
    sort(v.begin(),v.end(),comp);
    int now = n;
    stack<int> st;
    int ans[q+1];
    for(auto qu:v){
        while(now>=qu.l){
            while(st.size()&&arr[now]>arr[st.top()]){
                add(st.top(),arr[st.top()]+arr[now]);
                st.pop();
            }
            while(st.size()&&arr[now]==arr[st.top()])st.pop();
            st.push(now);
            now--;
        }
        ans[qu.id] = (sum(qu.r)<=qu.mood);
    }
    for(int i = 1;i<=q;i++){
        cout<<ans[i]<<"\n";
    }
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 304 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 304 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 3 ms 468 KB Output is correct
12 Correct 4 ms 468 KB Output is correct
13 Correct 4 ms 596 KB Output is correct
14 Correct 6 ms 724 KB Output is correct
15 Correct 6 ms 724 KB Output is correct
16 Correct 5 ms 596 KB Output is correct
17 Correct 6 ms 596 KB Output is correct
18 Correct 4 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Runtime error 1094 ms 80188 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 99 ms 5692 KB Output is correct
2 Correct 90 ms 5620 KB Output is correct
3 Correct 87 ms 4880 KB Output is correct
4 Correct 92 ms 4888 KB Output is correct
5 Correct 86 ms 4888 KB Output is correct
6 Correct 81 ms 4856 KB Output is correct
7 Correct 81 ms 4800 KB Output is correct
8 Correct 81 ms 4564 KB Output is correct
9 Correct 61 ms 3840 KB Output is correct
10 Correct 79 ms 4680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 304 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 3 ms 468 KB Output is correct
12 Correct 4 ms 468 KB Output is correct
13 Correct 4 ms 596 KB Output is correct
14 Correct 6 ms 724 KB Output is correct
15 Correct 6 ms 724 KB Output is correct
16 Correct 5 ms 596 KB Output is correct
17 Correct 6 ms 596 KB Output is correct
18 Correct 4 ms 596 KB Output is correct
19 Correct 246 ms 13576 KB Output is correct
20 Correct 234 ms 13568 KB Output is correct
21 Correct 225 ms 13456 KB Output is correct
22 Correct 229 ms 13500 KB Output is correct
23 Correct 236 ms 13444 KB Output is correct
24 Correct 225 ms 12568 KB Output is correct
25 Correct 217 ms 12552 KB Output is correct
26 Correct 225 ms 12636 KB Output is correct
27 Correct 225 ms 12680 KB Output is correct
28 Correct 231 ms 12624 KB Output is correct
29 Correct 228 ms 12928 KB Output is correct
30 Correct 226 ms 12740 KB Output is correct
31 Correct 228 ms 12816 KB Output is correct
32 Correct 232 ms 12852 KB Output is correct
33 Correct 227 ms 12812 KB Output is correct
34 Correct 213 ms 12464 KB Output is correct
35 Correct 216 ms 12364 KB Output is correct
36 Correct 210 ms 12208 KB Output is correct
37 Correct 229 ms 12196 KB Output is correct
38 Correct 214 ms 12432 KB Output is correct
39 Correct 196 ms 11648 KB Output is correct
40 Correct 171 ms 10276 KB Output is correct
41 Correct 186 ms 10236 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 304 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 312 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 320 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 212 KB Output is correct
11 Correct 3 ms 468 KB Output is correct
12 Correct 4 ms 468 KB Output is correct
13 Correct 4 ms 596 KB Output is correct
14 Correct 6 ms 724 KB Output is correct
15 Correct 6 ms 724 KB Output is correct
16 Correct 5 ms 596 KB Output is correct
17 Correct 6 ms 596 KB Output is correct
18 Correct 4 ms 596 KB Output is correct
19 Runtime error 1094 ms 80188 KB Execution killed with signal 11
20 Halted 0 ms 0 KB -