답안 #521698

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
521698 2022-02-02T18:33:36 Z inluminas Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
64 / 100
3000 ms 211784 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 int lmt=1e6+10;
vector<int>adj[3*lmt];
int a[lmt],mx,tree[3*lmt];
 
void build(int at,int L,int R){
  if(L==R){
    adj[at].push_back(a[L]);
    return;
  }
  int mid=(L+R)>>1;
  build(at*2,L,mid);
  build(at*2+1,mid+1,R);
 
  int res=adj[at*2].back();
  int 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());
}
 
int query(int at,int L,int R,int l,int 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{
      int lo=0,hi=adj[at].size()-1;
      while(hi-lo>1){
        int mid=(lo+hi)>>1;
        if(adj[at][mid]<mx) lo=mid;
        else hi=mid;
      }
      int 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;
    }
  }
  int mid=(L+R)>>1;
  int 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;
 
  int n,m;
  cin>>n>>m;
  for(int i=1;i<=n;i++){
    cin>>a[i];
  }
  build(1,1,n);
  for(int i=1;i<=m;i++){
    int l,r,k;
    cin>>l>>r>>k;
    int res=query(1,1,n,l,r);
    bool ans=(k>=res);
    cout<<ans<<endl;
    mx=0;
  }
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 70732 KB Output is correct
2 Correct 32 ms 70672 KB Output is correct
3 Correct 32 ms 70740 KB Output is correct
4 Correct 37 ms 70840 KB Output is correct
5 Correct 32 ms 70780 KB Output is correct
6 Correct 33 ms 70732 KB Output is correct
7 Correct 34 ms 70700 KB Output is correct
8 Correct 33 ms 70724 KB Output is correct
9 Correct 33 ms 70700 KB Output is correct
10 Correct 33 ms 70752 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 70732 KB Output is correct
2 Correct 32 ms 70672 KB Output is correct
3 Correct 32 ms 70740 KB Output is correct
4 Correct 37 ms 70840 KB Output is correct
5 Correct 32 ms 70780 KB Output is correct
6 Correct 33 ms 70732 KB Output is correct
7 Correct 34 ms 70700 KB Output is correct
8 Correct 33 ms 70724 KB Output is correct
9 Correct 33 ms 70700 KB Output is correct
10 Correct 33 ms 70752 KB Output is correct
11 Correct 39 ms 70836 KB Output is correct
12 Correct 41 ms 71216 KB Output is correct
13 Correct 45 ms 71244 KB Output is correct
14 Correct 50 ms 71320 KB Output is correct
15 Correct 46 ms 71264 KB Output is correct
16 Correct 44 ms 71340 KB Output is correct
17 Correct 41 ms 71108 KB Output is correct
18 Correct 42 ms 71204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3094 ms 211784 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 425 ms 83504 KB Output is correct
2 Correct 420 ms 83552 KB Output is correct
3 Correct 307 ms 83520 KB Output is correct
4 Correct 303 ms 83552 KB Output is correct
5 Correct 320 ms 83516 KB Output is correct
6 Correct 297 ms 83532 KB Output is correct
7 Correct 294 ms 83680 KB Output is correct
8 Correct 366 ms 83536 KB Output is correct
9 Correct 201 ms 70920 KB Output is correct
10 Correct 310 ms 83544 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 70732 KB Output is correct
2 Correct 32 ms 70672 KB Output is correct
3 Correct 32 ms 70740 KB Output is correct
4 Correct 37 ms 70840 KB Output is correct
5 Correct 32 ms 70780 KB Output is correct
6 Correct 33 ms 70732 KB Output is correct
7 Correct 34 ms 70700 KB Output is correct
8 Correct 33 ms 70724 KB Output is correct
9 Correct 33 ms 70700 KB Output is correct
10 Correct 33 ms 70752 KB Output is correct
11 Correct 39 ms 70836 KB Output is correct
12 Correct 41 ms 71216 KB Output is correct
13 Correct 45 ms 71244 KB Output is correct
14 Correct 50 ms 71320 KB Output is correct
15 Correct 46 ms 71264 KB Output is correct
16 Correct 44 ms 71340 KB Output is correct
17 Correct 41 ms 71108 KB Output is correct
18 Correct 42 ms 71204 KB Output is correct
19 Correct 1092 ms 97172 KB Output is correct
20 Correct 972 ms 97264 KB Output is correct
21 Correct 878 ms 97048 KB Output is correct
22 Correct 873 ms 97144 KB Output is correct
23 Correct 889 ms 97200 KB Output is correct
24 Correct 522 ms 97352 KB Output is correct
25 Correct 525 ms 97392 KB Output is correct
26 Correct 576 ms 97092 KB Output is correct
27 Correct 598 ms 97068 KB Output is correct
28 Correct 614 ms 97056 KB Output is correct
29 Correct 614 ms 97144 KB Output is correct
30 Correct 603 ms 97272 KB Output is correct
31 Correct 603 ms 97128 KB Output is correct
32 Correct 616 ms 97124 KB Output is correct
33 Correct 616 ms 97080 KB Output is correct
34 Correct 521 ms 97132 KB Output is correct
35 Correct 524 ms 97144 KB Output is correct
36 Correct 537 ms 97200 KB Output is correct
37 Correct 516 ms 97136 KB Output is correct
38 Correct 518 ms 97084 KB Output is correct
39 Correct 631 ms 97256 KB Output is correct
40 Correct 490 ms 87852 KB Output is correct
41 Correct 624 ms 97024 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 32 ms 70732 KB Output is correct
2 Correct 32 ms 70672 KB Output is correct
3 Correct 32 ms 70740 KB Output is correct
4 Correct 37 ms 70840 KB Output is correct
5 Correct 32 ms 70780 KB Output is correct
6 Correct 33 ms 70732 KB Output is correct
7 Correct 34 ms 70700 KB Output is correct
8 Correct 33 ms 70724 KB Output is correct
9 Correct 33 ms 70700 KB Output is correct
10 Correct 33 ms 70752 KB Output is correct
11 Correct 39 ms 70836 KB Output is correct
12 Correct 41 ms 71216 KB Output is correct
13 Correct 45 ms 71244 KB Output is correct
14 Correct 50 ms 71320 KB Output is correct
15 Correct 46 ms 71264 KB Output is correct
16 Correct 44 ms 71340 KB Output is correct
17 Correct 41 ms 71108 KB Output is correct
18 Correct 42 ms 71204 KB Output is correct
19 Execution timed out 3094 ms 211784 KB Time limit exceeded
20 Halted 0 ms 0 KB -