답안 #883204

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
883204 2023-12-04T19:00:27 Z mychecksedad Exhibition (JOI19_ho_t2) C++17
100 / 100
94 ms 22188 KB
/* Author : Mychecksdead  */
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD (1000000000+7)
#define MOD1 (998244353)
#define pb push_back
#define all(x) x.begin(), x.end()
#define en cout << '\n'
const int N = 1e6+100, M = 1e5+10, K = 52, MX = 30;


int n;
pair<int, int> T[N];
ll S[N];
array<ll, 2> a[N];
array<ll, 3> b[N];
void build(int x){
  for(int i = 0; i <= 4*x; ++i) T[i] = {x+1, 0};
}
pair<int, int> mx(pair<int, int> x, pair<int, int> y){
  swap(x.first, x.second);
  swap(y.first, y.second);
  if(max(x, y) == x) return {x.second, x.first};
  return {y.second, y.first};
}
pair<int, int> get(int l, int r, int ql, int qr, int k){
  if(ql > r || l > qr) return {0, 0};
  if(ql <= l && r <= qr) return T[k];
  int m = l+r>>1;
  return mx(get(l, m, ql, qr, k<<1), get(m+1, r, ql, qr, k<<1|1));
}
void update(int l, int r, int p, int k, pair<int, int> val){
  if(l == r){
    T[k] = mx(val, T[k]);
    return;
  }
  int m = l+r>>1;
  if(p <= m) update(l, m ,p, k<<1, val);
  else update(m+1, r, p, k<<1|1, val);
  T[k] = mx(T[k<<1], T[k<<1|1]);
}

int m;
void solve(){
  cin >> n >> m;
  for(int i = 1; i <= n; ++i) cin >> a[i][1] >> a[i][0];
  for(int i = 1; i <= n; ++i) b[i][0] = a[i][1], b[i][1] = a[i][0], b[i][2] = i;
  for(int i = 1; i <= m; ++i) cin >> S[i];
  sort(S+1, S+1+m);
  sort(a+1, a+1+n);
  sort(b+1, b+1+n);
  vector<int> val;
  // for(int i = 1; i <= n; ++i) val.pb(a[i][1]);
  // sort(all(val));
  // for(int i = 1; i <= n; ++i) a[b[i][2]][1] = i;
  build(m);

  for(int i = n; i >= 1; --i){
    // cout << a[i][0] << ' ' << a[i][1] << '\n';
    int pos = lower_bound(S+1, S+1+m, a[i][1]) - S;
    if(pos>m) continue;
    pair<int, int> dp = get(1, m, pos, m, 1);
    // cout << pos << ' ' << dp.first << ' ' << dp.second << '\n';
    if(dp.first >= pos + 1){
      // cout << "uwu" << '\n';
      update(1, m, dp.first - 1, 1, {dp.first - 1, dp.second + 1});
    }
  }
  int ans = T[1].second;
  cout << ans; 
}


int main(){
  cin.tie(0); ios::sync_with_stdio(0);
  int tt = 1, aa;
  // freopen("in.txt", "r", stdin);
  // freopen("out.txt", "w", stdout);
  while(tt--){
    solve();
    en;
  }
  cerr<<"time taken : "<<(float)clock()/CLOCKS_PER_SEC<<" seconds\n";
  return 0;
} 

Compilation message

joi2019_ho_t2.cpp: In function 'std::pair<int, int> get(int, int, int, int, int)':
joi2019_ho_t2.cpp:30:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   30 |   int m = l+r>>1;
      |           ~^~
joi2019_ho_t2.cpp: In function 'void update(int, int, int, int, std::pair<int, int>)':
joi2019_ho_t2.cpp:38:12: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   38 |   int m = l+r>>1;
      |           ~^~
joi2019_ho_t2.cpp: In function 'int main()':
joi2019_ho_t2.cpp:77:15: warning: unused variable 'aa' [-Wunused-variable]
   77 |   int tt = 1, aa;
      |               ^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6616 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6488 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6488 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6616 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6488 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6488 KB Output is correct
20 Correct 2 ms 6492 KB Output is correct
21 Correct 2 ms 6648 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 2 ms 6672 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 2 ms 6616 KB Output is correct
27 Correct 1 ms 6492 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
29 Correct 1 ms 6492 KB Output is correct
30 Correct 2 ms 6492 KB Output is correct
31 Correct 1 ms 6492 KB Output is correct
32 Correct 1 ms 6492 KB Output is correct
33 Correct 1 ms 6492 KB Output is correct
34 Correct 1 ms 6492 KB Output is correct
35 Correct 1 ms 6488 KB Output is correct
36 Correct 2 ms 6492 KB Output is correct
37 Correct 2 ms 6492 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 6492 KB Output is correct
2 Correct 1 ms 6616 KB Output is correct
3 Correct 1 ms 6492 KB Output is correct
4 Correct 1 ms 6492 KB Output is correct
5 Correct 1 ms 6492 KB Output is correct
6 Correct 1 ms 6492 KB Output is correct
7 Correct 1 ms 6492 KB Output is correct
8 Correct 1 ms 6488 KB Output is correct
9 Correct 1 ms 6492 KB Output is correct
10 Correct 1 ms 6492 KB Output is correct
11 Correct 1 ms 6492 KB Output is correct
12 Correct 1 ms 6492 KB Output is correct
13 Correct 1 ms 6492 KB Output is correct
14 Correct 1 ms 6492 KB Output is correct
15 Correct 1 ms 6492 KB Output is correct
16 Correct 1 ms 6492 KB Output is correct
17 Correct 1 ms 6492 KB Output is correct
18 Correct 1 ms 6492 KB Output is correct
19 Correct 1 ms 6488 KB Output is correct
20 Correct 2 ms 6492 KB Output is correct
21 Correct 2 ms 6648 KB Output is correct
22 Correct 1 ms 6492 KB Output is correct
23 Correct 1 ms 6492 KB Output is correct
24 Correct 2 ms 6672 KB Output is correct
25 Correct 1 ms 6492 KB Output is correct
26 Correct 2 ms 6616 KB Output is correct
27 Correct 1 ms 6492 KB Output is correct
28 Correct 1 ms 6492 KB Output is correct
29 Correct 1 ms 6492 KB Output is correct
30 Correct 2 ms 6492 KB Output is correct
31 Correct 1 ms 6492 KB Output is correct
32 Correct 1 ms 6492 KB Output is correct
33 Correct 1 ms 6492 KB Output is correct
34 Correct 1 ms 6492 KB Output is correct
35 Correct 1 ms 6488 KB Output is correct
36 Correct 2 ms 6492 KB Output is correct
37 Correct 2 ms 6492 KB Output is correct
38 Correct 92 ms 21844 KB Output is correct
39 Correct 74 ms 21840 KB Output is correct
40 Correct 71 ms 21948 KB Output is correct
41 Correct 77 ms 21980 KB Output is correct
42 Correct 49 ms 21948 KB Output is correct
43 Correct 48 ms 21844 KB Output is correct
44 Correct 71 ms 21964 KB Output is correct
45 Correct 82 ms 21936 KB Output is correct
46 Correct 71 ms 21760 KB Output is correct
47 Correct 77 ms 19612 KB Output is correct
48 Correct 66 ms 19540 KB Output is correct
49 Correct 61 ms 17232 KB Output is correct
50 Correct 57 ms 17268 KB Output is correct
51 Correct 48 ms 21936 KB Output is correct
52 Correct 57 ms 21840 KB Output is correct
53 Correct 49 ms 21684 KB Output is correct
54 Correct 60 ms 21996 KB Output is correct
55 Correct 94 ms 21996 KB Output is correct
56 Correct 33 ms 14892 KB Output is correct
57 Correct 15 ms 13728 KB Output is correct
58 Correct 42 ms 14600 KB Output is correct
59 Correct 49 ms 14672 KB Output is correct
60 Correct 16 ms 13728 KB Output is correct
61 Correct 40 ms 16624 KB Output is correct
62 Correct 81 ms 21844 KB Output is correct
63 Correct 87 ms 22188 KB Output is correct
64 Correct 81 ms 21964 KB Output is correct
65 Correct 81 ms 21968 KB Output is correct
66 Correct 81 ms 21948 KB Output is correct
67 Correct 83 ms 21976 KB Output is correct
68 Correct 80 ms 21840 KB Output is correct
69 Correct 83 ms 21928 KB Output is correct
70 Correct 83 ms 21976 KB Output is correct
71 Correct 81 ms 21844 KB Output is correct
72 Correct 79 ms 21840 KB Output is correct
73 Correct 81 ms 21804 KB Output is correct