답안 #174720

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
174720 2020-01-06T22:01:30 Z GoldeN Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1964 ms 150724 KB
#include <bits/stdc++.h>
 
using namespace std;
const int N = 1e6 + 5;
typedef long long ll;
const ll inf=1e15;
#define pb push_back
const int INF=(0x3f3f3f3f);
 
int a[N],b[N];
int T[4*N],mx[4*N];
 
void build(int v,int tl,int tr){
  if(tl==tr){
    T[v]=b[tl];
    return;
  }
  int tm=(tl+tr)/2;
  build(v+v,tl,tm);
  build(v+v+1,tm+1,tr);
  T[v]=max(T[v+v],T[v+v+1]);
}
 
int l[N],r[N],mo[N],answ[N];
vector<int>idx[N];
vector<int>st[N];
 
int query(int v,int tl,int tr,int l,int r){
  if(l>r)return 0;
  if(tl==l&&tr==r)return T[v];
  int tm=(tl+tr)/2;
  return max(query(v+v,tl,tm,l,min(tm,r)),query(v+v+1,tm+1,tr,max(tm+1,l),r));
}
 
void update(int v,int tl,int tr,int pos,int val){
  if(tl==tr){
    T[v]=val;
    return;
  }
  int tm=(tl+tr)/2;
  if(pos<=tm)update(v+v,tl,tm,pos,val);
  else update(v+v+1,tm+1,tr,pos,val);
  T[v]=max(T[v+v],T[v+v+1]);
}
 
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);cout.tie(0);
  
  int n,m;
  cin>>n>>m;
  vector<int>h;
  for(int i=1;i<=n;i++){
    cin>>a[i];
    while(!h.empty()&&a[h.back()]<=a[i])h.pop_back();
    if(h.empty())h.pb(i);
    else{
      int idx=h.back();
      st[idx].pb(i);
      b[i]=a[idx]+a[i];
      h.pb(i);
    }
  }
  build(1,1,n);
  for(int i=1;i<=m;i++){
    cin>>l[i]>>r[i]>>mo[i];
    idx[l[i]].pb(i);
  }
  
  for(int i=1;i<=n;i++){
    for(auto x:idx[i]){
      answ[x]=query(1,1,n,i,r[x]);
    }
    for(auto x:st[i]){
      update(1,1,n,x,0);
    }
  }
  for(int i=1;i<=m;i++){
    cout<<(answ[i]<=mo[i]?"1\n":"0\n");
  }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 47352 KB Output is correct
2 Correct 44 ms 47352 KB Output is correct
3 Correct 45 ms 47352 KB Output is correct
4 Correct 45 ms 47352 KB Output is correct
5 Correct 45 ms 47228 KB Output is correct
6 Correct 46 ms 47480 KB Output is correct
7 Correct 46 ms 47480 KB Output is correct
8 Correct 45 ms 47436 KB Output is correct
9 Correct 46 ms 47352 KB Output is correct
10 Correct 45 ms 47352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 47352 KB Output is correct
2 Correct 44 ms 47352 KB Output is correct
3 Correct 45 ms 47352 KB Output is correct
4 Correct 45 ms 47352 KB Output is correct
5 Correct 45 ms 47228 KB Output is correct
6 Correct 46 ms 47480 KB Output is correct
7 Correct 46 ms 47480 KB Output is correct
8 Correct 45 ms 47436 KB Output is correct
9 Correct 46 ms 47352 KB Output is correct
10 Correct 45 ms 47352 KB Output is correct
11 Correct 48 ms 47580 KB Output is correct
12 Correct 49 ms 47736 KB Output is correct
13 Correct 49 ms 47736 KB Output is correct
14 Correct 52 ms 47868 KB Output is correct
15 Correct 51 ms 47876 KB Output is correct
16 Correct 49 ms 47784 KB Output is correct
17 Correct 49 ms 47608 KB Output is correct
18 Correct 50 ms 47740 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1933 ms 115256 KB Output is correct
2 Correct 1953 ms 127208 KB Output is correct
3 Correct 1952 ms 127004 KB Output is correct
4 Correct 1940 ms 127280 KB Output is correct
5 Correct 1631 ms 107000 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 177 ms 54508 KB Output is correct
2 Correct 159 ms 54016 KB Output is correct
3 Correct 144 ms 52728 KB Output is correct
4 Correct 149 ms 53192 KB Output is correct
5 Correct 149 ms 53128 KB Output is correct
6 Correct 121 ms 51796 KB Output is correct
7 Correct 123 ms 51856 KB Output is correct
8 Correct 137 ms 52980 KB Output is correct
9 Correct 89 ms 50260 KB Output is correct
10 Correct 136 ms 52952 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 47352 KB Output is correct
2 Correct 44 ms 47352 KB Output is correct
3 Correct 45 ms 47352 KB Output is correct
4 Correct 45 ms 47352 KB Output is correct
5 Correct 45 ms 47228 KB Output is correct
6 Correct 46 ms 47480 KB Output is correct
7 Correct 46 ms 47480 KB Output is correct
8 Correct 45 ms 47436 KB Output is correct
9 Correct 46 ms 47352 KB Output is correct
10 Correct 45 ms 47352 KB Output is correct
11 Correct 48 ms 47580 KB Output is correct
12 Correct 49 ms 47736 KB Output is correct
13 Correct 49 ms 47736 KB Output is correct
14 Correct 52 ms 47868 KB Output is correct
15 Correct 51 ms 47876 KB Output is correct
16 Correct 49 ms 47784 KB Output is correct
17 Correct 49 ms 47608 KB Output is correct
18 Correct 50 ms 47740 KB Output is correct
19 Correct 362 ms 62328 KB Output is correct
20 Correct 360 ms 62324 KB Output is correct
21 Correct 301 ms 59896 KB Output is correct
22 Correct 303 ms 60104 KB Output is correct
23 Correct 310 ms 60012 KB Output is correct
24 Correct 242 ms 55800 KB Output is correct
25 Correct 237 ms 55800 KB Output is correct
26 Correct 264 ms 56700 KB Output is correct
27 Correct 267 ms 56820 KB Output is correct
28 Correct 275 ms 57444 KB Output is correct
29 Correct 304 ms 58232 KB Output is correct
30 Correct 314 ms 58316 KB Output is correct
31 Correct 310 ms 58188 KB Output is correct
32 Correct 308 ms 58232 KB Output is correct
33 Correct 318 ms 58360 KB Output is correct
34 Correct 225 ms 55544 KB Output is correct
35 Correct 221 ms 55572 KB Output is correct
36 Correct 223 ms 55564 KB Output is correct
37 Correct 223 ms 55548 KB Output is correct
38 Correct 224 ms 55420 KB Output is correct
39 Correct 267 ms 58228 KB Output is correct
40 Correct 202 ms 55532 KB Output is correct
41 Correct 252 ms 58008 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 45 ms 47352 KB Output is correct
2 Correct 44 ms 47352 KB Output is correct
3 Correct 45 ms 47352 KB Output is correct
4 Correct 45 ms 47352 KB Output is correct
5 Correct 45 ms 47228 KB Output is correct
6 Correct 46 ms 47480 KB Output is correct
7 Correct 46 ms 47480 KB Output is correct
8 Correct 45 ms 47436 KB Output is correct
9 Correct 46 ms 47352 KB Output is correct
10 Correct 45 ms 47352 KB Output is correct
11 Correct 48 ms 47580 KB Output is correct
12 Correct 49 ms 47736 KB Output is correct
13 Correct 49 ms 47736 KB Output is correct
14 Correct 52 ms 47868 KB Output is correct
15 Correct 51 ms 47876 KB Output is correct
16 Correct 49 ms 47784 KB Output is correct
17 Correct 49 ms 47608 KB Output is correct
18 Correct 50 ms 47740 KB Output is correct
19 Correct 1933 ms 115256 KB Output is correct
20 Correct 1953 ms 127208 KB Output is correct
21 Correct 1952 ms 127004 KB Output is correct
22 Correct 1940 ms 127280 KB Output is correct
23 Correct 1631 ms 107000 KB Output is correct
24 Correct 177 ms 54508 KB Output is correct
25 Correct 159 ms 54016 KB Output is correct
26 Correct 144 ms 52728 KB Output is correct
27 Correct 149 ms 53192 KB Output is correct
28 Correct 149 ms 53128 KB Output is correct
29 Correct 121 ms 51796 KB Output is correct
30 Correct 123 ms 51856 KB Output is correct
31 Correct 137 ms 52980 KB Output is correct
32 Correct 89 ms 50260 KB Output is correct
33 Correct 136 ms 52952 KB Output is correct
34 Correct 362 ms 62328 KB Output is correct
35 Correct 360 ms 62324 KB Output is correct
36 Correct 301 ms 59896 KB Output is correct
37 Correct 303 ms 60104 KB Output is correct
38 Correct 310 ms 60012 KB Output is correct
39 Correct 242 ms 55800 KB Output is correct
40 Correct 237 ms 55800 KB Output is correct
41 Correct 264 ms 56700 KB Output is correct
42 Correct 267 ms 56820 KB Output is correct
43 Correct 275 ms 57444 KB Output is correct
44 Correct 304 ms 58232 KB Output is correct
45 Correct 314 ms 58316 KB Output is correct
46 Correct 310 ms 58188 KB Output is correct
47 Correct 308 ms 58232 KB Output is correct
48 Correct 318 ms 58360 KB Output is correct
49 Correct 225 ms 55544 KB Output is correct
50 Correct 221 ms 55572 KB Output is correct
51 Correct 223 ms 55564 KB Output is correct
52 Correct 223 ms 55548 KB Output is correct
53 Correct 224 ms 55420 KB Output is correct
54 Correct 267 ms 58228 KB Output is correct
55 Correct 202 ms 55532 KB Output is correct
56 Correct 252 ms 58008 KB Output is correct
57 Correct 1964 ms 150712 KB Output is correct
58 Correct 1944 ms 150724 KB Output is correct
59 Correct 1883 ms 127852 KB Output is correct
60 Correct 1854 ms 137208 KB Output is correct
61 Correct 1860 ms 145032 KB Output is correct
62 Correct 1926 ms 144964 KB Output is correct
63 Correct 1137 ms 102520 KB Output is correct
64 Correct 1135 ms 100840 KB Output is correct
65 Correct 1579 ms 123976 KB Output is correct
66 Correct 1552 ms 123980 KB Output is correct
67 Correct 1561 ms 124588 KB Output is correct
68 Correct 1634 ms 130652 KB Output is correct
69 Correct 1641 ms 130544 KB Output is correct
70 Correct 1651 ms 128456 KB Output is correct
71 Correct 1640 ms 128508 KB Output is correct
72 Correct 1641 ms 128160 KB Output is correct
73 Correct 1073 ms 112096 KB Output is correct
74 Correct 1102 ms 112852 KB Output is correct
75 Correct 1081 ms 111796 KB Output is correct
76 Correct 1079 ms 112268 KB Output is correct
77 Correct 1074 ms 111868 KB Output is correct
78 Correct 1446 ms 122740 KB Output is correct
79 Correct 1002 ms 104984 KB Output is correct
80 Correct 1376 ms 119040 KB Output is correct