/* 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 |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6500 KB |
Output is correct |
3 |
Correct |
1 ms |
6644 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6612 KB |
Output is correct |
6 |
Correct |
2 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6644 KB |
Output is correct |
9 |
Correct |
2 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6488 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 |
6492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6500 KB |
Output is correct |
3 |
Correct |
1 ms |
6644 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6612 KB |
Output is correct |
6 |
Correct |
2 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6644 KB |
Output is correct |
9 |
Correct |
2 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6488 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 |
6492 KB |
Output is correct |
20 |
Correct |
2 ms |
6492 KB |
Output is correct |
21 |
Correct |
2 ms |
6640 KB |
Output is correct |
22 |
Correct |
2 ms |
6492 KB |
Output is correct |
23 |
Correct |
1 ms |
6492 KB |
Output is correct |
24 |
Correct |
2 ms |
6492 KB |
Output is correct |
25 |
Correct |
2 ms |
6492 KB |
Output is correct |
26 |
Correct |
1 ms |
6492 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 |
2 ms |
6500 KB |
Output is correct |
32 |
Correct |
2 ms |
6492 KB |
Output is correct |
33 |
Correct |
1 ms |
6492 KB |
Output is correct |
34 |
Correct |
2 ms |
6488 KB |
Output is correct |
35 |
Correct |
1 ms |
6492 KB |
Output is correct |
36 |
Correct |
1 ms |
6492 KB |
Output is correct |
37 |
Correct |
1 ms |
6492 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
6488 KB |
Output is correct |
2 |
Correct |
1 ms |
6500 KB |
Output is correct |
3 |
Correct |
1 ms |
6644 KB |
Output is correct |
4 |
Correct |
1 ms |
6492 KB |
Output is correct |
5 |
Correct |
1 ms |
6612 KB |
Output is correct |
6 |
Correct |
2 ms |
6492 KB |
Output is correct |
7 |
Correct |
1 ms |
6492 KB |
Output is correct |
8 |
Correct |
1 ms |
6644 KB |
Output is correct |
9 |
Correct |
2 ms |
6492 KB |
Output is correct |
10 |
Correct |
1 ms |
6488 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 |
6492 KB |
Output is correct |
20 |
Correct |
2 ms |
6492 KB |
Output is correct |
21 |
Correct |
2 ms |
6640 KB |
Output is correct |
22 |
Correct |
2 ms |
6492 KB |
Output is correct |
23 |
Correct |
1 ms |
6492 KB |
Output is correct |
24 |
Correct |
2 ms |
6492 KB |
Output is correct |
25 |
Correct |
2 ms |
6492 KB |
Output is correct |
26 |
Correct |
1 ms |
6492 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 |
2 ms |
6500 KB |
Output is correct |
32 |
Correct |
2 ms |
6492 KB |
Output is correct |
33 |
Correct |
1 ms |
6492 KB |
Output is correct |
34 |
Correct |
2 ms |
6488 KB |
Output is correct |
35 |
Correct |
1 ms |
6492 KB |
Output is correct |
36 |
Correct |
1 ms |
6492 KB |
Output is correct |
37 |
Correct |
1 ms |
6492 KB |
Output is correct |
38 |
Correct |
77 ms |
19028 KB |
Output is correct |
39 |
Correct |
79 ms |
19076 KB |
Output is correct |
40 |
Correct |
80 ms |
18880 KB |
Output is correct |
41 |
Correct |
92 ms |
19072 KB |
Output is correct |
42 |
Correct |
47 ms |
19088 KB |
Output is correct |
43 |
Correct |
48 ms |
19028 KB |
Output is correct |
44 |
Correct |
71 ms |
19028 KB |
Output is correct |
45 |
Correct |
82 ms |
19024 KB |
Output is correct |
46 |
Correct |
70 ms |
19028 KB |
Output is correct |
47 |
Correct |
76 ms |
16840 KB |
Output is correct |
48 |
Correct |
80 ms |
16976 KB |
Output is correct |
49 |
Correct |
62 ms |
14928 KB |
Output is correct |
50 |
Correct |
56 ms |
14932 KB |
Output is correct |
51 |
Correct |
48 ms |
19024 KB |
Output is correct |
52 |
Correct |
47 ms |
19028 KB |
Output is correct |
53 |
Correct |
53 ms |
19028 KB |
Output is correct |
54 |
Correct |
62 ms |
19080 KB |
Output is correct |
55 |
Correct |
76 ms |
19076 KB |
Output is correct |
56 |
Correct |
33 ms |
12888 KB |
Output is correct |
57 |
Correct |
15 ms |
12636 KB |
Output is correct |
58 |
Correct |
42 ms |
12676 KB |
Output is correct |
59 |
Correct |
48 ms |
12892 KB |
Output is correct |
60 |
Correct |
15 ms |
12636 KB |
Output is correct |
61 |
Correct |
39 ms |
14972 KB |
Output is correct |
62 |
Correct |
80 ms |
18888 KB |
Output is correct |
63 |
Correct |
82 ms |
19024 KB |
Output is correct |
64 |
Correct |
81 ms |
19024 KB |
Output is correct |
65 |
Correct |
83 ms |
19084 KB |
Output is correct |
66 |
Correct |
82 ms |
19084 KB |
Output is correct |
67 |
Correct |
83 ms |
19076 KB |
Output is correct |
68 |
Correct |
81 ms |
19028 KB |
Output is correct |
69 |
Correct |
84 ms |
18888 KB |
Output is correct |
70 |
Correct |
82 ms |
19084 KB |
Output is correct |
71 |
Correct |
89 ms |
19080 KB |
Output is correct |
72 |
Correct |
77 ms |
19024 KB |
Output is correct |
73 |
Correct |
70 ms |
19064 KB |
Output is correct |