Submission #447246

# Submission time Handle Problem Language Result Execution time Memory
447246 2021-07-25T13:14:15 Z zaneyu Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
1201 ms 120556 KB
/*input
5 2
3 5 1 8 2
1 3 6
2 5 3
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#pragma GCC optimize("unroll-loops,no-stack-protector")
//order_of_key #of elements less than x
// find_by_order kth element
typedef long long int ll;
#define ld long double
#define pii pair<ll,ll>
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
#define f first
#define s second
#define pb push_back
#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define FILL(n,x) memset(n,x,sizeof(n))
#define ALL(_a) _a.begin(),_a.end()
#define sz(x) (int)x.size()
const ll maxn=1e6+5;
const ll maxlg=__lg(maxn)+2;
const ll INF64=4e18;
const int INF=0x3f3f3f3f;
const ll MOD=INF64;
const ld PI=acos(-1);
const ld eps=1e-9;
#define lowb(x) x&(-x)
#define MNTO(x,y) x=min(x,(__typeof__(x))y)
#define MXTO(x,y) x=max(x,(__typeof__(x))y)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
ll mult(ll a,ll b){
    return (a*b)%MOD;
}
ll mypow(ll a,ll b){
    if(b<=0) return 1;
    ll res=1LL;
    while(b){
        if(b&1) res=mult(res,a);
        a=mult(a,a);
        b>>=1;
    }
    return res;
}
int bit[maxn],arr[maxn],ans[maxn];
vector<pair<pii,int>> qq[maxn];
void upd(int p,int x){
    ++p;
    while(p<maxn){
        MXTO(bit[p],x);
        p+=lowb(p);
    }
}
int query(int p){
    ++p;
    int ans=0;
    while(p){
        MXTO(ans,bit[p]);
        p-=lowb(p);
    }
    return ans;
}
int main(){
    ios::sync_with_stdio(false),cin.tie(0);
    int n,q;
    cin>>n>>q;
    vector<int> v;
    vector<pii> inv;
    REP(i,n){
        cin>>arr[i];
        while(sz(v) and arr[v.back()]<=arr[i]) v.pop_back();
        if(sz(v)) inv.pb({v.back(),i});
        v.pb(i);
    }
    sort(ALL(inv));
    REP(i,q){
        int l,r,k;
        cin>>l>>r>>k;
        --l,--r;
        qq[l].pb({{r,k},i});
    }
    for(int i=n-1;i>=0;i--){
        while(sz(inv) and inv.back().f>=i){
            int l=inv.back().f,r=inv.back().s;
            upd(r,arr[l]+arr[r]);
            inv.pop_back();
        }
        for(auto x:qq[i]){
            ans[x.s]=query(x.f.f)<=x.f.s;
        }
    }
    REP(i,q) cout<<ans[i]<<'\n';
}
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23756 KB Output is correct
2 Correct 14 ms 23804 KB Output is correct
3 Correct 14 ms 23884 KB Output is correct
4 Correct 13 ms 23804 KB Output is correct
5 Correct 15 ms 23756 KB Output is correct
6 Correct 14 ms 23884 KB Output is correct
7 Correct 16 ms 23804 KB Output is correct
8 Correct 14 ms 23856 KB Output is correct
9 Correct 14 ms 23884 KB Output is correct
10 Correct 14 ms 23796 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23756 KB Output is correct
2 Correct 14 ms 23804 KB Output is correct
3 Correct 14 ms 23884 KB Output is correct
4 Correct 13 ms 23804 KB Output is correct
5 Correct 15 ms 23756 KB Output is correct
6 Correct 14 ms 23884 KB Output is correct
7 Correct 16 ms 23804 KB Output is correct
8 Correct 14 ms 23856 KB Output is correct
9 Correct 14 ms 23884 KB Output is correct
10 Correct 14 ms 23796 KB Output is correct
11 Correct 15 ms 24068 KB Output is correct
12 Correct 16 ms 24200 KB Output is correct
13 Correct 17 ms 24220 KB Output is correct
14 Correct 17 ms 24268 KB Output is correct
15 Correct 18 ms 24204 KB Output is correct
16 Correct 16 ms 24108 KB Output is correct
17 Correct 16 ms 24196 KB Output is correct
18 Correct 15 ms 24140 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1120 ms 117520 KB Output is correct
2 Correct 1104 ms 118524 KB Output is correct
3 Correct 1134 ms 118320 KB Output is correct
4 Correct 1125 ms 118584 KB Output is correct
5 Correct 958 ms 98948 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 99 ms 31928 KB Output is correct
2 Correct 96 ms 32452 KB Output is correct
3 Correct 86 ms 29988 KB Output is correct
4 Correct 81 ms 30004 KB Output is correct
5 Correct 100 ms 29952 KB Output is correct
6 Correct 68 ms 30132 KB Output is correct
7 Correct 69 ms 30208 KB Output is correct
8 Correct 81 ms 31512 KB Output is correct
9 Correct 54 ms 28588 KB Output is correct
10 Correct 75 ms 30580 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23756 KB Output is correct
2 Correct 14 ms 23804 KB Output is correct
3 Correct 14 ms 23884 KB Output is correct
4 Correct 13 ms 23804 KB Output is correct
5 Correct 15 ms 23756 KB Output is correct
6 Correct 14 ms 23884 KB Output is correct
7 Correct 16 ms 23804 KB Output is correct
8 Correct 14 ms 23856 KB Output is correct
9 Correct 14 ms 23884 KB Output is correct
10 Correct 14 ms 23796 KB Output is correct
11 Correct 15 ms 24068 KB Output is correct
12 Correct 16 ms 24200 KB Output is correct
13 Correct 17 ms 24220 KB Output is correct
14 Correct 17 ms 24268 KB Output is correct
15 Correct 18 ms 24204 KB Output is correct
16 Correct 16 ms 24108 KB Output is correct
17 Correct 16 ms 24196 KB Output is correct
18 Correct 15 ms 24140 KB Output is correct
19 Correct 211 ms 42696 KB Output is correct
20 Correct 212 ms 42672 KB Output is correct
21 Correct 188 ms 43604 KB Output is correct
22 Correct 187 ms 43700 KB Output is correct
23 Correct 182 ms 43652 KB Output is correct
24 Correct 161 ms 39668 KB Output is correct
25 Correct 151 ms 39860 KB Output is correct
26 Correct 184 ms 39364 KB Output is correct
27 Correct 186 ms 39404 KB Output is correct
28 Correct 173 ms 39264 KB Output is correct
29 Correct 189 ms 38800 KB Output is correct
30 Correct 182 ms 38768 KB Output is correct
31 Correct 184 ms 38852 KB Output is correct
32 Correct 191 ms 38696 KB Output is correct
33 Correct 183 ms 38780 KB Output is correct
34 Correct 145 ms 38612 KB Output is correct
35 Correct 143 ms 38608 KB Output is correct
36 Correct 140 ms 38468 KB Output is correct
37 Correct 141 ms 38548 KB Output is correct
38 Correct 155 ms 38668 KB Output is correct
39 Correct 166 ms 38392 KB Output is correct
40 Correct 167 ms 36276 KB Output is correct
41 Correct 179 ms 38652 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 23756 KB Output is correct
2 Correct 14 ms 23804 KB Output is correct
3 Correct 14 ms 23884 KB Output is correct
4 Correct 13 ms 23804 KB Output is correct
5 Correct 15 ms 23756 KB Output is correct
6 Correct 14 ms 23884 KB Output is correct
7 Correct 16 ms 23804 KB Output is correct
8 Correct 14 ms 23856 KB Output is correct
9 Correct 14 ms 23884 KB Output is correct
10 Correct 14 ms 23796 KB Output is correct
11 Correct 15 ms 24068 KB Output is correct
12 Correct 16 ms 24200 KB Output is correct
13 Correct 17 ms 24220 KB Output is correct
14 Correct 17 ms 24268 KB Output is correct
15 Correct 18 ms 24204 KB Output is correct
16 Correct 16 ms 24108 KB Output is correct
17 Correct 16 ms 24196 KB Output is correct
18 Correct 15 ms 24140 KB Output is correct
19 Correct 1120 ms 117520 KB Output is correct
20 Correct 1104 ms 118524 KB Output is correct
21 Correct 1134 ms 118320 KB Output is correct
22 Correct 1125 ms 118584 KB Output is correct
23 Correct 958 ms 98948 KB Output is correct
24 Correct 99 ms 31928 KB Output is correct
25 Correct 96 ms 32452 KB Output is correct
26 Correct 86 ms 29988 KB Output is correct
27 Correct 81 ms 30004 KB Output is correct
28 Correct 100 ms 29952 KB Output is correct
29 Correct 68 ms 30132 KB Output is correct
30 Correct 69 ms 30208 KB Output is correct
31 Correct 81 ms 31512 KB Output is correct
32 Correct 54 ms 28588 KB Output is correct
33 Correct 75 ms 30580 KB Output is correct
34 Correct 211 ms 42696 KB Output is correct
35 Correct 212 ms 42672 KB Output is correct
36 Correct 188 ms 43604 KB Output is correct
37 Correct 187 ms 43700 KB Output is correct
38 Correct 182 ms 43652 KB Output is correct
39 Correct 161 ms 39668 KB Output is correct
40 Correct 151 ms 39860 KB Output is correct
41 Correct 184 ms 39364 KB Output is correct
42 Correct 186 ms 39404 KB Output is correct
43 Correct 173 ms 39264 KB Output is correct
44 Correct 189 ms 38800 KB Output is correct
45 Correct 182 ms 38768 KB Output is correct
46 Correct 184 ms 38852 KB Output is correct
47 Correct 191 ms 38696 KB Output is correct
48 Correct 183 ms 38780 KB Output is correct
49 Correct 145 ms 38612 KB Output is correct
50 Correct 143 ms 38608 KB Output is correct
51 Correct 140 ms 38468 KB Output is correct
52 Correct 141 ms 38548 KB Output is correct
53 Correct 155 ms 38668 KB Output is correct
54 Correct 166 ms 38392 KB Output is correct
55 Correct 167 ms 36276 KB Output is correct
56 Correct 179 ms 38652 KB Output is correct
57 Correct 1201 ms 118804 KB Output is correct
58 Correct 1183 ms 118972 KB Output is correct
59 Correct 1138 ms 120556 KB Output is correct
60 Correct 1099 ms 120520 KB Output is correct
61 Correct 1110 ms 120508 KB Output is correct
62 Correct 1123 ms 120488 KB Output is correct
63 Correct 717 ms 98324 KB Output is correct
64 Correct 745 ms 98164 KB Output is correct
65 Correct 1020 ms 101380 KB Output is correct
66 Correct 1010 ms 101284 KB Output is correct
67 Correct 986 ms 101020 KB Output is correct
68 Correct 996 ms 99392 KB Output is correct
69 Correct 1031 ms 99300 KB Output is correct
70 Correct 983 ms 99448 KB Output is correct
71 Correct 1012 ms 99360 KB Output is correct
72 Correct 1006 ms 99504 KB Output is correct
73 Correct 653 ms 94636 KB Output is correct
74 Correct 677 ms 95276 KB Output is correct
75 Correct 628 ms 94384 KB Output is correct
76 Correct 651 ms 94536 KB Output is correct
77 Correct 651 ms 94552 KB Output is correct
78 Correct 882 ms 98224 KB Output is correct
79 Correct 713 ms 84828 KB Output is correct
80 Correct 939 ms 102812 KB Output is correct