Submission #209219

# Submission time Handle Problem Language Result Execution time Memory
209219 2020-03-13T12:39:41 Z AryaKnight Exhibition (JOI19_ho_t2) C++14
100 / 100
422 ms 4568 KB
//#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline") //Optimization flags
//#pragma GCC option("arch=native","tune=native","no-zero-upper") //Enable AVX
//#pragma GCC target("avx2")  //Enable AVX
#include<bits/stdc++.h>
using namespace std;

#define all(a) begin(a),end(a)
#define F first
#define S second
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

#ifdef LOCAL
#include "debug.h"
#else
#define debug(...) 42
#endif

void clr(auto &a,int n){
  a.clear();
  a.resize(n);
}

template <typename A, typename B>
istream& operator>>(istream& input,pair<A,B>& x) {
  input>>x.F>>x.S;
  return input;
}

template <typename A>
istream& operator>>(istream& input,vector<A>& x) {
  for(auto& i:x)
    input>>i;
  return input;
}

template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {
  for(auto& i:x)
    output<<i<<' ';
  return output;
}

template<typename T>
vector<pair<T,int>> getvec(int n){
  vector<pair<T,int>>a(n);
  for(int i=0;i<a.size();i++){
    cin>>a[i].F;
    a[i].S=i;
  }
  return a;
}

const int mod=1e9+7;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int mul(int a,int b){
  return ((a)*1ll*(b))%mod;
}

void add(int &a,int b){
  a+=b;
  if(a>=mod)a-=mod;
}

int sub(int a,int b){
  a-=b;
  if(a<0){
    a+=mod;
  }
  return a;
}

int powz(int a,int b){
  int res=1;
  while(b){
    if(b&1){
      res=mul(res,a);
    }
    b/=2;
    a=mul(a,a);
  }
  return res;
}

const int N=200005;

struct SegTree{
  vector<int>t;
  int _=1e9;
  int merge(int x,int y){
    return min(x,y);
  }
  SegTree(int n){
    t.resize(4*n);
    for(auto &i:t){
      i=_;
    }
  }
  
  int query(int v, int tl, int tr, int l, int r) {
    if (l > r) 
      return _;
    if (l == tl && r == tr) {
      return t[v];
    }
    int tm = (tl + tr) / 2;
    return merge(query(v*2, tl, tm, l, min(r, tm))
		 ,query(v*2+1, tm+1, tr, max(l, tm+1), r));
  }
  
  void update(int v, int tl, int tr, int pos, int new_val) {
    if (tl == tr) {
      t[v] = new_val;
    } else {
      int tm = (tl + tr) / 2;
      if (pos <= tm)
	update(v*2, tl, tm, pos, new_val);
      else
	update(v*2+1, tm+1, tr, pos, new_val);
      t[v] = merge(t[v*2],t[v*2+1]);
    }
  }
}; 

void solve(){
  int n,m;
  cin>>n>>m;
  vector<pair<int,int>>a(n);
  for(auto &i:a){
    cin>>i.S>>i.F;
  }
  sort(all(a));
  vi c(m);
  cin>>c;
  sort(all(c));
  vector<int>compress;
  for(auto &i:a){
    compress.pb(i.S);
  }
  for(auto &i:c){
    compress.pb(i);
  }
  sort(all(compress));
  compress.resize(unique(all(compress))-compress.begin());
  for(auto &i:a){
    i.S=lower_bound(all(compress),i.S)-compress.begin();
  }
  for(auto &i:c){
    i=lower_bound(all(compress),i)-compress.begin();
  }
  vector<int>prf;
  int mn=1e9;
  vector<int>nw(n);
  for(int i=0;i<n;i++){
    mn=min(mn,a[i].S);
    nw[i]=mn;
  }
  int lst=n-1;
  int ans=0;
  SegTree st(n);
  for(int i=0;i<n;i++){
    st.update(1,0,n-1,i,a[i].S);
  }
  for(int i=m-1;i>=0;i--){
    int l=0,r=lst,an=0;
    if(st.query(1,0,n-1,0,lst)>c[i]){
      cout<<ans;
      return;
    }
    while(l<=r){
      int mid=(l+r)/2;
      if(st.query(1,0,n-1,mid,lst)<=c[i]){
	l=mid+1;
	an=max(an,mid);
      }
      else{
	r=mid-1;
      }
    }
    ans++;
    lst=an-1;
    if(lst<0){
      cout<<ans;
      return;
    }
  }
  cout<<ans;
}

signed main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int tc=1;
  //cin>>tc;
  for(int _=0;_<tc;_++){
    // cout<<"Case #"<<_+1<<": ";
    solve();
    if(_!=tc-1){
      cout<<'\n';
    }
  }
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 380 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 380 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 380 KB Output is correct
13 Correct 5 ms 380 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 380 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 380 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 380 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 380 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 380 KB Output is correct
13 Correct 5 ms 380 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 380 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 380 KB Output is correct
20 Correct 7 ms 376 KB Output is correct
21 Correct 7 ms 376 KB Output is correct
22 Correct 6 ms 376 KB Output is correct
23 Correct 6 ms 376 KB Output is correct
24 Correct 7 ms 376 KB Output is correct
25 Correct 7 ms 376 KB Output is correct
26 Correct 7 ms 376 KB Output is correct
27 Correct 6 ms 376 KB Output is correct
28 Correct 5 ms 376 KB Output is correct
29 Correct 7 ms 376 KB Output is correct
30 Correct 7 ms 376 KB Output is correct
31 Correct 7 ms 376 KB Output is correct
32 Correct 8 ms 376 KB Output is correct
33 Correct 5 ms 376 KB Output is correct
34 Correct 6 ms 452 KB Output is correct
35 Correct 5 ms 376 KB Output is correct
36 Correct 7 ms 376 KB Output is correct
37 Correct 7 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 380 KB Output is correct
7 Correct 5 ms 376 KB Output is correct
8 Correct 5 ms 376 KB Output is correct
9 Correct 5 ms 376 KB Output is correct
10 Correct 5 ms 380 KB Output is correct
11 Correct 5 ms 376 KB Output is correct
12 Correct 5 ms 380 KB Output is correct
13 Correct 5 ms 380 KB Output is correct
14 Correct 5 ms 376 KB Output is correct
15 Correct 5 ms 380 KB Output is correct
16 Correct 5 ms 376 KB Output is correct
17 Correct 5 ms 376 KB Output is correct
18 Correct 5 ms 376 KB Output is correct
19 Correct 5 ms 380 KB Output is correct
20 Correct 7 ms 376 KB Output is correct
21 Correct 7 ms 376 KB Output is correct
22 Correct 6 ms 376 KB Output is correct
23 Correct 6 ms 376 KB Output is correct
24 Correct 7 ms 376 KB Output is correct
25 Correct 7 ms 376 KB Output is correct
26 Correct 7 ms 376 KB Output is correct
27 Correct 6 ms 376 KB Output is correct
28 Correct 5 ms 376 KB Output is correct
29 Correct 7 ms 376 KB Output is correct
30 Correct 7 ms 376 KB Output is correct
31 Correct 7 ms 376 KB Output is correct
32 Correct 8 ms 376 KB Output is correct
33 Correct 5 ms 376 KB Output is correct
34 Correct 6 ms 452 KB Output is correct
35 Correct 5 ms 376 KB Output is correct
36 Correct 7 ms 376 KB Output is correct
37 Correct 7 ms 376 KB Output is correct
38 Correct 418 ms 4460 KB Output is correct
39 Correct 402 ms 4456 KB Output is correct
40 Correct 398 ms 4392 KB Output is correct
41 Correct 404 ms 4484 KB Output is correct
42 Correct 87 ms 4464 KB Output is correct
43 Correct 109 ms 4388 KB Output is correct
44 Correct 269 ms 4336 KB Output is correct
45 Correct 422 ms 4336 KB Output is correct
46 Correct 408 ms 4336 KB Output is correct
47 Correct 319 ms 4208 KB Output is correct
48 Correct 314 ms 4228 KB Output is correct
49 Correct 298 ms 3540 KB Output is correct
50 Correct 279 ms 3544 KB Output is correct
51 Correct 107 ms 4332 KB Output is correct
52 Correct 104 ms 4384 KB Output is correct
53 Correct 131 ms 4416 KB Output is correct
54 Correct 377 ms 4392 KB Output is correct
55 Correct 413 ms 4500 KB Output is correct
56 Correct 82 ms 3804 KB Output is correct
57 Correct 35 ms 1528 KB Output is correct
58 Correct 62 ms 3700 KB Output is correct
59 Correct 87 ms 3956 KB Output is correct
60 Correct 44 ms 1528 KB Output is correct
61 Correct 145 ms 2292 KB Output is correct
62 Correct 308 ms 4336 KB Output is correct
63 Correct 310 ms 4456 KB Output is correct
64 Correct 319 ms 4504 KB Output is correct
65 Correct 308 ms 4336 KB Output is correct
66 Correct 325 ms 4460 KB Output is correct
67 Correct 316 ms 4568 KB Output is correct
68 Correct 310 ms 4464 KB Output is correct
69 Correct 301 ms 4440 KB Output is correct
70 Correct 301 ms 4340 KB Output is correct
71 Correct 296 ms 4464 KB Output is correct
72 Correct 290 ms 4336 KB Output is correct
73 Correct 309 ms 4440 KB Output is correct