#include <bits/stdc++.h>
#define sz(x) ((int)x.size())
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
const int INF = 1e9 + 10;
int m, n, a[3][200010];
set<pair<int,int> > st[200010];
pair<int,int> p[200010];
bool Check(int k, pair<int,int>& v) {
auto it = st[k].lower_bound({v.first, -INF});
if(it == st[k].begin()) return 0;
--it;
return it->second < v.second;
}
void Push(int k, pair<int,int>& v) {
auto it = st[k].lower_bound({v.first, INF});
if(it != st[k].begin()) {
--it;
if(it->second <= v.second) return;
if(it->first < v.first) ++it;
}
while(it != st[k].end() && it->second >= v.second)
it = st[k].erase(it);
st[k].insert(v);
}
int main() {
scanf("%d%d", &m, &n);
for(int i=0; i<m; i++) for(int j=1; j<=n; j++)
scanf("%d", &a[i][j]);
vector<pair<int,pair<int,int> > > Vq;
for(int i=1; i<=n; i++)
Vq.push_back({a[0][i], {a[1][i], a[m == 3 ? 2 : 0][i]}});
sort(all(Vq));
int res = 0;
for(int i=0; i<sz(Vq); i++) {
int lo = 0, hi = i;
while(lo < hi) {
int mid = (lo + hi + 1) / 2;
if(Check(mid, Vq[i].second)) lo = mid;
else hi = mid - 1;
}
Push(lo+1, Vq[i].second);
res = max(res, lo+1);
}
printf("%d", res);
return 0;
}
Compilation message
matrix.cpp: In function 'int main()':
matrix.cpp:29:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d", &m, &n);
~~~~~^~~~~~~~~~~~~~~~
matrix.cpp:31:9: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d", &a[i][j]);
~~~~~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
10552 KB |
Output is correct |
2 |
Correct |
26 ms |
10872 KB |
Output is correct |
3 |
Correct |
21 ms |
10884 KB |
Output is correct |
4 |
Correct |
20 ms |
10936 KB |
Output is correct |
5 |
Correct |
21 ms |
10996 KB |
Output is correct |
6 |
Correct |
18 ms |
10996 KB |
Output is correct |
7 |
Correct |
17 ms |
10996 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
10996 KB |
Output is correct |
2 |
Correct |
22 ms |
11124 KB |
Output is correct |
3 |
Correct |
25 ms |
11352 KB |
Output is correct |
4 |
Correct |
26 ms |
11644 KB |
Output is correct |
5 |
Correct |
26 ms |
11872 KB |
Output is correct |
6 |
Correct |
19 ms |
12576 KB |
Output is correct |
7 |
Correct |
23 ms |
12600 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
27 ms |
10552 KB |
Output is correct |
2 |
Correct |
26 ms |
10872 KB |
Output is correct |
3 |
Correct |
21 ms |
10884 KB |
Output is correct |
4 |
Correct |
20 ms |
10936 KB |
Output is correct |
5 |
Correct |
21 ms |
10996 KB |
Output is correct |
6 |
Correct |
18 ms |
10996 KB |
Output is correct |
7 |
Correct |
17 ms |
10996 KB |
Output is correct |
8 |
Correct |
500 ms |
25460 KB |
Output is correct |
9 |
Correct |
329 ms |
25484 KB |
Output is correct |
10 |
Correct |
196 ms |
25484 KB |
Output is correct |
11 |
Correct |
277 ms |
25484 KB |
Output is correct |
12 |
Correct |
277 ms |
25484 KB |
Output is correct |
13 |
Correct |
181 ms |
25484 KB |
Output is correct |
14 |
Correct |
281 ms |
25548 KB |
Output is correct |
15 |
Correct |
289 ms |
25548 KB |
Output is correct |
16 |
Correct |
206 ms |
25548 KB |
Output is correct |
17 |
Correct |
208 ms |
25548 KB |
Output is correct |
18 |
Correct |
188 ms |
25548 KB |
Output is correct |
19 |
Correct |
199 ms |
25548 KB |
Output is correct |
20 |
Correct |
609 ms |
25548 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
23 ms |
10996 KB |
Output is correct |
2 |
Correct |
22 ms |
11124 KB |
Output is correct |
3 |
Correct |
25 ms |
11352 KB |
Output is correct |
4 |
Correct |
26 ms |
11644 KB |
Output is correct |
5 |
Correct |
26 ms |
11872 KB |
Output is correct |
6 |
Correct |
19 ms |
12576 KB |
Output is correct |
7 |
Correct |
23 ms |
12600 KB |
Output is correct |
8 |
Correct |
263 ms |
26840 KB |
Output is correct |
9 |
Correct |
258 ms |
26840 KB |
Output is correct |
10 |
Correct |
254 ms |
30464 KB |
Output is correct |
11 |
Correct |
202 ms |
33024 KB |
Output is correct |
12 |
Correct |
207 ms |
33024 KB |
Output is correct |
13 |
Correct |
232 ms |
33024 KB |
Output is correct |
14 |
Correct |
308 ms |
33024 KB |
Output is correct |
15 |
Correct |
229 ms |
33024 KB |
Output is correct |
16 |
Correct |
233 ms |
33024 KB |
Output is correct |
17 |
Correct |
322 ms |
33024 KB |
Output is correct |
18 |
Correct |
416 ms |
33024 KB |
Output is correct |
19 |
Correct |
209 ms |
33024 KB |
Output is correct |
20 |
Correct |
296 ms |
38580 KB |
Output is correct |
21 |
Correct |
269 ms |
47392 KB |
Output is correct |
22 |
Correct |
386 ms |
47888 KB |
Output is correct |
23 |
Correct |
310 ms |
55968 KB |
Output is correct |
24 |
Correct |
225 ms |
59596 KB |
Output is correct |
25 |
Correct |
304 ms |
66020 KB |
Output is correct |
26 |
Correct |
459 ms |
79696 KB |
Output is correct |
27 |
Correct |
248 ms |
79696 KB |
Output is correct |
28 |
Correct |
228 ms |
88244 KB |
Output is correct |
29 |
Correct |
278 ms |
91032 KB |
Output is correct |
30 |
Correct |
309 ms |
96712 KB |
Output is correct |
31 |
Correct |
503 ms |
108692 KB |
Output is correct |
32 |
Correct |
256 ms |
108692 KB |
Output is correct |