답안 #168297

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
168297 2019-12-12T10:40:49 Z Nordway Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
1414 ms 107392 KB
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define x first
#define y second
#define pb push_back
#define mp make_pair
#define all(v) v.begin(),v.end()
#define sz(v) (int)v.size()
#define up_b upper_bound
#define low_b lower_bound
#define nl '\n'

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;

const int N=1e6+11;
const int M=1e6+11;
const int inf=1e9;
const ll INF=1e18;
const ll mod=1e9+7;
const double EPS=1e-9;

int t[4*N];
vector<int>inv[N];
pair<pair<int,int>,pair<int,int>>q[N];
int ans[N];
int a[N];

void upd(int v,int tl,int tr,int pos,int val){
  if(tl==tr){
    t[v]=max(t[v],val);
    return ;
  }
  int tm=(tl+tr)/2;
  if(pos<=tm)upd(v*2,tl,tm,pos,val);
  else upd(v*2+1,tm+1,tr,pos,val);
  t[v]=max(t[v*2],t[v*2+1]);
}

int get(int v,int tl,int tr,int l,int r){
  if(tl>r||l>tr)return 0;
  if(l<=tl&&tr<=r)return t[v];
  int tm=(tl+tr)/2;
  return max(get(v*2,tl,tm,l,r),get(v*2+1,tm+1,tr,l,r));
}

int main(){
  ios_base::sync_with_stdio(NULL);
  cin.tie(nullptr),cout.tie(nullptr);
  int n,m;
  cin>>n>>m;
  for(int i=1;i<=n;i++){
    cin>>a[i];
  }
  stack<int>st;
  for(int i=n;i>=1;i--){
    while(!st.empty()&&a[st.top()]<a[i]){
      inv[i].pb(st.top());
      st.pop();
    }
    st.push(i);
  }
  for(int i=1;i<=m;i++){
    cin>>q[i].x.x>>q[i].x.y>>q[i].y.x;
    q[i].y.y=i;
  }
  sort(q+1,q+m+1);
  reverse(q+1,q+m+1);
  int l=n;
  for(int i=1;i<=m;i++){
    while(q[i].x.x<=l){
      for(int j=0;j<sz(inv[l]);j++){
        upd(1,1,n,inv[l][j],a[inv[l][j]]+a[l]);
      }
      l--;
    }
    ans[q[i].y.y]=(get(1,1,n,1,q[i].x.y)<=q[i].y.x);
  }
  for(int i=1;i<=m;i++){
    cout<<ans[i]<<nl;
  }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 23800 KB Output is correct
2 Correct 24 ms 23928 KB Output is correct
3 Correct 23 ms 23800 KB Output is correct
4 Correct 23 ms 23800 KB Output is correct
5 Correct 23 ms 23928 KB Output is correct
6 Correct 24 ms 23928 KB Output is correct
7 Correct 24 ms 23928 KB Output is correct
8 Correct 24 ms 23928 KB Output is correct
9 Correct 24 ms 23928 KB Output is correct
10 Correct 24 ms 23928 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 23800 KB Output is correct
2 Correct 24 ms 23928 KB Output is correct
3 Correct 23 ms 23800 KB Output is correct
4 Correct 23 ms 23800 KB Output is correct
5 Correct 23 ms 23928 KB Output is correct
6 Correct 24 ms 23928 KB Output is correct
7 Correct 24 ms 23928 KB Output is correct
8 Correct 24 ms 23928 KB Output is correct
9 Correct 24 ms 23928 KB Output is correct
10 Correct 24 ms 23928 KB Output is correct
11 Correct 35 ms 23928 KB Output is correct
12 Correct 26 ms 24056 KB Output is correct
13 Correct 26 ms 24056 KB Output is correct
14 Correct 28 ms 24184 KB Output is correct
15 Correct 31 ms 24180 KB Output is correct
16 Correct 27 ms 24184 KB Output is correct
17 Correct 26 ms 24056 KB Output is correct
18 Correct 26 ms 24056 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1363 ms 73848 KB Output is correct
2 Correct 1370 ms 106720 KB Output is correct
3 Correct 1378 ms 106668 KB Output is correct
4 Correct 1414 ms 106824 KB Output is correct
5 Correct 1049 ms 86496 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 124 ms 29260 KB Output is correct
2 Correct 122 ms 29020 KB Output is correct
3 Correct 103 ms 26804 KB Output is correct
4 Correct 101 ms 26784 KB Output is correct
5 Correct 101 ms 26872 KB Output is correct
6 Correct 98 ms 27128 KB Output is correct
7 Correct 98 ms 27000 KB Output is correct
8 Correct 101 ms 27772 KB Output is correct
9 Correct 73 ms 26008 KB Output is correct
10 Correct 105 ms 27468 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 23800 KB Output is correct
2 Correct 24 ms 23928 KB Output is correct
3 Correct 23 ms 23800 KB Output is correct
4 Correct 23 ms 23800 KB Output is correct
5 Correct 23 ms 23928 KB Output is correct
6 Correct 24 ms 23928 KB Output is correct
7 Correct 24 ms 23928 KB Output is correct
8 Correct 24 ms 23928 KB Output is correct
9 Correct 24 ms 23928 KB Output is correct
10 Correct 24 ms 23928 KB Output is correct
11 Correct 35 ms 23928 KB Output is correct
12 Correct 26 ms 24056 KB Output is correct
13 Correct 26 ms 24056 KB Output is correct
14 Correct 28 ms 24184 KB Output is correct
15 Correct 31 ms 24180 KB Output is correct
16 Correct 27 ms 24184 KB Output is correct
17 Correct 26 ms 24056 KB Output is correct
18 Correct 26 ms 24056 KB Output is correct
19 Correct 266 ms 34272 KB Output is correct
20 Correct 259 ms 34252 KB Output is correct
21 Correct 272 ms 34296 KB Output is correct
22 Correct 252 ms 34304 KB Output is correct
23 Correct 255 ms 34296 KB Output is correct
24 Correct 205 ms 29816 KB Output is correct
25 Correct 201 ms 29768 KB Output is correct
26 Correct 205 ms 29816 KB Output is correct
27 Correct 206 ms 29892 KB Output is correct
28 Correct 206 ms 29944 KB Output is correct
29 Correct 208 ms 29816 KB Output is correct
30 Correct 214 ms 29744 KB Output is correct
31 Correct 208 ms 29816 KB Output is correct
32 Correct 222 ms 29816 KB Output is correct
33 Correct 213 ms 29816 KB Output is correct
34 Correct 197 ms 29816 KB Output is correct
35 Correct 203 ms 29888 KB Output is correct
36 Correct 211 ms 29884 KB Output is correct
37 Correct 210 ms 29944 KB Output is correct
38 Correct 207 ms 29816 KB Output is correct
39 Correct 205 ms 31352 KB Output is correct
40 Correct 167 ms 29560 KB Output is correct
41 Correct 203 ms 31020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 24 ms 23800 KB Output is correct
2 Correct 24 ms 23928 KB Output is correct
3 Correct 23 ms 23800 KB Output is correct
4 Correct 23 ms 23800 KB Output is correct
5 Correct 23 ms 23928 KB Output is correct
6 Correct 24 ms 23928 KB Output is correct
7 Correct 24 ms 23928 KB Output is correct
8 Correct 24 ms 23928 KB Output is correct
9 Correct 24 ms 23928 KB Output is correct
10 Correct 24 ms 23928 KB Output is correct
11 Correct 35 ms 23928 KB Output is correct
12 Correct 26 ms 24056 KB Output is correct
13 Correct 26 ms 24056 KB Output is correct
14 Correct 28 ms 24184 KB Output is correct
15 Correct 31 ms 24180 KB Output is correct
16 Correct 27 ms 24184 KB Output is correct
17 Correct 26 ms 24056 KB Output is correct
18 Correct 26 ms 24056 KB Output is correct
19 Correct 1363 ms 73848 KB Output is correct
20 Correct 1370 ms 106720 KB Output is correct
21 Correct 1378 ms 106668 KB Output is correct
22 Correct 1414 ms 106824 KB Output is correct
23 Correct 1049 ms 86496 KB Output is correct
24 Correct 124 ms 29260 KB Output is correct
25 Correct 122 ms 29020 KB Output is correct
26 Correct 103 ms 26804 KB Output is correct
27 Correct 101 ms 26784 KB Output is correct
28 Correct 101 ms 26872 KB Output is correct
29 Correct 98 ms 27128 KB Output is correct
30 Correct 98 ms 27000 KB Output is correct
31 Correct 101 ms 27772 KB Output is correct
32 Correct 73 ms 26008 KB Output is correct
33 Correct 105 ms 27468 KB Output is correct
34 Correct 266 ms 34272 KB Output is correct
35 Correct 259 ms 34252 KB Output is correct
36 Correct 272 ms 34296 KB Output is correct
37 Correct 252 ms 34304 KB Output is correct
38 Correct 255 ms 34296 KB Output is correct
39 Correct 205 ms 29816 KB Output is correct
40 Correct 201 ms 29768 KB Output is correct
41 Correct 205 ms 29816 KB Output is correct
42 Correct 206 ms 29892 KB Output is correct
43 Correct 206 ms 29944 KB Output is correct
44 Correct 208 ms 29816 KB Output is correct
45 Correct 214 ms 29744 KB Output is correct
46 Correct 208 ms 29816 KB Output is correct
47 Correct 222 ms 29816 KB Output is correct
48 Correct 213 ms 29816 KB Output is correct
49 Correct 197 ms 29816 KB Output is correct
50 Correct 203 ms 29888 KB Output is correct
51 Correct 211 ms 29884 KB Output is correct
52 Correct 210 ms 29944 KB Output is correct
53 Correct 207 ms 29816 KB Output is correct
54 Correct 205 ms 31352 KB Output is correct
55 Correct 167 ms 29560 KB Output is correct
56 Correct 203 ms 31020 KB Output is correct
57 Correct 1396 ms 107276 KB Output is correct
58 Correct 1396 ms 107256 KB Output is correct
59 Correct 1355 ms 107264 KB Output is correct
60 Correct 1356 ms 107256 KB Output is correct
61 Correct 1350 ms 107392 KB Output is correct
62 Correct 1403 ms 107256 KB Output is correct
63 Correct 1010 ms 85200 KB Output is correct
64 Correct 997 ms 85184 KB Output is correct
65 Correct 1055 ms 86764 KB Output is correct
66 Correct 1111 ms 86836 KB Output is correct
67 Correct 1044 ms 86884 KB Output is correct
68 Correct 1041 ms 86748 KB Output is correct
69 Correct 1056 ms 85804 KB Output is correct
70 Correct 1045 ms 86632 KB Output is correct
71 Correct 1048 ms 85980 KB Output is correct
72 Correct 1053 ms 85860 KB Output is correct
73 Correct 978 ms 83368 KB Output is correct
74 Correct 1010 ms 83564 KB Output is correct
75 Correct 989 ms 79068 KB Output is correct
76 Correct 971 ms 83472 KB Output is correct
77 Correct 991 ms 82420 KB Output is correct
78 Correct 1062 ms 86796 KB Output is correct
79 Correct 788 ms 73264 KB Output is correct
80 Correct 1035 ms 84068 KB Output is correct