#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct Query
{
int a, b, c, idx;
Query() : a(0), b(0), c(0), idx(0) {}
Query(int _a, int _b, int _c, int _idx) : a(_a), b(_b), c(_c), idx(_idx) {}
};
struct Student
{
int s, t, idx;
Student() : s(0), t(0), idx(0) {}
};
int n, q;
struct SegTree
{
int t[1000000] = {0};
SegTree() {}
void update(int idx, int v = 1, int tl = 0, int tr = 200000)
{
if (tl == tr)
{
t[v]++;
return;
}
int tm = (tl + tr) / 2;
if (idx <= tm)
update(idx, 2 * v, tl, tm);
else
update(idx, 2 * v + 1, tm + 1, tr);
t[v] = t[2 * v] + t[2 * v + 1];
}
int query(int l, int r, int v = 1, int tl = 0, int tr = 200000)
{
if (l > r || r < tl || tr < l)
return 0;
if (l <= tl && tr <= r)
return t[v];
int tm = (tl + tr) / 2;
return query(l, r, 2 * v, tl, tm) + query(l, r, 2 * v + 1, tm + 1, tr);
}
};
int main()
{
cin.tie(0)->sync_with_stdio(0);
cin >> n >> q;
vector<Student> students(n);
for (Student &x : students)
cin >> x.s >> 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));
}
vector<int> res(q);
SegTree seg1;
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)
seg1.update(students[i++].t);
res[Q.idx] = seg1.query(Q.b, 200000);
}
seg1 = SegTree();
SegTree seg2;
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)
{
seg1.update(students[i].s);
seg2.update(students[i].t);
i++;
}
res[Q.idx] = seg1.query(Q.a, 200000) - seg2.query(0, Q.b - 1);
}
for (int j = 0; j < q; j++)
cout << res[j] << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
8136 KB |
Output is correct |
2 |
Correct |
5 ms |
8148 KB |
Output is correct |
3 |
Correct |
6 ms |
8148 KB |
Output is correct |
4 |
Incorrect |
5 ms |
8144 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
117 ms |
14280 KB |
Output is correct |
2 |
Correct |
135 ms |
14312 KB |
Output is correct |
3 |
Correct |
122 ms |
14280 KB |
Output is correct |
4 |
Correct |
97 ms |
13540 KB |
Output is correct |
5 |
Correct |
111 ms |
13548 KB |
Output is correct |
6 |
Correct |
70 ms |
12768 KB |
Output is correct |
7 |
Correct |
120 ms |
14224 KB |
Output is correct |
8 |
Correct |
103 ms |
14160 KB |
Output is correct |
9 |
Correct |
118 ms |
14092 KB |
Output is correct |
10 |
Correct |
109 ms |
13312 KB |
Output is correct |
11 |
Correct |
75 ms |
13520 KB |
Output is correct |
12 |
Correct |
61 ms |
12468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
117 ms |
14280 KB |
Output is correct |
2 |
Correct |
135 ms |
14312 KB |
Output is correct |
3 |
Correct |
122 ms |
14280 KB |
Output is correct |
4 |
Correct |
97 ms |
13540 KB |
Output is correct |
5 |
Correct |
111 ms |
13548 KB |
Output is correct |
6 |
Correct |
70 ms |
12768 KB |
Output is correct |
7 |
Correct |
120 ms |
14224 KB |
Output is correct |
8 |
Correct |
103 ms |
14160 KB |
Output is correct |
9 |
Correct |
118 ms |
14092 KB |
Output is correct |
10 |
Correct |
109 ms |
13312 KB |
Output is correct |
11 |
Correct |
75 ms |
13520 KB |
Output is correct |
12 |
Correct |
61 ms |
12468 KB |
Output is correct |
13 |
Correct |
170 ms |
14716 KB |
Output is correct |
14 |
Correct |
133 ms |
14824 KB |
Output is correct |
15 |
Correct |
104 ms |
14276 KB |
Output is correct |
16 |
Correct |
104 ms |
13932 KB |
Output is correct |
17 |
Correct |
134 ms |
13924 KB |
Output is correct |
18 |
Correct |
88 ms |
12912 KB |
Output is correct |
19 |
Correct |
158 ms |
14724 KB |
Output is correct |
20 |
Correct |
160 ms |
14696 KB |
Output is correct |
21 |
Correct |
166 ms |
15076 KB |
Output is correct |
22 |
Correct |
108 ms |
13412 KB |
Output is correct |
23 |
Correct |
73 ms |
13396 KB |
Output is correct |
24 |
Correct |
61 ms |
12412 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
8136 KB |
Output is correct |
2 |
Correct |
5 ms |
8148 KB |
Output is correct |
3 |
Correct |
6 ms |
8148 KB |
Output is correct |
4 |
Incorrect |
5 ms |
8144 KB |
Output isn't correct |
5 |
Halted |
0 ms |
0 KB |
- |