답안 #892847

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
892847 2023-12-26T05:21:03 Z vjudge1 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1306 ms 169412 KB
#include<bits/stdc++.h>
#define pb push_back
#define pf push_front
#define F first
#define S second
#define ff first
#define ss second
#define ll long long
#define ull unsigned long long
#define ld long double
#define pll pair<ll,ll>
#define plll pair<ll,pll>
#define pllll pair<pll,pll>
#define vl vector<ll>
#define vll vector<pll>
#define vlll vector<plll>
#define vllll vector<pllll>
#define vb vector<bool>
#define sz size()
#define fr front()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define bk back();
using namespace std;
const ld pi=3.14159265359;
const ll e5=1e5;
const ll e6=1e6;
const ll e9=1e9;
const ll inf=1e18;
const ll mod=1e9+7;
const ll mod2=998244353;
const ll N=2e6+5;
ll bpm(ll x,ll y,ll m){if(y==0)return 1%m;if(y==1)return x%m;ll p=bpm(x,y/2,m);
if(y%2==0)return p*p%m;else return p*p%m*x%m;}
ll bp(ll x,ll y){if(y==0)return 1;if(y==1)return x;ll p=bp(x,y/2);
if(y%2==0)return p*p;else return p*p*x;}
ll n,m,a[N],p[N],ql[N],qr[N],qk[N],t[N*4];
bool ans[N];
vl q[N];
void upd(ll v,ll l,ll r,ll i,ll x){
    if(l==r){
        t[v]=x;
        return;
    }
    ll m=(l+r)/2;
    if(i<=m) upd(v*2,l,m,i,x);
    else upd(v*2+1,m+1,r,i,x);
    t[v]=max(t[v*2],t[v*2+1]);
}
ll get(ll v,ll l,ll r,ll ql,ll qr){
    if(qr<l||r<ql) return 0;
    if(ql<=l&&r<=qr) return t[v];
    ll m=(l+r)/2;
    ll m1=get(v*2,l,m,ql,qr);
    ll m2=get(v*2+1,m+1,r,ql,qr);
    return max(m1,m2);
}
void solve(){
    cin>>n>>m;
    stack<ll> s;
    for(ll i=1;i<=n;i++){
        cin>>a[i];
        while(!s.empty()&&a[s.top()]<=a[i]) s.pop();
        if(!s.empty()) p[i]=s.top();
        s.push(i);
    }
    for(ll i=1;i<=m;i++){
        cin>>ql[i]>>qr[i]>>qk[i];
        q[qr[i]].pb(i);
    }
    for(ll i=1;i<=n;i++){
        if(p[i]!=0) upd(1,1,n,p[i],a[p[i]]+a[i]);
        for(ll j:q[i]){
           ans[j] = get(1,1,n,ql[j],qr[j]) <= qk[j];
        }
    }
    for(ll i=1;i<=m;i++){
        if(ans[i]) cout<<1<<'\n';
        else cout<<0<<'\n';
    }
    return;
}
int main(/*Aldk*/){
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    //freopen(".in", "r", stdin);
    //freopen(".out", "w", stdout);    
    //cout<<setprecision(6)<<fixed;
    ll T=1;
    //cin>>T;
    for(ll i=1;i<=T;i++){
        //cout<<"Scenario #"<<i<<":\n";
        solve();
        //cout<<'\n';
    }
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 59992 KB Output is correct
2 Correct 13 ms 55900 KB Output is correct
3 Correct 12 ms 60164 KB Output is correct
4 Correct 12 ms 59996 KB Output is correct
5 Correct 12 ms 59996 KB Output is correct
6 Correct 12 ms 59992 KB Output is correct
7 Correct 12 ms 59996 KB Output is correct
8 Correct 12 ms 58124 KB Output is correct
9 Correct 13 ms 58104 KB Output is correct
10 Correct 12 ms 57948 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 59992 KB Output is correct
2 Correct 13 ms 55900 KB Output is correct
3 Correct 12 ms 60164 KB Output is correct
4 Correct 12 ms 59996 KB Output is correct
5 Correct 12 ms 59996 KB Output is correct
6 Correct 12 ms 59992 KB Output is correct
7 Correct 12 ms 59996 KB Output is correct
8 Correct 12 ms 58124 KB Output is correct
9 Correct 13 ms 58104 KB Output is correct
10 Correct 12 ms 57948 KB Output is correct
11 Correct 13 ms 60252 KB Output is correct
12 Correct 14 ms 60248 KB Output is correct
13 Correct 14 ms 60252 KB Output is correct
14 Correct 16 ms 60332 KB Output is correct
15 Correct 15 ms 60252 KB Output is correct
16 Correct 14 ms 58360 KB Output is correct
17 Correct 14 ms 58200 KB Output is correct
18 Correct 14 ms 58204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1227 ms 136852 KB Output is correct
2 Correct 1273 ms 136904 KB Output is correct
3 Correct 1233 ms 136916 KB Output is correct
4 Correct 1264 ms 136784 KB Output is correct
5 Correct 1053 ms 111588 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 83 ms 68180 KB Output is correct
2 Correct 78 ms 69640 KB Output is correct
3 Correct 72 ms 63824 KB Output is correct
4 Correct 81 ms 64208 KB Output is correct
5 Correct 75 ms 64012 KB Output is correct
6 Correct 65 ms 69460 KB Output is correct
7 Correct 62 ms 69372 KB Output is correct
8 Correct 67 ms 65680 KB Output is correct
9 Correct 42 ms 62688 KB Output is correct
10 Correct 71 ms 65744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 59992 KB Output is correct
2 Correct 13 ms 55900 KB Output is correct
3 Correct 12 ms 60164 KB Output is correct
4 Correct 12 ms 59996 KB Output is correct
5 Correct 12 ms 59996 KB Output is correct
6 Correct 12 ms 59992 KB Output is correct
7 Correct 12 ms 59996 KB Output is correct
8 Correct 12 ms 58124 KB Output is correct
9 Correct 13 ms 58104 KB Output is correct
10 Correct 12 ms 57948 KB Output is correct
11 Correct 13 ms 60252 KB Output is correct
12 Correct 14 ms 60248 KB Output is correct
13 Correct 14 ms 60252 KB Output is correct
14 Correct 16 ms 60332 KB Output is correct
15 Correct 15 ms 60252 KB Output is correct
16 Correct 14 ms 58360 KB Output is correct
17 Correct 14 ms 58200 KB Output is correct
18 Correct 14 ms 58204 KB Output is correct
19 Correct 202 ms 82540 KB Output is correct
20 Correct 204 ms 83276 KB Output is correct
21 Correct 167 ms 81888 KB Output is correct
22 Correct 163 ms 81728 KB Output is correct
23 Correct 170 ms 81764 KB Output is correct
24 Correct 134 ms 73300 KB Output is correct
25 Correct 131 ms 73424 KB Output is correct
26 Correct 151 ms 74036 KB Output is correct
27 Correct 150 ms 74056 KB Output is correct
28 Correct 148 ms 74212 KB Output is correct
29 Correct 156 ms 74860 KB Output is correct
30 Correct 185 ms 75096 KB Output is correct
31 Correct 155 ms 74836 KB Output is correct
32 Correct 161 ms 74836 KB Output is correct
33 Correct 169 ms 74884 KB Output is correct
34 Correct 126 ms 79052 KB Output is correct
35 Correct 131 ms 79168 KB Output is correct
36 Correct 126 ms 78936 KB Output is correct
37 Correct 128 ms 79088 KB Output is correct
38 Correct 128 ms 79188 KB Output is correct
39 Correct 149 ms 76432 KB Output is correct
40 Correct 113 ms 74196 KB Output is correct
41 Correct 137 ms 74900 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 12 ms 59992 KB Output is correct
2 Correct 13 ms 55900 KB Output is correct
3 Correct 12 ms 60164 KB Output is correct
4 Correct 12 ms 59996 KB Output is correct
5 Correct 12 ms 59996 KB Output is correct
6 Correct 12 ms 59992 KB Output is correct
7 Correct 12 ms 59996 KB Output is correct
8 Correct 12 ms 58124 KB Output is correct
9 Correct 13 ms 58104 KB Output is correct
10 Correct 12 ms 57948 KB Output is correct
11 Correct 13 ms 60252 KB Output is correct
12 Correct 14 ms 60248 KB Output is correct
13 Correct 14 ms 60252 KB Output is correct
14 Correct 16 ms 60332 KB Output is correct
15 Correct 15 ms 60252 KB Output is correct
16 Correct 14 ms 58360 KB Output is correct
17 Correct 14 ms 58200 KB Output is correct
18 Correct 14 ms 58204 KB Output is correct
19 Correct 1227 ms 136852 KB Output is correct
20 Correct 1273 ms 136904 KB Output is correct
21 Correct 1233 ms 136916 KB Output is correct
22 Correct 1264 ms 136784 KB Output is correct
23 Correct 1053 ms 111588 KB Output is correct
24 Correct 83 ms 68180 KB Output is correct
25 Correct 78 ms 69640 KB Output is correct
26 Correct 72 ms 63824 KB Output is correct
27 Correct 81 ms 64208 KB Output is correct
28 Correct 75 ms 64012 KB Output is correct
29 Correct 65 ms 69460 KB Output is correct
30 Correct 62 ms 69372 KB Output is correct
31 Correct 67 ms 65680 KB Output is correct
32 Correct 42 ms 62688 KB Output is correct
33 Correct 71 ms 65744 KB Output is correct
34 Correct 202 ms 82540 KB Output is correct
35 Correct 204 ms 83276 KB Output is correct
36 Correct 167 ms 81888 KB Output is correct
37 Correct 163 ms 81728 KB Output is correct
38 Correct 170 ms 81764 KB Output is correct
39 Correct 134 ms 73300 KB Output is correct
40 Correct 131 ms 73424 KB Output is correct
41 Correct 151 ms 74036 KB Output is correct
42 Correct 150 ms 74056 KB Output is correct
43 Correct 148 ms 74212 KB Output is correct
44 Correct 156 ms 74860 KB Output is correct
45 Correct 185 ms 75096 KB Output is correct
46 Correct 155 ms 74836 KB Output is correct
47 Correct 161 ms 74836 KB Output is correct
48 Correct 169 ms 74884 KB Output is correct
49 Correct 126 ms 79052 KB Output is correct
50 Correct 131 ms 79168 KB Output is correct
51 Correct 126 ms 78936 KB Output is correct
52 Correct 128 ms 79088 KB Output is correct
53 Correct 128 ms 79188 KB Output is correct
54 Correct 149 ms 76432 KB Output is correct
55 Correct 113 ms 74196 KB Output is correct
56 Correct 137 ms 74900 KB Output is correct
57 Correct 1272 ms 169412 KB Output is correct
58 Correct 1306 ms 169332 KB Output is correct
59 Correct 1169 ms 166452 KB Output is correct
60 Correct 1187 ms 166760 KB Output is correct
61 Correct 1196 ms 166972 KB Output is correct
62 Correct 1212 ms 166336 KB Output is correct
63 Correct 719 ms 135344 KB Output is correct
64 Correct 785 ms 135324 KB Output is correct
65 Correct 995 ms 140536 KB Output is correct
66 Correct 1018 ms 138372 KB Output is correct
67 Correct 997 ms 140948 KB Output is correct
68 Correct 1033 ms 143952 KB Output is correct
69 Correct 1055 ms 143692 KB Output is correct
70 Correct 1020 ms 143084 KB Output is correct
71 Correct 1012 ms 143292 KB Output is correct
72 Correct 1046 ms 143056 KB Output is correct
73 Correct 663 ms 142028 KB Output is correct
74 Correct 678 ms 142956 KB Output is correct
75 Correct 701 ms 141908 KB Output is correct
76 Correct 675 ms 141852 KB Output is correct
77 Correct 739 ms 141896 KB Output is correct
78 Correct 892 ms 147904 KB Output is correct
79 Correct 632 ms 128332 KB Output is correct
80 Correct 850 ms 141808 KB Output is correct