#include<bits/stdc++.h>
using namespace std;
int nr, N, M, Q, h[200009], B[200009], realV[200009], aib[200009], dp[200009], ans[200009];
pair < int, int > v[200009], nrm[200009];
pair < pair < int, int >, int > qr[200009];
void Update (int pos, int val)
{
while (pos <= M)
aib[pos] = max (aib[pos], val),
pos += pos - (pos & (pos - 1));
}
int Query (int pos)
{
int ans = 0;
while (pos)
ans = max (ans, aib[pos]),
pos &= pos - 1;
return ans;
}
int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);
scanf ("%d %d", &N, &Q);
for (int i=1; i<=N; i++)
scanf ("%d %d", &v[i].first, &v[i].second), v[i].second = -v[i].second;
sort (v + 1, v + N + 1);
for (int i=1; i<=N; i++)
v[i].second = -v[i].second, nrm[i] = {v[i].second, i};
sort (nrm + 1, nrm + N + 1), M = 0;
for (int i=1; i<=N; i++)
{
if (i == 1 || nrm[i].first != nrm[i - 1].first)
realV[++M] = nrm[i].first;
B[nrm[i].second] = M;
}
for (int i=N; i>=1; i--)
dp[i] = Query (B[i]) + 1,
Update (B[i], dp[i]);
for (int i=1; i<=Q; i++)
scanf ("%d %d", &qr[i].first.first, &qr[i].first.second),
qr[i].first.first = -qr[i].first.first, qr[i].second = i;
sort (qr + 1, qr + Q + 1);
memset (aib, 0, sizeof (aib));
for (int i=1; i<=Q; i++)
qr[i].first.first = -qr[i].first.first;
int j = N;
for (int i=1; i<=Q; i++)
{
while (v[j].first >= qr[i].first.first && j > 0)
Update (B[j], dp[j]), j --;
int pos = upper_bound (realV + 1, realV + M + 1, qr[i].first.second) - realV - 1;
ans[qr[i].second] = Query (pos);
}
for (int i=1; i<=Q; i++)
printf ("%d\n", ans[i]);
return 0;
}
Compilation message
matryoshka.cpp: In function 'int main()':
matryoshka.cpp:30:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf ("%d %d", &N, &Q);
~~~~~~^~~~~~~~~~~~~~~~~
matryoshka.cpp:32:47: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf ("%d %d", &v[i].first, &v[i].second), v[i].second = -v[i].second;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
matryoshka.cpp:48:43: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf ("%d %d", &qr[i].first.first, &qr[i].first.second),
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
qr[i].first.first = -qr[i].first.first, qr[i].second = i;
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1144 KB |
Output is correct |
2 |
Correct |
3 ms |
1144 KB |
Output is correct |
3 |
Correct |
2 ms |
1312 KB |
Output is correct |
4 |
Correct |
2 ms |
1396 KB |
Output is correct |
5 |
Correct |
3 ms |
1396 KB |
Output is correct |
6 |
Correct |
2 ms |
1396 KB |
Output is correct |
7 |
Correct |
3 ms |
1396 KB |
Output is correct |
8 |
Correct |
3 ms |
1396 KB |
Output is correct |
9 |
Correct |
3 ms |
1396 KB |
Output is correct |
10 |
Correct |
2 ms |
1396 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1144 KB |
Output is correct |
2 |
Correct |
3 ms |
1144 KB |
Output is correct |
3 |
Correct |
2 ms |
1312 KB |
Output is correct |
4 |
Correct |
2 ms |
1396 KB |
Output is correct |
5 |
Correct |
3 ms |
1396 KB |
Output is correct |
6 |
Correct |
2 ms |
1396 KB |
Output is correct |
7 |
Correct |
3 ms |
1396 KB |
Output is correct |
8 |
Correct |
3 ms |
1396 KB |
Output is correct |
9 |
Correct |
3 ms |
1396 KB |
Output is correct |
10 |
Correct |
2 ms |
1396 KB |
Output is correct |
11 |
Correct |
3 ms |
1396 KB |
Output is correct |
12 |
Correct |
3 ms |
1396 KB |
Output is correct |
13 |
Correct |
3 ms |
1516 KB |
Output is correct |
14 |
Correct |
2 ms |
1516 KB |
Output is correct |
15 |
Correct |
2 ms |
1516 KB |
Output is correct |
16 |
Correct |
2 ms |
1516 KB |
Output is correct |
17 |
Correct |
2 ms |
1516 KB |
Output is correct |
18 |
Correct |
3 ms |
1516 KB |
Output is correct |
19 |
Correct |
2 ms |
1516 KB |
Output is correct |
20 |
Correct |
3 ms |
1516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1144 KB |
Output is correct |
2 |
Correct |
3 ms |
1144 KB |
Output is correct |
3 |
Correct |
2 ms |
1312 KB |
Output is correct |
4 |
Correct |
2 ms |
1396 KB |
Output is correct |
5 |
Correct |
3 ms |
1396 KB |
Output is correct |
6 |
Correct |
2 ms |
1396 KB |
Output is correct |
7 |
Correct |
3 ms |
1396 KB |
Output is correct |
8 |
Correct |
3 ms |
1396 KB |
Output is correct |
9 |
Correct |
3 ms |
1396 KB |
Output is correct |
10 |
Correct |
2 ms |
1396 KB |
Output is correct |
11 |
Correct |
3 ms |
1396 KB |
Output is correct |
12 |
Correct |
3 ms |
1396 KB |
Output is correct |
13 |
Correct |
3 ms |
1516 KB |
Output is correct |
14 |
Correct |
2 ms |
1516 KB |
Output is correct |
15 |
Correct |
2 ms |
1516 KB |
Output is correct |
16 |
Correct |
2 ms |
1516 KB |
Output is correct |
17 |
Correct |
2 ms |
1516 KB |
Output is correct |
18 |
Correct |
3 ms |
1516 KB |
Output is correct |
19 |
Correct |
2 ms |
1516 KB |
Output is correct |
20 |
Correct |
3 ms |
1516 KB |
Output is correct |
21 |
Correct |
3 ms |
1516 KB |
Output is correct |
22 |
Correct |
5 ms |
1516 KB |
Output is correct |
23 |
Correct |
6 ms |
1532 KB |
Output is correct |
24 |
Correct |
6 ms |
1532 KB |
Output is correct |
25 |
Correct |
5 ms |
1532 KB |
Output is correct |
26 |
Correct |
6 ms |
1676 KB |
Output is correct |
27 |
Correct |
4 ms |
1676 KB |
Output is correct |
28 |
Correct |
5 ms |
1676 KB |
Output is correct |
29 |
Correct |
5 ms |
1708 KB |
Output is correct |
30 |
Correct |
4 ms |
1708 KB |
Output is correct |
31 |
Correct |
6 ms |
1708 KB |
Output is correct |
32 |
Correct |
5 ms |
1708 KB |
Output is correct |
33 |
Correct |
5 ms |
1708 KB |
Output is correct |
34 |
Correct |
5 ms |
1708 KB |
Output is correct |
35 |
Correct |
5 ms |
1708 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1144 KB |
Output is correct |
2 |
Correct |
3 ms |
1144 KB |
Output is correct |
3 |
Correct |
2 ms |
1312 KB |
Output is correct |
4 |
Correct |
2 ms |
1396 KB |
Output is correct |
5 |
Correct |
3 ms |
1396 KB |
Output is correct |
6 |
Correct |
2 ms |
1396 KB |
Output is correct |
7 |
Correct |
3 ms |
1396 KB |
Output is correct |
8 |
Correct |
3 ms |
1396 KB |
Output is correct |
9 |
Correct |
3 ms |
1396 KB |
Output is correct |
10 |
Correct |
2 ms |
1396 KB |
Output is correct |
11 |
Correct |
3 ms |
1396 KB |
Output is correct |
12 |
Correct |
3 ms |
1396 KB |
Output is correct |
13 |
Correct |
3 ms |
1516 KB |
Output is correct |
14 |
Correct |
2 ms |
1516 KB |
Output is correct |
15 |
Correct |
2 ms |
1516 KB |
Output is correct |
16 |
Correct |
2 ms |
1516 KB |
Output is correct |
17 |
Correct |
2 ms |
1516 KB |
Output is correct |
18 |
Correct |
3 ms |
1516 KB |
Output is correct |
19 |
Correct |
2 ms |
1516 KB |
Output is correct |
20 |
Correct |
3 ms |
1516 KB |
Output is correct |
21 |
Correct |
3 ms |
1516 KB |
Output is correct |
22 |
Correct |
5 ms |
1516 KB |
Output is correct |
23 |
Correct |
6 ms |
1532 KB |
Output is correct |
24 |
Correct |
6 ms |
1532 KB |
Output is correct |
25 |
Correct |
5 ms |
1532 KB |
Output is correct |
26 |
Correct |
6 ms |
1676 KB |
Output is correct |
27 |
Correct |
4 ms |
1676 KB |
Output is correct |
28 |
Correct |
5 ms |
1676 KB |
Output is correct |
29 |
Correct |
5 ms |
1708 KB |
Output is correct |
30 |
Correct |
4 ms |
1708 KB |
Output is correct |
31 |
Correct |
6 ms |
1708 KB |
Output is correct |
32 |
Correct |
5 ms |
1708 KB |
Output is correct |
33 |
Correct |
5 ms |
1708 KB |
Output is correct |
34 |
Correct |
5 ms |
1708 KB |
Output is correct |
35 |
Correct |
5 ms |
1708 KB |
Output is correct |
36 |
Correct |
269 ms |
10544 KB |
Output is correct |
37 |
Correct |
226 ms |
10544 KB |
Output is correct |
38 |
Correct |
91 ms |
10544 KB |
Output is correct |
39 |
Correct |
192 ms |
10544 KB |
Output is correct |
40 |
Correct |
189 ms |
10544 KB |
Output is correct |
41 |
Correct |
218 ms |
10544 KB |
Output is correct |
42 |
Correct |
147 ms |
10544 KB |
Output is correct |
43 |
Correct |
105 ms |
10556 KB |
Output is correct |
44 |
Correct |
290 ms |
10928 KB |
Output is correct |
45 |
Correct |
284 ms |
10928 KB |
Output is correct |
46 |
Correct |
298 ms |
10980 KB |
Output is correct |
47 |
Correct |
272 ms |
10980 KB |
Output is correct |
48 |
Correct |
284 ms |
11068 KB |
Output is correct |
49 |
Correct |
275 ms |
11068 KB |
Output is correct |
50 |
Correct |
282 ms |
11068 KB |
Output is correct |