#include<bits/stdc++.h>
using namespace std;
int nr, N, M, Q, h[200009], B[200009], realV[200009], aib[200009], dp[200009];
pair < int, int > v[200009], nrm[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]);
while (Q --)
{
int X, Y, ans = 0;
scanf ("%d %d", &X, &Y);
for (int i=1; i<=N; i++)
if (v[i].first >= X && v[i].second <= Y)
ans = max (ans, dp[i]);
printf ("%d\n", ans);
}
return 0;
}
Compilation message
matryoshka.cpp: In function 'int main()':
matryoshka.cpp:29: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:31: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:11: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf ("%d %d", &X, &Y);
~~~~~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
428 KB |
Output is correct |
4 |
Correct |
2 ms |
428 KB |
Output is correct |
5 |
Correct |
2 ms |
460 KB |
Output is correct |
6 |
Correct |
2 ms |
640 KB |
Output is correct |
7 |
Correct |
2 ms |
652 KB |
Output is correct |
8 |
Correct |
2 ms |
652 KB |
Output is correct |
9 |
Correct |
2 ms |
652 KB |
Output is correct |
10 |
Correct |
2 ms |
652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
428 KB |
Output is correct |
4 |
Correct |
2 ms |
428 KB |
Output is correct |
5 |
Correct |
2 ms |
460 KB |
Output is correct |
6 |
Correct |
2 ms |
640 KB |
Output is correct |
7 |
Correct |
2 ms |
652 KB |
Output is correct |
8 |
Correct |
2 ms |
652 KB |
Output is correct |
9 |
Correct |
2 ms |
652 KB |
Output is correct |
10 |
Correct |
2 ms |
652 KB |
Output is correct |
11 |
Correct |
2 ms |
652 KB |
Output is correct |
12 |
Correct |
2 ms |
652 KB |
Output is correct |
13 |
Correct |
2 ms |
652 KB |
Output is correct |
14 |
Correct |
2 ms |
652 KB |
Output is correct |
15 |
Correct |
2 ms |
652 KB |
Output is correct |
16 |
Correct |
2 ms |
652 KB |
Output is correct |
17 |
Correct |
2 ms |
652 KB |
Output is correct |
18 |
Correct |
2 ms |
652 KB |
Output is correct |
19 |
Correct |
2 ms |
652 KB |
Output is correct |
20 |
Correct |
2 ms |
652 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
428 KB |
Output is correct |
4 |
Correct |
2 ms |
428 KB |
Output is correct |
5 |
Correct |
2 ms |
460 KB |
Output is correct |
6 |
Correct |
2 ms |
640 KB |
Output is correct |
7 |
Correct |
2 ms |
652 KB |
Output is correct |
8 |
Correct |
2 ms |
652 KB |
Output is correct |
9 |
Correct |
2 ms |
652 KB |
Output is correct |
10 |
Correct |
2 ms |
652 KB |
Output is correct |
11 |
Correct |
2 ms |
652 KB |
Output is correct |
12 |
Correct |
2 ms |
652 KB |
Output is correct |
13 |
Correct |
2 ms |
652 KB |
Output is correct |
14 |
Correct |
2 ms |
652 KB |
Output is correct |
15 |
Correct |
2 ms |
652 KB |
Output is correct |
16 |
Correct |
2 ms |
652 KB |
Output is correct |
17 |
Correct |
2 ms |
652 KB |
Output is correct |
18 |
Correct |
2 ms |
652 KB |
Output is correct |
19 |
Correct |
2 ms |
652 KB |
Output is correct |
20 |
Correct |
2 ms |
652 KB |
Output is correct |
21 |
Correct |
2 ms |
652 KB |
Output is correct |
22 |
Correct |
5 ms |
652 KB |
Output is correct |
23 |
Correct |
18 ms |
716 KB |
Output is correct |
24 |
Correct |
8 ms |
716 KB |
Output is correct |
25 |
Correct |
9 ms |
716 KB |
Output is correct |
26 |
Correct |
8 ms |
716 KB |
Output is correct |
27 |
Correct |
8 ms |
716 KB |
Output is correct |
28 |
Correct |
8 ms |
716 KB |
Output is correct |
29 |
Correct |
8 ms |
716 KB |
Output is correct |
30 |
Correct |
8 ms |
716 KB |
Output is correct |
31 |
Correct |
14 ms |
716 KB |
Output is correct |
32 |
Correct |
14 ms |
716 KB |
Output is correct |
33 |
Correct |
16 ms |
716 KB |
Output is correct |
34 |
Correct |
14 ms |
716 KB |
Output is correct |
35 |
Correct |
16 ms |
720 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
2 ms |
428 KB |
Output is correct |
4 |
Correct |
2 ms |
428 KB |
Output is correct |
5 |
Correct |
2 ms |
460 KB |
Output is correct |
6 |
Correct |
2 ms |
640 KB |
Output is correct |
7 |
Correct |
2 ms |
652 KB |
Output is correct |
8 |
Correct |
2 ms |
652 KB |
Output is correct |
9 |
Correct |
2 ms |
652 KB |
Output is correct |
10 |
Correct |
2 ms |
652 KB |
Output is correct |
11 |
Correct |
2 ms |
652 KB |
Output is correct |
12 |
Correct |
2 ms |
652 KB |
Output is correct |
13 |
Correct |
2 ms |
652 KB |
Output is correct |
14 |
Correct |
2 ms |
652 KB |
Output is correct |
15 |
Correct |
2 ms |
652 KB |
Output is correct |
16 |
Correct |
2 ms |
652 KB |
Output is correct |
17 |
Correct |
2 ms |
652 KB |
Output is correct |
18 |
Correct |
2 ms |
652 KB |
Output is correct |
19 |
Correct |
2 ms |
652 KB |
Output is correct |
20 |
Correct |
2 ms |
652 KB |
Output is correct |
21 |
Correct |
2 ms |
652 KB |
Output is correct |
22 |
Correct |
5 ms |
652 KB |
Output is correct |
23 |
Correct |
18 ms |
716 KB |
Output is correct |
24 |
Correct |
8 ms |
716 KB |
Output is correct |
25 |
Correct |
9 ms |
716 KB |
Output is correct |
26 |
Correct |
8 ms |
716 KB |
Output is correct |
27 |
Correct |
8 ms |
716 KB |
Output is correct |
28 |
Correct |
8 ms |
716 KB |
Output is correct |
29 |
Correct |
8 ms |
716 KB |
Output is correct |
30 |
Correct |
8 ms |
716 KB |
Output is correct |
31 |
Correct |
14 ms |
716 KB |
Output is correct |
32 |
Correct |
14 ms |
716 KB |
Output is correct |
33 |
Correct |
16 ms |
716 KB |
Output is correct |
34 |
Correct |
14 ms |
716 KB |
Output is correct |
35 |
Correct |
16 ms |
720 KB |
Output is correct |
36 |
Execution timed out |
2066 ms |
6432 KB |
Time limit exceeded |
37 |
Halted |
0 ms |
0 KB |
- |