#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int maxn = 1e5+5;
int N, M;
int frames[maxn];
int dp[maxn];
struct SegDyn
{
int s, e, m; //represents range [s,e]
SegDyn *l, *r;
int sum; //sum for this interval
SegDyn(int _s, int _e) {
s = _s;
e = _e;
m = (s+e)/2;
l = NULL;
r = NULL;
sum = 0;
}
void prepareL() { if (l == NULL) l = new SegDyn(s,m); }
void prepareR() { if (r == NULL) r = new SegDyn(m+1,e); }
void pull() {
sum = 0;
if (l) sum = max(sum,l->sum);
if (r) sum = max(sum,r->sum);
}
void add(int idx, int x) { //a[idx] = max(a[idx],x)
//cout << s << ' ' << e << '\n';
if (s == e && s == idx) {
//at the node, stop
sum = max(sum,x);
return;
}
if (idx <= m) {
prepareL();
assert(l);
l->add(idx,x);
}
else {
prepareR();
r->add(idx,x);
}
pull(); //updates current node based on the children
}
int getmax(int se, int en) {
if (se <= s && e <= en) return sum;
int res = 0;
if (l && se <= m) res = max(res,l->getmax(se,en));
if (r && en > m) res = max(res,r->getmax(se,en));
return res;
}
};
int main()
{
cin >> N >> M;
vector<pair<int,int>> pictures;
for (int i = 0; i < N; i++) {
int a, b; cin >> a >> b;
pictures.push_back({a,b});
}
//coordinate compress values
/*
sort(pictures.begin(),pictures.end(),[](auto a, auto b) {
return a.second < b.second;
});
map<int,int> comp;
int c = 1;
for (auto& p: pictures) {
if (comp.count(p.second)) p.second = comp[p.second];
else p.second = comp[p.second] = c++;
}
*/
sort(pictures.begin(),pictures.end(),[](auto a, auto b) {
if (a.second != b.second) return a.second < b.second;
return a.first < b.first;
});
for (int i = 1; i <= M; i++) cin >> frames[i];
sort(frames+1,frames+M+1);
SegDyn *root = new SegDyn(0,1000000007);
int ans = 0;
for (int i = N - 1; i >= 0; i--) {
int sz = pictures[i].first;
int val = pictures[i].second;
/*
for (int j = i + 1; j < N; j++) {
if (dp[j] < M && frames[M-dp[j]] >= sz) {
dp[i] = max(dp[i],dp[j]+1);
}
}
*/
if (frames[M] >= sz) {
dp[i] = root->getmax(sz,1000000007) + 1;
}
//cout << i << ": " << dp[i] << '\n';
if (dp[i] < M) root->add(frames[M-dp[i]],dp[i]);
ans = max(ans,dp[i]);
}
cout << ans << '\n';
}
Compilation message
joi2019_ho_t3.cpp: In function 'int main()':
joi2019_ho_t3.cpp:92:13: warning: unused variable 'val' [-Wunused-variable]
int val = pictures[i].second;
^~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
256 KB |
Output is correct |
10 |
Correct |
2 ms |
256 KB |
Output is correct |
11 |
Correct |
3 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
256 KB |
Output is correct |
18 |
Correct |
3 ms |
384 KB |
Output is correct |
19 |
Correct |
3 ms |
256 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
256 KB |
Output is correct |
10 |
Correct |
2 ms |
256 KB |
Output is correct |
11 |
Correct |
3 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
256 KB |
Output is correct |
18 |
Correct |
3 ms |
384 KB |
Output is correct |
19 |
Correct |
3 ms |
256 KB |
Output is correct |
20 |
Correct |
7 ms |
1280 KB |
Output is correct |
21 |
Correct |
4 ms |
384 KB |
Output is correct |
22 |
Correct |
3 ms |
384 KB |
Output is correct |
23 |
Correct |
4 ms |
384 KB |
Output is correct |
24 |
Correct |
4 ms |
512 KB |
Output is correct |
25 |
Correct |
4 ms |
384 KB |
Output is correct |
26 |
Correct |
7 ms |
1408 KB |
Output is correct |
27 |
Correct |
4 ms |
384 KB |
Output is correct |
28 |
Correct |
4 ms |
384 KB |
Output is correct |
29 |
Correct |
6 ms |
384 KB |
Output is correct |
30 |
Correct |
5 ms |
1280 KB |
Output is correct |
31 |
Correct |
5 ms |
384 KB |
Output is correct |
32 |
Correct |
4 ms |
384 KB |
Output is correct |
33 |
Correct |
3 ms |
384 KB |
Output is correct |
34 |
Correct |
4 ms |
640 KB |
Output is correct |
35 |
Correct |
3 ms |
384 KB |
Output is correct |
36 |
Correct |
6 ms |
1024 KB |
Output is correct |
37 |
Correct |
6 ms |
896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
384 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
2 ms |
256 KB |
Output is correct |
4 |
Correct |
2 ms |
256 KB |
Output is correct |
5 |
Correct |
2 ms |
256 KB |
Output is correct |
6 |
Correct |
2 ms |
256 KB |
Output is correct |
7 |
Correct |
2 ms |
256 KB |
Output is correct |
8 |
Correct |
2 ms |
384 KB |
Output is correct |
9 |
Correct |
2 ms |
256 KB |
Output is correct |
10 |
Correct |
2 ms |
256 KB |
Output is correct |
11 |
Correct |
3 ms |
256 KB |
Output is correct |
12 |
Correct |
2 ms |
384 KB |
Output is correct |
13 |
Correct |
3 ms |
384 KB |
Output is correct |
14 |
Correct |
2 ms |
384 KB |
Output is correct |
15 |
Correct |
2 ms |
384 KB |
Output is correct |
16 |
Correct |
2 ms |
384 KB |
Output is correct |
17 |
Correct |
2 ms |
256 KB |
Output is correct |
18 |
Correct |
3 ms |
384 KB |
Output is correct |
19 |
Correct |
3 ms |
256 KB |
Output is correct |
20 |
Correct |
7 ms |
1280 KB |
Output is correct |
21 |
Correct |
4 ms |
384 KB |
Output is correct |
22 |
Correct |
3 ms |
384 KB |
Output is correct |
23 |
Correct |
4 ms |
384 KB |
Output is correct |
24 |
Correct |
4 ms |
512 KB |
Output is correct |
25 |
Correct |
4 ms |
384 KB |
Output is correct |
26 |
Correct |
7 ms |
1408 KB |
Output is correct |
27 |
Correct |
4 ms |
384 KB |
Output is correct |
28 |
Correct |
4 ms |
384 KB |
Output is correct |
29 |
Correct |
6 ms |
384 KB |
Output is correct |
30 |
Correct |
5 ms |
1280 KB |
Output is correct |
31 |
Correct |
5 ms |
384 KB |
Output is correct |
32 |
Correct |
4 ms |
384 KB |
Output is correct |
33 |
Correct |
3 ms |
384 KB |
Output is correct |
34 |
Correct |
4 ms |
640 KB |
Output is correct |
35 |
Correct |
3 ms |
384 KB |
Output is correct |
36 |
Correct |
6 ms |
1024 KB |
Output is correct |
37 |
Correct |
6 ms |
896 KB |
Output is correct |
38 |
Correct |
320 ms |
69792 KB |
Output is correct |
39 |
Correct |
194 ms |
2856 KB |
Output is correct |
40 |
Correct |
176 ms |
2036 KB |
Output is correct |
41 |
Correct |
256 ms |
37232 KB |
Output is correct |
42 |
Correct |
181 ms |
1780 KB |
Output is correct |
43 |
Correct |
178 ms |
1768 KB |
Output is correct |
44 |
Correct |
272 ms |
35724 KB |
Output is correct |
45 |
Correct |
309 ms |
69696 KB |
Output is correct |
46 |
Correct |
170 ms |
2152 KB |
Output is correct |
47 |
Correct |
260 ms |
50948 KB |
Output is correct |
48 |
Correct |
169 ms |
1984 KB |
Output is correct |
49 |
Correct |
261 ms |
49012 KB |
Output is correct |
50 |
Correct |
130 ms |
2284 KB |
Output is correct |
51 |
Correct |
249 ms |
1804 KB |
Output is correct |
52 |
Correct |
171 ms |
1772 KB |
Output is correct |
53 |
Correct |
163 ms |
1804 KB |
Output is correct |
54 |
Correct |
194 ms |
2072 KB |
Output is correct |
55 |
Correct |
296 ms |
69480 KB |
Output is correct |
56 |
Correct |
111 ms |
1640 KB |
Output is correct |
57 |
Correct |
65 ms |
760 KB |
Output is correct |
58 |
Correct |
174 ms |
1612 KB |
Output is correct |
59 |
Correct |
179 ms |
2664 KB |
Output is correct |
60 |
Correct |
52 ms |
876 KB |
Output is correct |
61 |
Correct |
136 ms |
20976 KB |
Output is correct |
62 |
Correct |
313 ms |
44652 KB |
Output is correct |
63 |
Correct |
309 ms |
44776 KB |
Output is correct |
64 |
Correct |
342 ms |
44724 KB |
Output is correct |
65 |
Correct |
311 ms |
44652 KB |
Output is correct |
66 |
Correct |
320 ms |
44968 KB |
Output is correct |
67 |
Correct |
345 ms |
44872 KB |
Output is correct |
68 |
Correct |
342 ms |
44856 KB |
Output is correct |
69 |
Correct |
282 ms |
24232 KB |
Output is correct |
70 |
Correct |
314 ms |
44904 KB |
Output is correct |
71 |
Correct |
244 ms |
4432 KB |
Output is correct |
72 |
Correct |
293 ms |
14076 KB |
Output is correct |
73 |
Correct |
170 ms |
2028 KB |
Output is correct |