답안 #335030

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
335030 2020-12-10T21:19:19 Z ivan_tudor Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
1860 ms 96620 KB
#include<bits/stdc++.h>
using namespace std;
const int N =  1e6 + 5;
int aint[4*N];
void build(int nod,int l,int r){
  if(l == r){
    aint[nod] = INT_MIN;
    return;
  }
  int mid = (l + r)/2;
  build(2*nod, l, mid);
  build(2*nod + 1, mid+1, r);
  aint[nod] = INT_MIN;
}
void update(int nod, int l, int r, int upoz,int val){
  if(upoz < l || upoz > r)
    return;
  if(l == r){
    aint[nod] = val;
    return;
  }
  int mid = (l + r)/2;
  update(2*nod, l, mid, upoz, val);
  update(2*nod + 1, mid+1, r, upoz, val);
  aint[nod] = max(aint[2*nod], aint[2*nod + 1]);
}
int query(int nod,int l,int r, int ql, int qr){
  if(r < ql || l > qr)
    return INT_MIN;
  if(ql <=l && r <= qr)
    return aint[nod];
  int mid = (l + r)/2;
  int ls = query(2*nod, l, mid, ql, qr);
  int rs = query(2*nod + 1, mid+1, r, ql, qr);
  return max(ls, rs);
}
struct qry{
  int poz, w;
  int id;
};
int v[N];
int ans[N];
vector<qry> qu[N];
int st[N];
int main()
{
  //freopen(".in","r",stdin);
  ios::sync_with_stdio(false);
  cin.tie(0),cout.tie(0);
  int n, q;
  cin>>n>>q;
  for(int i=1;i<=n;i++){
    cin>>v[i];
  }
  build(1, 1, n);
  for(int i = 1; i<=q;i ++){
    int l, r, w;
    cin>>l>>r>>w;
    qu[r].push_back({l, w, i});
  }
  int vf =0;
  for(int i=1;i<=n;i++){
    while(vf > 0 && v[st[vf]] <= v[i])
      vf--;
    if(vf){
      update(1, 1, n, st[vf], v[i] + v[st[vf]]);
    }
    st[++vf] = i;
    for(auto x:qu[i]){
      if(query(1, 1, n, x.poz, i) > x.w)
        ans[x.id] = 0;
      else
        ans[x.id] = 1;
    }
  }
  for(int i=1;i<=q;i++)
    cout<<ans[i]<<"\n";
  return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23788 KB Output is correct
2 Correct 15 ms 23788 KB Output is correct
3 Correct 15 ms 23916 KB Output is correct
4 Correct 15 ms 23916 KB Output is correct
5 Correct 17 ms 23916 KB Output is correct
6 Correct 15 ms 23916 KB Output is correct
7 Correct 16 ms 23916 KB Output is correct
8 Correct 15 ms 23916 KB Output is correct
9 Correct 15 ms 23916 KB Output is correct
10 Correct 15 ms 23916 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23788 KB Output is correct
2 Correct 15 ms 23788 KB Output is correct
3 Correct 15 ms 23916 KB Output is correct
4 Correct 15 ms 23916 KB Output is correct
5 Correct 17 ms 23916 KB Output is correct
6 Correct 15 ms 23916 KB Output is correct
7 Correct 16 ms 23916 KB Output is correct
8 Correct 15 ms 23916 KB Output is correct
9 Correct 15 ms 23916 KB Output is correct
10 Correct 15 ms 23916 KB Output is correct
11 Correct 17 ms 23916 KB Output is correct
12 Correct 18 ms 24044 KB Output is correct
13 Correct 19 ms 24044 KB Output is correct
14 Correct 20 ms 24044 KB Output is correct
15 Correct 21 ms 24044 KB Output is correct
16 Correct 19 ms 24044 KB Output is correct
17 Correct 18 ms 24064 KB Output is correct
18 Correct 19 ms 24044 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1825 ms 76652 KB Output is correct
2 Correct 1820 ms 64620 KB Output is correct
3 Correct 1860 ms 79596 KB Output is correct
4 Correct 1834 ms 79608 KB Output is correct
5 Correct 1530 ms 96620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 138 ms 28012 KB Output is correct
2 Correct 128 ms 27756 KB Output is correct
3 Correct 112 ms 27884 KB Output is correct
4 Correct 113 ms 28012 KB Output is correct
5 Correct 116 ms 28012 KB Output is correct
6 Correct 93 ms 27628 KB Output is correct
7 Correct 92 ms 27628 KB Output is correct
8 Correct 119 ms 27812 KB Output is correct
9 Correct 58 ms 25912 KB Output is correct
10 Correct 109 ms 27812 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23788 KB Output is correct
2 Correct 15 ms 23788 KB Output is correct
3 Correct 15 ms 23916 KB Output is correct
4 Correct 15 ms 23916 KB Output is correct
5 Correct 17 ms 23916 KB Output is correct
6 Correct 15 ms 23916 KB Output is correct
7 Correct 16 ms 23916 KB Output is correct
8 Correct 15 ms 23916 KB Output is correct
9 Correct 15 ms 23916 KB Output is correct
10 Correct 15 ms 23916 KB Output is correct
11 Correct 17 ms 23916 KB Output is correct
12 Correct 18 ms 24044 KB Output is correct
13 Correct 19 ms 24044 KB Output is correct
14 Correct 20 ms 24044 KB Output is correct
15 Correct 21 ms 24044 KB Output is correct
16 Correct 19 ms 24044 KB Output is correct
17 Correct 18 ms 24064 KB Output is correct
18 Correct 19 ms 24044 KB Output is correct
19 Correct 314 ms 32236 KB Output is correct
20 Correct 302 ms 32236 KB Output is correct
21 Correct 265 ms 31852 KB Output is correct
22 Correct 267 ms 31860 KB Output is correct
23 Correct 265 ms 31596 KB Output is correct
24 Correct 207 ms 31692 KB Output is correct
25 Correct 209 ms 31596 KB Output is correct
26 Correct 237 ms 31852 KB Output is correct
27 Correct 236 ms 31724 KB Output is correct
28 Correct 243 ms 31852 KB Output is correct
29 Correct 253 ms 32108 KB Output is correct
30 Correct 255 ms 32108 KB Output is correct
31 Correct 253 ms 32108 KB Output is correct
32 Correct 258 ms 32088 KB Output is correct
33 Correct 257 ms 32108 KB Output is correct
34 Correct 198 ms 31212 KB Output is correct
35 Correct 195 ms 31212 KB Output is correct
36 Correct 192 ms 31340 KB Output is correct
37 Correct 186 ms 31212 KB Output is correct
38 Correct 191 ms 31336 KB Output is correct
39 Correct 234 ms 31780 KB Output is correct
40 Correct 177 ms 30240 KB Output is correct
41 Correct 234 ms 31776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 23788 KB Output is correct
2 Correct 15 ms 23788 KB Output is correct
3 Correct 15 ms 23916 KB Output is correct
4 Correct 15 ms 23916 KB Output is correct
5 Correct 17 ms 23916 KB Output is correct
6 Correct 15 ms 23916 KB Output is correct
7 Correct 16 ms 23916 KB Output is correct
8 Correct 15 ms 23916 KB Output is correct
9 Correct 15 ms 23916 KB Output is correct
10 Correct 15 ms 23916 KB Output is correct
11 Correct 17 ms 23916 KB Output is correct
12 Correct 18 ms 24044 KB Output is correct
13 Correct 19 ms 24044 KB Output is correct
14 Correct 20 ms 24044 KB Output is correct
15 Correct 21 ms 24044 KB Output is correct
16 Correct 19 ms 24044 KB Output is correct
17 Correct 18 ms 24064 KB Output is correct
18 Correct 19 ms 24044 KB Output is correct
19 Correct 1825 ms 76652 KB Output is correct
20 Correct 1820 ms 64620 KB Output is correct
21 Correct 1860 ms 79596 KB Output is correct
22 Correct 1834 ms 79608 KB Output is correct
23 Correct 1530 ms 96620 KB Output is correct
24 Correct 138 ms 28012 KB Output is correct
25 Correct 128 ms 27756 KB Output is correct
26 Correct 112 ms 27884 KB Output is correct
27 Correct 113 ms 28012 KB Output is correct
28 Correct 116 ms 28012 KB Output is correct
29 Correct 93 ms 27628 KB Output is correct
30 Correct 92 ms 27628 KB Output is correct
31 Correct 119 ms 27812 KB Output is correct
32 Correct 58 ms 25912 KB Output is correct
33 Correct 109 ms 27812 KB Output is correct
34 Correct 314 ms 32236 KB Output is correct
35 Correct 302 ms 32236 KB Output is correct
36 Correct 265 ms 31852 KB Output is correct
37 Correct 267 ms 31860 KB Output is correct
38 Correct 265 ms 31596 KB Output is correct
39 Correct 207 ms 31692 KB Output is correct
40 Correct 209 ms 31596 KB Output is correct
41 Correct 237 ms 31852 KB Output is correct
42 Correct 236 ms 31724 KB Output is correct
43 Correct 243 ms 31852 KB Output is correct
44 Correct 253 ms 32108 KB Output is correct
45 Correct 255 ms 32108 KB Output is correct
46 Correct 253 ms 32108 KB Output is correct
47 Correct 258 ms 32088 KB Output is correct
48 Correct 257 ms 32108 KB Output is correct
49 Correct 198 ms 31212 KB Output is correct
50 Correct 195 ms 31212 KB Output is correct
51 Correct 192 ms 31340 KB Output is correct
52 Correct 186 ms 31212 KB Output is correct
53 Correct 191 ms 31336 KB Output is correct
54 Correct 234 ms 31780 KB Output is correct
55 Correct 177 ms 30240 KB Output is correct
56 Correct 234 ms 31776 KB Output is correct
57 Correct 1833 ms 79108 KB Output is correct
58 Correct 1819 ms 79596 KB Output is correct
59 Correct 1735 ms 78060 KB Output is correct
60 Correct 1746 ms 78260 KB Output is correct
61 Correct 1756 ms 77932 KB Output is correct
62 Correct 1750 ms 78056 KB Output is correct
63 Correct 1094 ms 91992 KB Output is correct
64 Correct 1094 ms 91884 KB Output is correct
65 Correct 1427 ms 77324 KB Output is correct
66 Correct 1431 ms 77420 KB Output is correct
67 Correct 1416 ms 77932 KB Output is correct
68 Correct 1500 ms 79340 KB Output is correct
69 Correct 1505 ms 79396 KB Output is correct
70 Correct 1500 ms 78828 KB Output is correct
71 Correct 1490 ms 74476 KB Output is correct
72 Correct 1514 ms 79084 KB Output is correct
73 Correct 964 ms 87788 KB Output is correct
74 Correct 997 ms 88940 KB Output is correct
75 Correct 959 ms 88044 KB Output is correct
76 Correct 962 ms 87956 KB Output is correct
77 Correct 961 ms 87660 KB Output is correct
78 Correct 1341 ms 71580 KB Output is correct
79 Correct 924 ms 55440 KB Output is correct
80 Correct 1369 ms 63760 KB Output is correct