#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct Query
{
int a, b, A, B, C, idx;
Query() : a(0), b(0), A(0), B(0), C(0), idx(0) {}
Query(int _a, int _b, int _c, int _idx) : a(0), b(0), A(_a), B(_b), C(_c), idx(_idx) {}
};
struct Student
{
int s, t, S, T, idx;
Student() : s(0), t(0), S(0), T(0), idx(0) {}
};
int n, q;
struct BIT
{
int bit[300000] = {0};
BIT() {}
void update(int idx)
{
for (; idx < 300000; idx |= (idx + 1))
bit[idx]++;
}
int sum(int idx)
{
int res = 0;
for (; idx >= 0; idx = (idx & (idx + 1)) - 1)
res += bit[idx];
return res;
}
int sum(int l, int r)
{
return sum(r) - sum(l-1);
}
};
int main()
{
cin.tie(0)->sync_with_stdio(0);
cin >> n >> q;
set<int> a_vals, b_vals;
vector<Student> students(n);
for (Student &x : students)
{
cin >> x.S >> x.T;
a_vals.insert(x.S);
b_vals.insert(x.T);
}
vector<Query> type1, type2;
for (int i = 0, a, b, c; i < q; i++)
{
cin >> a >> b >> c;
if (a + b >= c)
type1.push_back(Query(a, b, c, i));
else
type2.push_back(Query(a, b, c, i));
a_vals.insert(a);
b_vals.insert(b);
}
unordered_map<int, int> smolA, smolB;
int mxA = 0;
for (int a : a_vals)
smolA[a] = mxA++;
int mxB = 0;
for (int b : b_vals)
smolB[b] = mxB++;
for (Student &x : students)
{
x.s = smolA[x.S];
x.t = smolB[x.T];
}
for (Query &Q : type1)
{
Q.a = smolA[Q.A];
Q.b = smolB[Q.B];
}
for (Query &Q : type2)
{
Q.a = smolA[Q.A];
Q.b = smolB[Q.B];
}
vector<int> res(q);
BIT bit1;
sort(type1.begin(), type1.end(), [] (const Query &X, const Query &Y) {return X.A > Y.A;});
sort(students.begin(), students.end(), [] (const Student &X, const Student &Y) {return X.S > Y.S;});
int i = 0;
for (const Query &Q : type1)
{
while (i < n && students[i].S >= Q.A)
bit1.update(students[i++].t);
res[Q.idx] = bit1.sum(Q.b, 200000);
}
bit1 = BIT();
BIT bit2;
sort(type2.begin(), type2.end(), [] (const Query &X, const Query &Y) {return X.C > Y.C;});
sort(students.begin(), students.end(), [] (const Student &X, const Student &Y) {return X.S + X.T > Y.S + Y.T;});
i = 0;
for (const Query &Q : type2)
{
while (i < n && students[i].S + students[i].T >= Q.C)
{
bit1.update(students[i].s);
bit2.update(students[i].t);
i++;
}
res[Q.idx] = bit1.sum(Q.a, 200000) - bit2.sum(0, Q.b - 1);
}
for (int j = 0; j < q; j++)
cout << res[j] << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
1 ms |
2644 KB |
Output is correct |
4 |
Correct |
1 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2644 KB |
Output is correct |
6 |
Correct |
1 ms |
2644 KB |
Output is correct |
7 |
Correct |
8 ms |
3924 KB |
Output is correct |
8 |
Correct |
8 ms |
3928 KB |
Output is correct |
9 |
Correct |
8 ms |
3924 KB |
Output is correct |
10 |
Correct |
6 ms |
3284 KB |
Output is correct |
11 |
Correct |
7 ms |
3284 KB |
Output is correct |
12 |
Correct |
4 ms |
2772 KB |
Output is correct |
13 |
Correct |
9 ms |
3924 KB |
Output is correct |
14 |
Correct |
8 ms |
3924 KB |
Output is correct |
15 |
Correct |
10 ms |
3924 KB |
Output is correct |
16 |
Correct |
6 ms |
3284 KB |
Output is correct |
17 |
Correct |
6 ms |
3372 KB |
Output is correct |
18 |
Correct |
4 ms |
2772 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
243 ms |
24380 KB |
Output is correct |
2 |
Correct |
268 ms |
24296 KB |
Output is correct |
3 |
Correct |
231 ms |
24444 KB |
Output is correct |
4 |
Correct |
138 ms |
16272 KB |
Output is correct |
5 |
Correct |
144 ms |
16288 KB |
Output is correct |
6 |
Correct |
64 ms |
7884 KB |
Output is correct |
7 |
Correct |
225 ms |
22176 KB |
Output is correct |
8 |
Correct |
228 ms |
21900 KB |
Output is correct |
9 |
Correct |
214 ms |
19672 KB |
Output is correct |
10 |
Correct |
145 ms |
16108 KB |
Output is correct |
11 |
Correct |
157 ms |
16116 KB |
Output is correct |
12 |
Correct |
51 ms |
7828 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
243 ms |
24380 KB |
Output is correct |
2 |
Correct |
268 ms |
24296 KB |
Output is correct |
3 |
Correct |
231 ms |
24444 KB |
Output is correct |
4 |
Correct |
138 ms |
16272 KB |
Output is correct |
5 |
Correct |
144 ms |
16288 KB |
Output is correct |
6 |
Correct |
64 ms |
7884 KB |
Output is correct |
7 |
Correct |
225 ms |
22176 KB |
Output is correct |
8 |
Correct |
228 ms |
21900 KB |
Output is correct |
9 |
Correct |
214 ms |
19672 KB |
Output is correct |
10 |
Correct |
145 ms |
16108 KB |
Output is correct |
11 |
Correct |
157 ms |
16116 KB |
Output is correct |
12 |
Correct |
51 ms |
7828 KB |
Output is correct |
13 |
Correct |
273 ms |
24344 KB |
Output is correct |
14 |
Correct |
235 ms |
24420 KB |
Output is correct |
15 |
Correct |
245 ms |
24348 KB |
Output is correct |
16 |
Correct |
143 ms |
16188 KB |
Output is correct |
17 |
Correct |
143 ms |
16244 KB |
Output is correct |
18 |
Correct |
68 ms |
8352 KB |
Output is correct |
19 |
Correct |
227 ms |
24456 KB |
Output is correct |
20 |
Correct |
223 ms |
24372 KB |
Output is correct |
21 |
Correct |
208 ms |
21628 KB |
Output is correct |
22 |
Correct |
136 ms |
16120 KB |
Output is correct |
23 |
Correct |
140 ms |
15992 KB |
Output is correct |
24 |
Correct |
52 ms |
7788 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
2644 KB |
Output is correct |
2 |
Correct |
2 ms |
2644 KB |
Output is correct |
3 |
Correct |
1 ms |
2644 KB |
Output is correct |
4 |
Correct |
1 ms |
2644 KB |
Output is correct |
5 |
Correct |
2 ms |
2644 KB |
Output is correct |
6 |
Correct |
1 ms |
2644 KB |
Output is correct |
7 |
Correct |
8 ms |
3924 KB |
Output is correct |
8 |
Correct |
8 ms |
3928 KB |
Output is correct |
9 |
Correct |
8 ms |
3924 KB |
Output is correct |
10 |
Correct |
6 ms |
3284 KB |
Output is correct |
11 |
Correct |
7 ms |
3284 KB |
Output is correct |
12 |
Correct |
4 ms |
2772 KB |
Output is correct |
13 |
Correct |
9 ms |
3924 KB |
Output is correct |
14 |
Correct |
8 ms |
3924 KB |
Output is correct |
15 |
Correct |
10 ms |
3924 KB |
Output is correct |
16 |
Correct |
6 ms |
3284 KB |
Output is correct |
17 |
Correct |
6 ms |
3372 KB |
Output is correct |
18 |
Correct |
4 ms |
2772 KB |
Output is correct |
19 |
Correct |
243 ms |
24380 KB |
Output is correct |
20 |
Correct |
268 ms |
24296 KB |
Output is correct |
21 |
Correct |
231 ms |
24444 KB |
Output is correct |
22 |
Correct |
138 ms |
16272 KB |
Output is correct |
23 |
Correct |
144 ms |
16288 KB |
Output is correct |
24 |
Correct |
64 ms |
7884 KB |
Output is correct |
25 |
Correct |
225 ms |
22176 KB |
Output is correct |
26 |
Correct |
228 ms |
21900 KB |
Output is correct |
27 |
Correct |
214 ms |
19672 KB |
Output is correct |
28 |
Correct |
145 ms |
16108 KB |
Output is correct |
29 |
Correct |
157 ms |
16116 KB |
Output is correct |
30 |
Correct |
51 ms |
7828 KB |
Output is correct |
31 |
Correct |
273 ms |
24344 KB |
Output is correct |
32 |
Correct |
235 ms |
24420 KB |
Output is correct |
33 |
Correct |
245 ms |
24348 KB |
Output is correct |
34 |
Correct |
143 ms |
16188 KB |
Output is correct |
35 |
Correct |
143 ms |
16244 KB |
Output is correct |
36 |
Correct |
68 ms |
8352 KB |
Output is correct |
37 |
Correct |
227 ms |
24456 KB |
Output is correct |
38 |
Correct |
223 ms |
24372 KB |
Output is correct |
39 |
Correct |
208 ms |
21628 KB |
Output is correct |
40 |
Correct |
136 ms |
16120 KB |
Output is correct |
41 |
Correct |
140 ms |
15992 KB |
Output is correct |
42 |
Correct |
52 ms |
7788 KB |
Output is correct |
43 |
Correct |
572 ms |
44804 KB |
Output is correct |
44 |
Correct |
548 ms |
44804 KB |
Output is correct |
45 |
Correct |
488 ms |
44836 KB |
Output is correct |
46 |
Correct |
318 ms |
26260 KB |
Output is correct |
47 |
Correct |
228 ms |
26220 KB |
Output is correct |
48 |
Correct |
68 ms |
8832 KB |
Output is correct |
49 |
Correct |
530 ms |
44796 KB |
Output is correct |
50 |
Correct |
485 ms |
44804 KB |
Output is correct |
51 |
Correct |
514 ms |
44952 KB |
Output is correct |
52 |
Correct |
273 ms |
26156 KB |
Output is correct |
53 |
Correct |
256 ms |
26268 KB |
Output is correct |