답안 #564579

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
564579 2022-05-19T11:27:19 Z urosk Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
1240 ms 107280 KB
#include <bits/stdc++.h>
#define here cerr<<"------------------------------------\n"
#define ll long long
#define pll pair<ll,ll>
#define all(a) a.begin(),a.end()
#define fi first
#define sc second
#define pb push_back
#define popb pop_back
#define sz(x) (ll)(x.size())
#define llinf 100000000000000LL
#define endl '\n'
#define ceri(a,l,r) {for(ll i_ = l;i_<=r;i_++) cerr<<a[i_]<< " ";cerr<<endl;}
using namespace std;
#define maxn 1000005

ll n,q;
ll a[maxn];
ll b[maxn];
ll t[4*maxn];
ll ans[maxn];
struct upit{
    ll l,r,x,id;
};
bool cmp(upit a,upit b){return a.r<b.r;}
void upd(ll v,ll tl,ll tr,ll i,ll x){
    if(tl==tr){
        t[v] = max(t[v],x);
        return;
    }
    ll mid = (tl+tr)/2;
    if(i<=mid) upd(2*v,tl,mid,i,x);
    else upd(2*v+1,mid+1,tr,i,x);
    t[v] = max(t[2*v],t[2*v+1]);
}
ll get(ll v,ll tl,ll tr,ll l,ll r){
    if(l>r) return 0;
    if(tl==l&&tr==r) return t[v];
    ll mid = (tl+tr)/2;
    return max(get(2*v,tl,mid,l,min(mid,r)),get(2*v+1,mid+1,tr,max(mid+1,l),r));
}
vector<upit> v;
int main(){
    ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0);
    cin >> n >> q;
    for(ll i = 1;i<=n;i++) cin >> a[i];
    stack<ll> st;
    for(ll i = 1;i<=n;i++){
        while(sz(st)&&a[i]>=a[st.top()]) st.pop();
        if(sz(st)) b[i] = st.top();
        st.push(i);
    }
    for(ll i = 1;i<=q;i++){
        ll l,r,x;
        cin >> l >> r >> x;
        v.pb({l,r,x,i});
    }
    sort(all(v),cmp);
    ll j = 1;
    for(upit p : v){
        ll l = p.l;
        ll r = p.r;
        ll x = p.x;
        ll id = p.id;
        while(j<=r){
            if(b[j]!=0) upd(1,1,n,b[j],a[j] + a[b[j]]);
            j++;
        }
        ans[id] = get(1,1,n,l,r)<=x;
    }
    for(ll i = 1;i<=q;i++) cout<<ans[i]<<endl;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 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 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 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 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 3 ms 724 KB Output is correct
12 Correct 4 ms 880 KB Output is correct
13 Correct 4 ms 852 KB Output is correct
14 Correct 5 ms 1032 KB Output is correct
15 Correct 5 ms 984 KB Output is correct
16 Correct 4 ms 856 KB Output is correct
17 Correct 3 ms 860 KB Output is correct
18 Correct 4 ms 856 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1188 ms 73660 KB Output is correct
2 Correct 1179 ms 73660 KB Output is correct
3 Correct 1228 ms 73644 KB Output is correct
4 Correct 1198 ms 73596 KB Output is correct
5 Correct 948 ms 49396 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 89 ms 8120 KB Output is correct
2 Correct 89 ms 10168 KB Output is correct
3 Correct 81 ms 7344 KB Output is correct
4 Correct 82 ms 7348 KB Output is correct
5 Correct 77 ms 7308 KB Output is correct
6 Correct 76 ms 7336 KB Output is correct
7 Correct 73 ms 7280 KB Output is correct
8 Correct 75 ms 7612 KB Output is correct
9 Correct 44 ms 5936 KB Output is correct
10 Correct 71 ms 7464 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 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 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 3 ms 724 KB Output is correct
12 Correct 4 ms 880 KB Output is correct
13 Correct 4 ms 852 KB Output is correct
14 Correct 5 ms 1032 KB Output is correct
15 Correct 5 ms 984 KB Output is correct
16 Correct 4 ms 856 KB Output is correct
17 Correct 3 ms 860 KB Output is correct
18 Correct 4 ms 856 KB Output is correct
19 Correct 228 ms 22544 KB Output is correct
20 Correct 216 ms 22580 KB Output is correct
21 Correct 199 ms 22300 KB Output is correct
22 Correct 200 ms 22268 KB Output is correct
23 Correct 208 ms 22364 KB Output is correct
24 Correct 172 ms 16556 KB Output is correct
25 Correct 168 ms 16592 KB Output is correct
26 Correct 203 ms 16764 KB Output is correct
27 Correct 181 ms 16732 KB Output is correct
28 Correct 177 ms 16684 KB Output is correct
29 Correct 180 ms 16808 KB Output is correct
30 Correct 181 ms 16888 KB Output is correct
31 Correct 178 ms 16772 KB Output is correct
32 Correct 182 ms 16864 KB Output is correct
33 Correct 181 ms 16936 KB Output is correct
34 Correct 161 ms 16428 KB Output is correct
35 Correct 168 ms 16584 KB Output is correct
36 Correct 176 ms 16440 KB Output is correct
37 Correct 160 ms 16288 KB Output is correct
38 Correct 168 ms 16532 KB Output is correct
39 Correct 172 ms 17272 KB Output is correct
40 Correct 133 ms 14512 KB Output is correct
41 Correct 164 ms 16000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 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 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 3 ms 724 KB Output is correct
12 Correct 4 ms 880 KB Output is correct
13 Correct 4 ms 852 KB Output is correct
14 Correct 5 ms 1032 KB Output is correct
15 Correct 5 ms 984 KB Output is correct
16 Correct 4 ms 856 KB Output is correct
17 Correct 3 ms 860 KB Output is correct
18 Correct 4 ms 856 KB Output is correct
19 Correct 1188 ms 73660 KB Output is correct
20 Correct 1179 ms 73660 KB Output is correct
21 Correct 1228 ms 73644 KB Output is correct
22 Correct 1198 ms 73596 KB Output is correct
23 Correct 948 ms 49396 KB Output is correct
24 Correct 89 ms 8120 KB Output is correct
25 Correct 89 ms 10168 KB Output is correct
26 Correct 81 ms 7344 KB Output is correct
27 Correct 82 ms 7348 KB Output is correct
28 Correct 77 ms 7308 KB Output is correct
29 Correct 76 ms 7336 KB Output is correct
30 Correct 73 ms 7280 KB Output is correct
31 Correct 75 ms 7612 KB Output is correct
32 Correct 44 ms 5936 KB Output is correct
33 Correct 71 ms 7464 KB Output is correct
34 Correct 228 ms 22544 KB Output is correct
35 Correct 216 ms 22580 KB Output is correct
36 Correct 199 ms 22300 KB Output is correct
37 Correct 200 ms 22268 KB Output is correct
38 Correct 208 ms 22364 KB Output is correct
39 Correct 172 ms 16556 KB Output is correct
40 Correct 168 ms 16592 KB Output is correct
41 Correct 203 ms 16764 KB Output is correct
42 Correct 181 ms 16732 KB Output is correct
43 Correct 177 ms 16684 KB Output is correct
44 Correct 180 ms 16808 KB Output is correct
45 Correct 181 ms 16888 KB Output is correct
46 Correct 178 ms 16772 KB Output is correct
47 Correct 182 ms 16864 KB Output is correct
48 Correct 181 ms 16936 KB Output is correct
49 Correct 161 ms 16428 KB Output is correct
50 Correct 168 ms 16584 KB Output is correct
51 Correct 176 ms 16440 KB Output is correct
52 Correct 160 ms 16288 KB Output is correct
53 Correct 168 ms 16532 KB Output is correct
54 Correct 172 ms 17272 KB Output is correct
55 Correct 133 ms 14512 KB Output is correct
56 Correct 164 ms 16000 KB Output is correct
57 Correct 1240 ms 107280 KB Output is correct
58 Correct 1205 ms 107208 KB Output is correct
59 Correct 1197 ms 107260 KB Output is correct
60 Correct 1230 ms 107188 KB Output is correct
61 Correct 1190 ms 107104 KB Output is correct
62 Correct 1207 ms 107036 KB Output is correct
63 Correct 907 ms 80944 KB Output is correct
64 Correct 937 ms 81096 KB Output is correct
65 Correct 983 ms 82884 KB Output is correct
66 Correct 1022 ms 82876 KB Output is correct
67 Correct 986 ms 82824 KB Output is correct
68 Correct 982 ms 83052 KB Output is correct
69 Correct 978 ms 82952 KB Output is correct
70 Correct 997 ms 83060 KB Output is correct
71 Correct 1004 ms 83056 KB Output is correct
72 Correct 1002 ms 82920 KB Output is correct
73 Correct 898 ms 79492 KB Output is correct
74 Correct 962 ms 80476 KB Output is correct
75 Correct 908 ms 79724 KB Output is correct
76 Correct 894 ms 79532 KB Output is correct
77 Correct 911 ms 79480 KB Output is correct
78 Correct 905 ms 84956 KB Output is correct
79 Correct 701 ms 69284 KB Output is correct
80 Correct 915 ms 79748 KB Output is correct