#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;
struct Data
{
int s, t, sum, id;
Data(int s = 0, int t = 0, int sum = 0, int id = 0) : s(s), t(t), sum(sum), id(id) {}
};
int n, q;
int ans[MAXN];
vector <int> S, T;
vector <int> Value[MAXN], BIT[MAXN];
vector <Data> Student, Query, Query2D;
void Unique(vector <int> &A)
{
sort(A.begin(), A.end());
A.erase(unique(A.begin(), A.end()), A.end());
}
void Change(vector <Data> &A)
{
for(auto &x : A)
{
x.s = S.end() - lower_bound(S.begin(), S.end(), x.s);
x.t = T.end() - lower_bound(T.begin(), T.end(), x.t);
}
}
int GetPos(vector <int> &A, int b)
{
return lower_bound(A.begin(), A.end(), b) - A.begin();
}
void FakeUpdate(int x, int y)
{
for(x; x < MAXN; x += x & -x)
{
Value[x].push_back(y);
}
}
void FakeGet(int x, int y)
{
for(x; x > 0; x -= x & -x)
{
Value[x].push_back(y);
}
}
void Update(int x, int y)
{
for(x; x < MAXN; x += x & -x)
{
for(int id = GetPos(Value[x], y); id < (int)BIT[x].size(); id += id & -id)
{
BIT[x][id]++;
}
}
}
int Get(int x, int y)
{
int ans = 0;
for(x; x > 0; x -= x & -x)
{
for(int id = GetPos(Value[x], y); id > 0; id -= id & -id)
{
ans += BIT[x][id];
}
}
return ans;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> q;
Student.resize(n);
for(int i = 0; i < n; i++)
{
cin >> Student[i].s >> Student[i].t;
S.push_back(Student[i].s);
T.push_back(Student[i].t);
Student[i].sum = Student[i].s + Student[i].t;
Student[i].id = -1;
}
Query.resize(q);
for(int i = 0; i < q; i++)
{
cin >> Query[i].s >> Query[i].t >> Query[i].sum;
S.push_back(Query[i].s);
T.push_back(Query[i].t);
Query[i].id = i;
}
sort(Student.begin(), Student.end(), [](Data A, Data B)
{
return A.sum > B.sum;
});
sort(Query.begin(), Query.end(), [](Data A, Data B)
{
return A.sum > B.sum;
});
Unique(S);
Unique(T);
Change(Student);
Change(Query);
int pt0 = 0, pt1 = 0;
while(pt0 < (int)Student.size() and pt1 < (int)Query.size())
{
if(Student[pt0].sum >= Query[pt1].sum)
{
Query2D.push_back(Student[pt0]);
pt0++;
}
else
{
Query2D.push_back(Query[pt1]);
pt1++;
}
}
while(pt1 < (int)Query.size())
{
Query2D.push_back(Query[pt1]);
pt1++;
}
for(auto x : Query2D)
{
if(x.id == -1)
{
FakeUpdate(x.s, x.t);
}
else
{
FakeGet(x.s, x.t);
}
}
for(int i = 1; i < MAXN; i++)
{
Value[i].push_back(0);
Unique(Value[i]);
BIT[i].resize(Value[i].size() + 5);
}
for(auto x : Query2D)
{
if(x.id == -1)
{
Update(x.s, x.t);
}
else
{
ans[x.id] = Get(x.s, x.t);
}
}
for(int i = 0; i < q; i++)
{
cout << ans[i] << '\n';
}
}
Compilation message
examination.cpp: In function 'void FakeUpdate(int, int)':
examination.cpp:40:9: warning: statement has no effect [-Wunused-value]
40 | for(x; x < MAXN; x += x & -x)
| ^
examination.cpp: In function 'void FakeGet(int, int)':
examination.cpp:48:9: warning: statement has no effect [-Wunused-value]
48 | for(x; x > 0; x -= x & -x)
| ^
examination.cpp: In function 'void Update(int, int)':
examination.cpp:56:9: warning: statement has no effect [-Wunused-value]
56 | for(x; x < MAXN; x += x & -x)
| ^
examination.cpp: In function 'int Get(int, int)':
examination.cpp:68:9: warning: statement has no effect [-Wunused-value]
68 | for(x; x > 0; x -= x & -x)
| ^
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
11212 KB |
Output is correct |
2 |
Correct |
15 ms |
11272 KB |
Output is correct |
3 |
Correct |
16 ms |
11212 KB |
Output is correct |
4 |
Correct |
15 ms |
11212 KB |
Output is correct |
5 |
Correct |
14 ms |
11284 KB |
Output is correct |
6 |
Correct |
14 ms |
11252 KB |
Output is correct |
7 |
Correct |
28 ms |
11980 KB |
Output is correct |
8 |
Correct |
29 ms |
11972 KB |
Output is correct |
9 |
Correct |
28 ms |
11980 KB |
Output is correct |
10 |
Correct |
24 ms |
11800 KB |
Output is correct |
11 |
Correct |
27 ms |
11980 KB |
Output is correct |
12 |
Correct |
21 ms |
11864 KB |
Output is correct |
13 |
Correct |
26 ms |
11972 KB |
Output is correct |
14 |
Correct |
27 ms |
12032 KB |
Output is correct |
15 |
Correct |
28 ms |
11980 KB |
Output is correct |
16 |
Correct |
24 ms |
11968 KB |
Output is correct |
17 |
Correct |
22 ms |
11856 KB |
Output is correct |
18 |
Correct |
20 ms |
11716 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
541 ms |
35416 KB |
Output is correct |
2 |
Correct |
586 ms |
37976 KB |
Output is correct |
3 |
Correct |
543 ms |
38100 KB |
Output is correct |
4 |
Correct |
263 ms |
32444 KB |
Output is correct |
5 |
Correct |
394 ms |
34400 KB |
Output is correct |
6 |
Correct |
191 ms |
29112 KB |
Output is correct |
7 |
Correct |
534 ms |
37576 KB |
Output is correct |
8 |
Correct |
547 ms |
37832 KB |
Output is correct |
9 |
Correct |
536 ms |
36520 KB |
Output is correct |
10 |
Correct |
350 ms |
33464 KB |
Output is correct |
11 |
Correct |
212 ms |
31508 KB |
Output is correct |
12 |
Correct |
125 ms |
28072 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
541 ms |
35416 KB |
Output is correct |
2 |
Correct |
586 ms |
37976 KB |
Output is correct |
3 |
Correct |
543 ms |
38100 KB |
Output is correct |
4 |
Correct |
263 ms |
32444 KB |
Output is correct |
5 |
Correct |
394 ms |
34400 KB |
Output is correct |
6 |
Correct |
191 ms |
29112 KB |
Output is correct |
7 |
Correct |
534 ms |
37576 KB |
Output is correct |
8 |
Correct |
547 ms |
37832 KB |
Output is correct |
9 |
Correct |
536 ms |
36520 KB |
Output is correct |
10 |
Correct |
350 ms |
33464 KB |
Output is correct |
11 |
Correct |
212 ms |
31508 KB |
Output is correct |
12 |
Correct |
125 ms |
28072 KB |
Output is correct |
13 |
Correct |
581 ms |
38400 KB |
Output is correct |
14 |
Correct |
575 ms |
38468 KB |
Output is correct |
15 |
Correct |
536 ms |
38016 KB |
Output is correct |
16 |
Correct |
283 ms |
32612 KB |
Output is correct |
17 |
Correct |
401 ms |
34828 KB |
Output is correct |
18 |
Correct |
175 ms |
29224 KB |
Output is correct |
19 |
Correct |
618 ms |
38404 KB |
Output is correct |
20 |
Correct |
581 ms |
38496 KB |
Output is correct |
21 |
Correct |
600 ms |
37140 KB |
Output is correct |
22 |
Correct |
362 ms |
33424 KB |
Output is correct |
23 |
Correct |
214 ms |
31596 KB |
Output is correct |
24 |
Correct |
127 ms |
28068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
15 ms |
11212 KB |
Output is correct |
2 |
Correct |
15 ms |
11272 KB |
Output is correct |
3 |
Correct |
16 ms |
11212 KB |
Output is correct |
4 |
Correct |
15 ms |
11212 KB |
Output is correct |
5 |
Correct |
14 ms |
11284 KB |
Output is correct |
6 |
Correct |
14 ms |
11252 KB |
Output is correct |
7 |
Correct |
28 ms |
11980 KB |
Output is correct |
8 |
Correct |
29 ms |
11972 KB |
Output is correct |
9 |
Correct |
28 ms |
11980 KB |
Output is correct |
10 |
Correct |
24 ms |
11800 KB |
Output is correct |
11 |
Correct |
27 ms |
11980 KB |
Output is correct |
12 |
Correct |
21 ms |
11864 KB |
Output is correct |
13 |
Correct |
26 ms |
11972 KB |
Output is correct |
14 |
Correct |
27 ms |
12032 KB |
Output is correct |
15 |
Correct |
28 ms |
11980 KB |
Output is correct |
16 |
Correct |
24 ms |
11968 KB |
Output is correct |
17 |
Correct |
22 ms |
11856 KB |
Output is correct |
18 |
Correct |
20 ms |
11716 KB |
Output is correct |
19 |
Correct |
541 ms |
35416 KB |
Output is correct |
20 |
Correct |
586 ms |
37976 KB |
Output is correct |
21 |
Correct |
543 ms |
38100 KB |
Output is correct |
22 |
Correct |
263 ms |
32444 KB |
Output is correct |
23 |
Correct |
394 ms |
34400 KB |
Output is correct |
24 |
Correct |
191 ms |
29112 KB |
Output is correct |
25 |
Correct |
534 ms |
37576 KB |
Output is correct |
26 |
Correct |
547 ms |
37832 KB |
Output is correct |
27 |
Correct |
536 ms |
36520 KB |
Output is correct |
28 |
Correct |
350 ms |
33464 KB |
Output is correct |
29 |
Correct |
212 ms |
31508 KB |
Output is correct |
30 |
Correct |
125 ms |
28072 KB |
Output is correct |
31 |
Correct |
581 ms |
38400 KB |
Output is correct |
32 |
Correct |
575 ms |
38468 KB |
Output is correct |
33 |
Correct |
536 ms |
38016 KB |
Output is correct |
34 |
Correct |
283 ms |
32612 KB |
Output is correct |
35 |
Correct |
401 ms |
34828 KB |
Output is correct |
36 |
Correct |
175 ms |
29224 KB |
Output is correct |
37 |
Correct |
618 ms |
38404 KB |
Output is correct |
38 |
Correct |
581 ms |
38496 KB |
Output is correct |
39 |
Correct |
600 ms |
37140 KB |
Output is correct |
40 |
Correct |
362 ms |
33424 KB |
Output is correct |
41 |
Correct |
214 ms |
31596 KB |
Output is correct |
42 |
Correct |
127 ms |
28068 KB |
Output is correct |
43 |
Runtime error |
189 ms |
30960 KB |
Execution killed with signal 11 |
44 |
Halted |
0 ms |
0 KB |
- |