#include<bits/stdc++.h>
#define int long long
#define ii pair<int,int>
#define all(x) x.begin(), x.end()
using namespace std;
const int maxn = 6e5 + 4;
int n, m, q;
int ans[maxn];
vector<int> f[maxn], fake[maxn];
array<int, 4> qr[maxn], a[maxn];
vector<int> nen;
int comp(int x)
{
return upper_bound(all(nen), x) - nen.begin();
}
void fupd(int x, int y)
{
for (; x > 0; x -= x & -x)
fake[x].emplace_back(y);
}
void fqry(int x, int y)
{
for (; x <= nen.size(); x += x & -x)
fake[x].emplace_back(y);
}
void build()
{
for (int i = 1; i <= nen.size(); i++)
{
if (fake[i].empty()) continue;
sort(all(fake[i]));
fake[i].resize(unique(all(fake[i])) - fake[i].begin());
f[i].resize(fake[i].size() + 1, 0);
}
}
void upd(int x, int y)
{
for (; x > 0; x -= x & -x)
for (int i = upper_bound(all(fake[x]), y) - fake[x].begin(); i > 0; i -= i & -i)
f[x][i]++;
}
int qry(int x, int y)
{
int ans = 0;
for (; x <= nen.size(); x += x & -x)
for (int i = upper_bound(all(fake[x]), y) - fake[x].begin(); i <= fake[x].size(); i += i & -i)
ans += f[x][i];
return ans;
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
cin >> n >> q;
for (int i = 1; i <= n; i++)
{
cin >> a[i][0] >> a[i][1], a[i][2] = a[i][0] + a[i][1];
for (int j = 0; j < 3; j++)
nen.emplace_back(a[i][0]),
nen.emplace_back(a[i][1]),
nen.emplace_back(a[i][2]);
}
for (int i = 1; i <= q; i++)
{
cin >> qr[i][0] >> qr[i][1] >> qr[i][2];
qr[i][3] = i;
for (int j = 0; j < 3; j++)
nen.emplace_back(qr[i][j]);
}
sort(all(nen));
nen.resize(unique(all(nen)) - nen.begin());
sort(all(nen));
nen.resize(unique(all(nen)) - nen.begin());
for (int i = 1; i <= n; i++)
{
for (int j = 0; j < 3; j++)
a[i][j] = comp(a[i][j]);
fupd(a[i][1], a[i][2]);
}
for (int i = 1; i <= q; i++)
{
auto &[u1, u2, v1, v2] = qr[i];
u1 = comp(u1);
u2 = comp(u2);
v1 = comp(v1);
fqry(u2, v1);
}
build();
sort(a + 1, a + n + 1, greater<>());
sort(qr + 1, qr + q + 1, greater<>());
for (int i = 1, j = 1; i <= q; i++)
{
while (j <= n && a[j][0] >= qr[i][0])
upd(a[j][1], a[j][2]),
j++;
ans[qr[i][3]] = qry(qr[i][1], qr[i][2]);
}
for (int i = 1; i <= q; i++)
cout << ans[i] << "\n";
}
Compilation message
examination.cpp: In function 'void fqry(long long int, long long int)':
examination.cpp:27:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
27 | for (; x <= nen.size(); x += x & -x)
| ~~^~~~~~~~~~~~~
examination.cpp: In function 'void build()':
examination.cpp:34:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | for (int i = 1; i <= nen.size(); i++)
| ~~^~~~~~~~~~~~~
examination.cpp: In function 'long long int qry(long long int, long long int)':
examination.cpp:53:14: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
53 | for (; x <= nen.size(); x += x & -x)
| ~~^~~~~~~~~~~~~
examination.cpp:54:72: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | for (int i = upper_bound(all(fake[x]), y) - fake[x].begin(); i <= fake[x].size(); i += i & -i)
| ~~^~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
28764 KB |
Output is correct |
2 |
Correct |
11 ms |
28508 KB |
Output is correct |
3 |
Correct |
12 ms |
28660 KB |
Output is correct |
4 |
Correct |
12 ms |
28504 KB |
Output is correct |
5 |
Correct |
11 ms |
28508 KB |
Output is correct |
6 |
Correct |
11 ms |
28604 KB |
Output is correct |
7 |
Correct |
25 ms |
30312 KB |
Output is correct |
8 |
Correct |
23 ms |
30428 KB |
Output is correct |
9 |
Correct |
22 ms |
30448 KB |
Output is correct |
10 |
Correct |
20 ms |
29912 KB |
Output is correct |
11 |
Correct |
21 ms |
30172 KB |
Output is correct |
12 |
Correct |
21 ms |
29404 KB |
Output is correct |
13 |
Correct |
25 ms |
30172 KB |
Output is correct |
14 |
Correct |
29 ms |
30172 KB |
Output is correct |
15 |
Correct |
21 ms |
30172 KB |
Output is correct |
16 |
Correct |
19 ms |
29912 KB |
Output is correct |
17 |
Correct |
19 ms |
29916 KB |
Output is correct |
18 |
Correct |
14 ms |
29248 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
425 ms |
76888 KB |
Output is correct |
2 |
Correct |
385 ms |
77212 KB |
Output is correct |
3 |
Correct |
401 ms |
77156 KB |
Output is correct |
4 |
Correct |
227 ms |
65540 KB |
Output is correct |
5 |
Correct |
329 ms |
74092 KB |
Output is correct |
6 |
Correct |
144 ms |
52884 KB |
Output is correct |
7 |
Correct |
392 ms |
77056 KB |
Output is correct |
8 |
Correct |
405 ms |
77056 KB |
Output is correct |
9 |
Correct |
383 ms |
75668 KB |
Output is correct |
10 |
Correct |
288 ms |
73316 KB |
Output is correct |
11 |
Correct |
210 ms |
65180 KB |
Output is correct |
12 |
Correct |
95 ms |
50696 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
425 ms |
76888 KB |
Output is correct |
2 |
Correct |
385 ms |
77212 KB |
Output is correct |
3 |
Correct |
401 ms |
77156 KB |
Output is correct |
4 |
Correct |
227 ms |
65540 KB |
Output is correct |
5 |
Correct |
329 ms |
74092 KB |
Output is correct |
6 |
Correct |
144 ms |
52884 KB |
Output is correct |
7 |
Correct |
392 ms |
77056 KB |
Output is correct |
8 |
Correct |
405 ms |
77056 KB |
Output is correct |
9 |
Correct |
383 ms |
75668 KB |
Output is correct |
10 |
Correct |
288 ms |
73316 KB |
Output is correct |
11 |
Correct |
210 ms |
65180 KB |
Output is correct |
12 |
Correct |
95 ms |
50696 KB |
Output is correct |
13 |
Correct |
594 ms |
84100 KB |
Output is correct |
14 |
Correct |
609 ms |
83612 KB |
Output is correct |
15 |
Correct |
452 ms |
77220 KB |
Output is correct |
16 |
Correct |
464 ms |
73632 KB |
Output is correct |
17 |
Correct |
480 ms |
79772 KB |
Output is correct |
18 |
Correct |
131 ms |
53188 KB |
Output is correct |
19 |
Correct |
640 ms |
83872 KB |
Output is correct |
20 |
Correct |
651 ms |
83992 KB |
Output is correct |
21 |
Correct |
667 ms |
83388 KB |
Output is correct |
22 |
Correct |
319 ms |
73088 KB |
Output is correct |
23 |
Correct |
236 ms |
65132 KB |
Output is correct |
24 |
Correct |
111 ms |
50584 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
14 ms |
28764 KB |
Output is correct |
2 |
Correct |
11 ms |
28508 KB |
Output is correct |
3 |
Correct |
12 ms |
28660 KB |
Output is correct |
4 |
Correct |
12 ms |
28504 KB |
Output is correct |
5 |
Correct |
11 ms |
28508 KB |
Output is correct |
6 |
Correct |
11 ms |
28604 KB |
Output is correct |
7 |
Correct |
25 ms |
30312 KB |
Output is correct |
8 |
Correct |
23 ms |
30428 KB |
Output is correct |
9 |
Correct |
22 ms |
30448 KB |
Output is correct |
10 |
Correct |
20 ms |
29912 KB |
Output is correct |
11 |
Correct |
21 ms |
30172 KB |
Output is correct |
12 |
Correct |
21 ms |
29404 KB |
Output is correct |
13 |
Correct |
25 ms |
30172 KB |
Output is correct |
14 |
Correct |
29 ms |
30172 KB |
Output is correct |
15 |
Correct |
21 ms |
30172 KB |
Output is correct |
16 |
Correct |
19 ms |
29912 KB |
Output is correct |
17 |
Correct |
19 ms |
29916 KB |
Output is correct |
18 |
Correct |
14 ms |
29248 KB |
Output is correct |
19 |
Correct |
425 ms |
76888 KB |
Output is correct |
20 |
Correct |
385 ms |
77212 KB |
Output is correct |
21 |
Correct |
401 ms |
77156 KB |
Output is correct |
22 |
Correct |
227 ms |
65540 KB |
Output is correct |
23 |
Correct |
329 ms |
74092 KB |
Output is correct |
24 |
Correct |
144 ms |
52884 KB |
Output is correct |
25 |
Correct |
392 ms |
77056 KB |
Output is correct |
26 |
Correct |
405 ms |
77056 KB |
Output is correct |
27 |
Correct |
383 ms |
75668 KB |
Output is correct |
28 |
Correct |
288 ms |
73316 KB |
Output is correct |
29 |
Correct |
210 ms |
65180 KB |
Output is correct |
30 |
Correct |
95 ms |
50696 KB |
Output is correct |
31 |
Correct |
594 ms |
84100 KB |
Output is correct |
32 |
Correct |
609 ms |
83612 KB |
Output is correct |
33 |
Correct |
452 ms |
77220 KB |
Output is correct |
34 |
Correct |
464 ms |
73632 KB |
Output is correct |
35 |
Correct |
480 ms |
79772 KB |
Output is correct |
36 |
Correct |
131 ms |
53188 KB |
Output is correct |
37 |
Correct |
640 ms |
83872 KB |
Output is correct |
38 |
Correct |
651 ms |
83992 KB |
Output is correct |
39 |
Correct |
667 ms |
83388 KB |
Output is correct |
40 |
Correct |
319 ms |
73088 KB |
Output is correct |
41 |
Correct |
236 ms |
65132 KB |
Output is correct |
42 |
Correct |
111 ms |
50584 KB |
Output is correct |
43 |
Correct |
829 ms |
96632 KB |
Output is correct |
44 |
Correct |
808 ms |
96696 KB |
Output is correct |
45 |
Correct |
813 ms |
97604 KB |
Output is correct |
46 |
Correct |
628 ms |
82616 KB |
Output is correct |
47 |
Correct |
631 ms |
94112 KB |
Output is correct |
48 |
Correct |
154 ms |
53728 KB |
Output is correct |
49 |
Correct |
768 ms |
96548 KB |
Output is correct |
50 |
Correct |
770 ms |
97952 KB |
Output is correct |
51 |
Correct |
772 ms |
99188 KB |
Output is correct |
52 |
Correct |
542 ms |
92060 KB |
Output is correct |
53 |
Correct |
235 ms |
66980 KB |
Output is correct |