Submission #168296

# Submission time Handle Problem Language Result Execution time Memory
168296 2019-12-12T10:39:29 Z Nordway Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
64 / 100
3000 ms 101100 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(){
  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;
  }
}
# Verdict Execution time Memory Grader output
1 Correct 22 ms 23932 KB Output is correct
2 Correct 23 ms 23800 KB Output is correct
3 Correct 23 ms 23928 KB Output is correct
4 Correct 22 ms 23804 KB Output is correct
5 Correct 23 ms 23800 KB Output is correct
6 Correct 24 ms 23800 KB Output is correct
7 Correct 24 ms 23928 KB Output is correct
8 Correct 23 ms 23800 KB Output is correct
9 Correct 23 ms 23888 KB Output is correct
10 Correct 23 ms 23928 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 23932 KB Output is correct
2 Correct 23 ms 23800 KB Output is correct
3 Correct 23 ms 23928 KB Output is correct
4 Correct 22 ms 23804 KB Output is correct
5 Correct 23 ms 23800 KB Output is correct
6 Correct 24 ms 23800 KB Output is correct
7 Correct 24 ms 23928 KB Output is correct
8 Correct 23 ms 23800 KB Output is correct
9 Correct 23 ms 23888 KB Output is correct
10 Correct 23 ms 23928 KB Output is correct
11 Correct 30 ms 24184 KB Output is correct
12 Correct 33 ms 24184 KB Output is correct
13 Correct 34 ms 24296 KB Output is correct
14 Correct 42 ms 24184 KB Output is correct
15 Correct 42 ms 24312 KB Output is correct
16 Correct 34 ms 24184 KB Output is correct
17 Correct 38 ms 24056 KB Output is correct
18 Correct 37 ms 24056 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3035 ms 101100 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 261 ms 31040 KB Output is correct
2 Correct 259 ms 31020 KB Output is correct
3 Correct 238 ms 28792 KB Output is correct
4 Correct 239 ms 28792 KB Output is correct
5 Correct 242 ms 28764 KB Output is correct
6 Correct 232 ms 28792 KB Output is correct
7 Correct 229 ms 28796 KB Output is correct
8 Correct 223 ms 29404 KB Output is correct
9 Correct 170 ms 27384 KB Output is correct
10 Correct 223 ms 29144 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 23932 KB Output is correct
2 Correct 23 ms 23800 KB Output is correct
3 Correct 23 ms 23928 KB Output is correct
4 Correct 22 ms 23804 KB Output is correct
5 Correct 23 ms 23800 KB Output is correct
6 Correct 24 ms 23800 KB Output is correct
7 Correct 24 ms 23928 KB Output is correct
8 Correct 23 ms 23800 KB Output is correct
9 Correct 23 ms 23888 KB Output is correct
10 Correct 23 ms 23928 KB Output is correct
11 Correct 30 ms 24184 KB Output is correct
12 Correct 33 ms 24184 KB Output is correct
13 Correct 34 ms 24296 KB Output is correct
14 Correct 42 ms 24184 KB Output is correct
15 Correct 42 ms 24312 KB Output is correct
16 Correct 34 ms 24184 KB Output is correct
17 Correct 38 ms 24056 KB Output is correct
18 Correct 37 ms 24056 KB Output is correct
19 Correct 676 ms 40792 KB Output is correct
20 Correct 667 ms 40952 KB Output is correct
21 Correct 658 ms 40696 KB Output is correct
22 Correct 655 ms 40796 KB Output is correct
23 Correct 659 ms 40700 KB Output is correct
24 Correct 615 ms 36304 KB Output is correct
25 Correct 601 ms 36216 KB Output is correct
26 Correct 616 ms 36368 KB Output is correct
27 Correct 617 ms 36336 KB Output is correct
28 Correct 616 ms 36284 KB Output is correct
29 Correct 618 ms 36320 KB Output is correct
30 Correct 618 ms 36428 KB Output is correct
31 Correct 627 ms 36488 KB Output is correct
32 Correct 659 ms 36472 KB Output is correct
33 Correct 619 ms 36384 KB Output is correct
34 Correct 593 ms 36236 KB Output is correct
35 Correct 595 ms 36088 KB Output is correct
36 Correct 584 ms 35984 KB Output is correct
37 Correct 584 ms 35844 KB Output is correct
38 Correct 593 ms 36088 KB Output is correct
39 Correct 540 ms 36452 KB Output is correct
40 Correct 487 ms 33928 KB Output is correct
41 Correct 521 ms 35676 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 22 ms 23932 KB Output is correct
2 Correct 23 ms 23800 KB Output is correct
3 Correct 23 ms 23928 KB Output is correct
4 Correct 22 ms 23804 KB Output is correct
5 Correct 23 ms 23800 KB Output is correct
6 Correct 24 ms 23800 KB Output is correct
7 Correct 24 ms 23928 KB Output is correct
8 Correct 23 ms 23800 KB Output is correct
9 Correct 23 ms 23888 KB Output is correct
10 Correct 23 ms 23928 KB Output is correct
11 Correct 30 ms 24184 KB Output is correct
12 Correct 33 ms 24184 KB Output is correct
13 Correct 34 ms 24296 KB Output is correct
14 Correct 42 ms 24184 KB Output is correct
15 Correct 42 ms 24312 KB Output is correct
16 Correct 34 ms 24184 KB Output is correct
17 Correct 38 ms 24056 KB Output is correct
18 Correct 37 ms 24056 KB Output is correct
19 Execution timed out 3035 ms 101100 KB Time limit exceeded
20 Halted 0 ms 0 KB -