답안 #521696

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
521696 2022-02-02T18:25:19 Z inluminas Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
64 / 100
1056 ms 262148 KB
#include"bits/stdc++.h"
using namespace std;
 
#define ll long long
#define endl "\n"
#define fastio ios_base::sync_with_stdio(false)
#define inf LLONG_MAX

const ll lmt=1e6+10;
vector<ll>adj[4*lmt];
ll a[lmt],mx,tree[4*lmt];

void build(ll at,ll L,ll R){
  if(L==R){
    adj[at].push_back(a[L]);
    return;
  }
  ll mid=(L+R)>>1;
  build(at*2,L,mid);
  build(at*2+1,mid+1,R);

  ll res=adj[at*2].back();
  ll lo=0,hi=adj[at*2+1].size()-1;
  while(hi-lo>1){
    mid=(lo+hi)>>1;
    if(adj[at*2+1][mid]<res) lo=mid;
    else hi=mid;
  }

  tree[at]=max(tree[at*2],tree[at*2+1]);

  if(adj[at*2+1][hi]<res) tree[at]=max(tree[at],res+adj[at*2+1][hi]);
  else if(adj[at*2+1][lo]<res) tree[at]=max(tree[at],res+adj[at*2+1][lo]);

  adj[at]=adj[at*2];
  adj[at].insert(adj[at].end(),adj[at*2+1].begin(),adj[at*2+1].end());
  sort(adj[at].begin(),adj[at].end());
}

ll query(ll at,ll L,ll R,ll l,ll r){
  if(r<L || R<l || r<l) return 0;
  if(l<=L && R<=r){
    if(L==l){
      mx=max(mx,adj[at].back());
      return tree[at];
    }else if(adj[at][0]>=mx){
      mx=max(mx,adj[at].back());
      return tree[at];
    }else{
      ll lo=0,hi=adj[at].size()-1;
      while(hi-lo>1){
        ll mid=(lo+hi)>>1;
        if(adj[at][mid]<mx) lo=mid;
        else hi=mid;
      }
      ll res=tree[at];
      if(adj[at][hi]<mx){
        res=max(res,mx+adj[at][hi]);
      }else if(adj[at][lo]<mx){
        res=max(res,mx+adj[at][lo]);
      }
      mx=max(mx,adj[at].back());
      return res;
    }
  }
  ll mid=(L+R)>>1;
  ll x=query(at*2,L,mid,l,r),y=query(at*2+1,mid+1,R,l,r);
  return max(x,y);
}

int main(){
  fastio;

  ll n,m;
  cin>>n>>m;
  for(ll i=1;i<=n;i++){
    cin>>a[i];
  }
  build(1,1,n);
  for(ll i=1;i<=m;i++){
    ll l,r,k;
    cin>>l>>r>>k;
    ll res=query(1,1,n,l,r);
    bool ans=(k>=res);
    cout<<ans<<endl;
    mx=0;
  }
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 94204 KB Output is correct
2 Correct 43 ms 94168 KB Output is correct
3 Correct 47 ms 94140 KB Output is correct
4 Correct 43 ms 94220 KB Output is correct
5 Correct 46 ms 94304 KB Output is correct
6 Correct 44 ms 94260 KB Output is correct
7 Correct 43 ms 94304 KB Output is correct
8 Correct 43 ms 94304 KB Output is correct
9 Correct 43 ms 94204 KB Output is correct
10 Correct 44 ms 94276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 94204 KB Output is correct
2 Correct 43 ms 94168 KB Output is correct
3 Correct 47 ms 94140 KB Output is correct
4 Correct 43 ms 94220 KB Output is correct
5 Correct 46 ms 94304 KB Output is correct
6 Correct 44 ms 94260 KB Output is correct
7 Correct 43 ms 94304 KB Output is correct
8 Correct 43 ms 94304 KB Output is correct
9 Correct 43 ms 94204 KB Output is correct
10 Correct 44 ms 94276 KB Output is correct
11 Correct 49 ms 94444 KB Output is correct
12 Correct 54 ms 95216 KB Output is correct
13 Correct 53 ms 95124 KB Output is correct
14 Correct 55 ms 95252 KB Output is correct
15 Correct 56 ms 95236 KB Output is correct
16 Correct 54 ms 95172 KB Output is correct
17 Correct 52 ms 95016 KB Output is correct
18 Correct 53 ms 95172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 814 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 429 ms 114892 KB Output is correct
2 Correct 423 ms 116760 KB Output is correct
3 Correct 304 ms 116696 KB Output is correct
4 Correct 302 ms 116700 KB Output is correct
5 Correct 311 ms 116660 KB Output is correct
6 Correct 273 ms 116560 KB Output is correct
7 Correct 271 ms 116580 KB Output is correct
8 Correct 307 ms 116320 KB Output is correct
9 Correct 201 ms 95940 KB Output is correct
10 Correct 302 ms 116388 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 94204 KB Output is correct
2 Correct 43 ms 94168 KB Output is correct
3 Correct 47 ms 94140 KB Output is correct
4 Correct 43 ms 94220 KB Output is correct
5 Correct 46 ms 94304 KB Output is correct
6 Correct 44 ms 94260 KB Output is correct
7 Correct 43 ms 94304 KB Output is correct
8 Correct 43 ms 94304 KB Output is correct
9 Correct 43 ms 94204 KB Output is correct
10 Correct 44 ms 94276 KB Output is correct
11 Correct 49 ms 94444 KB Output is correct
12 Correct 54 ms 95216 KB Output is correct
13 Correct 53 ms 95124 KB Output is correct
14 Correct 55 ms 95252 KB Output is correct
15 Correct 56 ms 95236 KB Output is correct
16 Correct 54 ms 95172 KB Output is correct
17 Correct 52 ms 95016 KB Output is correct
18 Correct 53 ms 95172 KB Output is correct
19 Correct 1056 ms 143300 KB Output is correct
20 Correct 1004 ms 143356 KB Output is correct
21 Correct 885 ms 143220 KB Output is correct
22 Correct 886 ms 143288 KB Output is correct
23 Correct 900 ms 143200 KB Output is correct
24 Correct 559 ms 143100 KB Output is correct
25 Correct 542 ms 142988 KB Output is correct
26 Correct 631 ms 143272 KB Output is correct
27 Correct 636 ms 143280 KB Output is correct
28 Correct 655 ms 143280 KB Output is correct
29 Correct 642 ms 143272 KB Output is correct
30 Correct 666 ms 143324 KB Output is correct
31 Correct 664 ms 143288 KB Output is correct
32 Correct 656 ms 143472 KB Output is correct
33 Correct 669 ms 143360 KB Output is correct
34 Correct 545 ms 142968 KB Output is correct
35 Correct 548 ms 142940 KB Output is correct
36 Correct 534 ms 142812 KB Output is correct
37 Correct 525 ms 142700 KB Output is correct
38 Correct 535 ms 142964 KB Output is correct
39 Correct 659 ms 141940 KB Output is correct
40 Correct 500 ms 125236 KB Output is correct
41 Correct 644 ms 141488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 94204 KB Output is correct
2 Correct 43 ms 94168 KB Output is correct
3 Correct 47 ms 94140 KB Output is correct
4 Correct 43 ms 94220 KB Output is correct
5 Correct 46 ms 94304 KB Output is correct
6 Correct 44 ms 94260 KB Output is correct
7 Correct 43 ms 94304 KB Output is correct
8 Correct 43 ms 94304 KB Output is correct
9 Correct 43 ms 94204 KB Output is correct
10 Correct 44 ms 94276 KB Output is correct
11 Correct 49 ms 94444 KB Output is correct
12 Correct 54 ms 95216 KB Output is correct
13 Correct 53 ms 95124 KB Output is correct
14 Correct 55 ms 95252 KB Output is correct
15 Correct 56 ms 95236 KB Output is correct
16 Correct 54 ms 95172 KB Output is correct
17 Correct 52 ms 95016 KB Output is correct
18 Correct 53 ms 95172 KB Output is correct
19 Runtime error 814 ms 262148 KB Execution killed with signal 9
20 Halted 0 ms 0 KB -