/*input
5 4
35 100
70 70
45 15
80 40
20 95
20 50 120
10 10 100
60 60 80
0 100 100
*/
#pragma GCC optimize ("O3")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
struct query
{
int i;
int a[3];
};
vector<int>A[202020];
void add(int x, int y)
{
while (x < 202020)
{
A[x].push_back(y);
x += x & (-x);
}
}
int get(int x, int y)
{
x = min(x, 202019);
int ans = 0;
while (x > 0)
{
for (int i : A[x])
{
if (i >= y)
ans++;
}
x -= (x & (-x));
}
return ans;
}
int main()
{
ios_base::sync_with_stdio(false);
int n, q;
cin >> n >> q;
vector<int>a[n];
map<int, int>M;
for (int i = 0; i < n; i++)
{
int s, t;
cin >> s >> t;
M[t + 2] = -1;
a[i] = {s, t, s + t};
}
sort(a, a + n, [&](vector<int>x, vector<int>y) {return x[0] > y[0];});
query Q[q];
for (int i = 0; i < q; i++)
{
Q[i].i = i;
cin >> Q[i].a[0] >> Q[i].a[1] >> Q[i].a[2];
M[Q[i].a[1] + 1] = -1;
}
sort(Q, Q + q, [&](query a, query b) {return a.a[0] > b.a[0];});
int timer = 1;
for (auto &i : M)
{
i.second = timer++;
}
int i = 0;
int ans[q];
for (query x : Q)
{
while (i < n && a[i][0] >= x.a[0])
{
add(M[a[i][1] + 2], a[i][2]);
i++;
}
ans[x.i] = get(1e6, x.a[2]) - get(M[x.a[1] + 1], x.a[2]);
}
for (int i = 0; i < q; i++)
cout << ans[i] << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
5112 KB |
Output is correct |
2 |
Correct |
6 ms |
5112 KB |
Output is correct |
3 |
Correct |
6 ms |
5112 KB |
Output is correct |
4 |
Correct |
6 ms |
5112 KB |
Output is correct |
5 |
Correct |
6 ms |
5112 KB |
Output is correct |
6 |
Correct |
6 ms |
5132 KB |
Output is correct |
7 |
Correct |
20 ms |
5944 KB |
Output is correct |
8 |
Correct |
20 ms |
5880 KB |
Output is correct |
9 |
Correct |
20 ms |
5880 KB |
Output is correct |
10 |
Correct |
15 ms |
5624 KB |
Output is correct |
11 |
Correct |
18 ms |
5880 KB |
Output is correct |
12 |
Correct |
13 ms |
5624 KB |
Output is correct |
13 |
Correct |
20 ms |
5852 KB |
Output is correct |
14 |
Correct |
19 ms |
5880 KB |
Output is correct |
15 |
Correct |
20 ms |
5880 KB |
Output is correct |
16 |
Correct |
17 ms |
5880 KB |
Output is correct |
17 |
Correct |
15 ms |
5624 KB |
Output is correct |
18 |
Correct |
12 ms |
5624 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2818 ms |
24144 KB |
Output is correct |
2 |
Correct |
2863 ms |
24076 KB |
Output is correct |
3 |
Correct |
2849 ms |
24216 KB |
Output is correct |
4 |
Correct |
2300 ms |
20260 KB |
Output is correct |
5 |
Correct |
2902 ms |
24100 KB |
Output is correct |
6 |
Correct |
2446 ms |
20348 KB |
Output is correct |
7 |
Execution timed out |
3051 ms |
23560 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2818 ms |
24144 KB |
Output is correct |
2 |
Correct |
2863 ms |
24076 KB |
Output is correct |
3 |
Correct |
2849 ms |
24216 KB |
Output is correct |
4 |
Correct |
2300 ms |
20260 KB |
Output is correct |
5 |
Correct |
2902 ms |
24100 KB |
Output is correct |
6 |
Correct |
2446 ms |
20348 KB |
Output is correct |
7 |
Execution timed out |
3051 ms |
23560 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
6 ms |
5112 KB |
Output is correct |
2 |
Correct |
6 ms |
5112 KB |
Output is correct |
3 |
Correct |
6 ms |
5112 KB |
Output is correct |
4 |
Correct |
6 ms |
5112 KB |
Output is correct |
5 |
Correct |
6 ms |
5112 KB |
Output is correct |
6 |
Correct |
6 ms |
5132 KB |
Output is correct |
7 |
Correct |
20 ms |
5944 KB |
Output is correct |
8 |
Correct |
20 ms |
5880 KB |
Output is correct |
9 |
Correct |
20 ms |
5880 KB |
Output is correct |
10 |
Correct |
15 ms |
5624 KB |
Output is correct |
11 |
Correct |
18 ms |
5880 KB |
Output is correct |
12 |
Correct |
13 ms |
5624 KB |
Output is correct |
13 |
Correct |
20 ms |
5852 KB |
Output is correct |
14 |
Correct |
19 ms |
5880 KB |
Output is correct |
15 |
Correct |
20 ms |
5880 KB |
Output is correct |
16 |
Correct |
17 ms |
5880 KB |
Output is correct |
17 |
Correct |
15 ms |
5624 KB |
Output is correct |
18 |
Correct |
12 ms |
5624 KB |
Output is correct |
19 |
Correct |
2818 ms |
24144 KB |
Output is correct |
20 |
Correct |
2863 ms |
24076 KB |
Output is correct |
21 |
Correct |
2849 ms |
24216 KB |
Output is correct |
22 |
Correct |
2300 ms |
20260 KB |
Output is correct |
23 |
Correct |
2902 ms |
24100 KB |
Output is correct |
24 |
Correct |
2446 ms |
20348 KB |
Output is correct |
25 |
Execution timed out |
3051 ms |
23560 KB |
Time limit exceeded |
26 |
Halted |
0 ms |
0 KB |
- |