#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define OPT ios_base::sync_with_stdio(0); \
cin.tie(0); \
cout.tie(0)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define endl "\n"
#define all(v) v.begin(), v.end()
#define mpr make_pair
#define pb push_back
#define ts to_string
#define fi first
#define se second
#define inf 0x3F3F3F3F
#define bpc __builtin_popcount
#define print(v) for(int i = 0; i < v.size(); i++) \
cout << v[i] << " "; \
cout<<endl;
struct MTree
{
int size;
vector<vector<int>> tree;
void init(int n)
{
size = 1;
while (size < n) size *= 2;
tree.resize(2*size);
}
void merge(vector<int> &a, vector<int> &b, vector<int> &f)
{
int i = 0;
int j = 0;
while (i < a.size() && j < b.size())
{
if (a[i] <= b[j])
{
f.pb(a[i]);
i++;
}
else
{
f.pb(b[j]);
j++;
}
}
while (i < a.size())
{
f.pb(a[i]);
i++;
}
while (j < b.size())
{
f.pb(b[j]);
j++;
}
}
void _build(int l, int r, int x, vector<pii> &arr)
{
if (l + 1 == r)
{
if (l >= arr.size()) tree[x].pb(inf);
else tree[x].pb(arr[l].se);
return;
}
int mid = (l + r) >> 1;
_build(l, mid, 2*x+1, arr);
_build(mid, r, 2*x+2, arr);
merge(tree[2*x+1], tree[2*x+2], tree[x]);
}
void build(vector<pii> &arr)
{
_build(0, size, 0, arr);
}
int get(int lx, int rx, int l, int r, int x, int val)
{
if (l >= rx || r <= lx) return 0;
if (l >= lx && r <= rx)
{
return lower_bound(tree[x].begin(), tree[x].end(), val) - tree[x].begin();
}
int mid = (l + r) >> 1;
return get(lx, rx, l, mid, 2*x+1, val) + get(lx, rx, mid, r, 2*x+2, val);
}
int get(int l, int r, int val)
{
return get(l, r, 0, size, 0, val);
}
};
struct MergeTree
{
int size;
vector<vector<pii>> tree;
vector<MTree> sub;
void init(int &n)
{
size = 1;
while (size < n) size *= 2;
tree.resize(2*size);
sub.resize(2*size);
}
void merge(vector<pii> &a, vector<pii> &b, vector<pii> &f)
{
int i = 0;
int j = 0;
while (i < a.size() && j < b.size())
{
if (a[i].fi <= b[j].fi)
{
f.pb(a[i]);
i++;
}
else
{
f.pb(b[j]);
j++;
}
}
while (i < a.size())
{
f.pb(a[i]);
i++;
}
while (j < b.size())
{
f.pb(b[j]);
j++;
}
}
void _build(int l, int r, int x, vector<pii> &arr)
{
if (l + 1 == r)
{
if (l >= arr.size())
{
tree[x].pb(mpr(inf, inf));
sub[x].init(tree[x].size());
sub[x].build(tree[x]);
}
else
{
tree[x].pb(arr[l]);
sub[x].init(tree[x].size());
sub[x].build(tree[x]);
}
return;
}
int mid = (l + r) >> 1;
_build(l, mid, 2*x+1, arr);
_build(mid, r, 2*x+2, arr);
merge(tree[2*x+1], tree[2*x+2], tree[x]);
sub[x].init(tree[x].size());
sub[x].build(tree[x]);
}
void build(vector<pii> &arr)
{
_build(0, size, 0, arr);
}
int get(int lx, int rx, int l, int r, int x, pii val)
{
if (l >= rx || r <= lx) return 0;
if (l >= lx && r <= rx)
{
int ind = lower_bound(tree[x].begin(), tree[x].end(), mpr(val.fi, 0)) - tree[x].begin();
int temp = sub[x].get(ind, tree[x].size(), val.se) + ind;
return temp;
}
int mid = (l + r) >> 1;
return get(lx, rx, l, mid, 2*x+1, val) + get(lx, rx, mid, r, 2*x+2, val);
}
int get(int l, int r, pii val)
{
return get(l, r, 0, size, 0, val);
}
};
int n;
int main()
{
int q;
cin >> n >> q;
vector<pii> v(n);
for (int i = 0; i < n; i++)
{
cin >> v[i].fi >> v[i].se;
}
sort(all(v));
vector<pii> arr;
for (int i = 0; i < n; i++)
{
arr.pb(mpr(v[i].se, v[i].fi + v[i].se));
}
MergeTree st;
st.init(n);
st.build(arr);
while (q--)
{
int a, b, c;
cin >> a >> b >> c;
int ind = lower_bound(v.begin(), v.end(), mpr(a, b)) - v.begin();
int rem = n - ind;
rem -= st.get(ind, n, mpr(b, c));
cout << rem << endl;
}
}
Compilation message
examination.cpp: In member function 'void MTree::merge(std::vector<int>&, std::vector<int>&, std::vector<int>&)':
examination.cpp:45:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | while (i < a.size() && j < b.size())
| ~~^~~~~~~~~~
examination.cpp:45:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
45 | while (i < a.size() && j < b.size())
| ~~^~~~~~~~~~
examination.cpp:59:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
59 | while (i < a.size())
| ~~^~~~~~~~~~
examination.cpp:65:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
65 | while (j < b.size())
| ~~^~~~~~~~~~
examination.cpp: In member function 'void MTree::_build(int, int, int, std::vector<std::pair<int, int> >&)':
examination.cpp:76:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
76 | if (l >= arr.size()) tree[x].pb(inf);
| ~~^~~~~~~~~~~~~
examination.cpp: In member function 'void MergeTree::merge(std::vector<std::pair<int, int> >&, std::vector<std::pair<int, int> >&, std::vector<std::pair<int, int> >&)':
examination.cpp:135:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
135 | while (i < a.size() && j < b.size())
| ~~^~~~~~~~~~
examination.cpp:135:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
135 | while (i < a.size() && j < b.size())
| ~~^~~~~~~~~~
examination.cpp:149:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
149 | while (i < a.size())
| ~~^~~~~~~~~~
examination.cpp:155:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
155 | while (j < b.size())
| ~~^~~~~~~~~~
examination.cpp: In member function 'void MergeTree::_build(int, int, int, std::vector<std::pair<int, int> >&)':
examination.cpp:166:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
166 | if (l >= arr.size())
| ~~^~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
31 ms |
7856 KB |
Output is correct |
8 |
Correct |
32 ms |
7852 KB |
Output is correct |
9 |
Correct |
29 ms |
7764 KB |
Output is correct |
10 |
Correct |
28 ms |
7852 KB |
Output is correct |
11 |
Correct |
27 ms |
7868 KB |
Output is correct |
12 |
Correct |
24 ms |
7736 KB |
Output is correct |
13 |
Correct |
30 ms |
7892 KB |
Output is correct |
14 |
Correct |
30 ms |
7988 KB |
Output is correct |
15 |
Correct |
29 ms |
7976 KB |
Output is correct |
16 |
Correct |
25 ms |
8012 KB |
Output is correct |
17 |
Correct |
24 ms |
7892 KB |
Output is correct |
18 |
Correct |
21 ms |
7896 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1659 ms |
349884 KB |
Output is correct |
2 |
Correct |
1974 ms |
349744 KB |
Output is correct |
3 |
Correct |
1793 ms |
349732 KB |
Output is correct |
4 |
Correct |
1386 ms |
350120 KB |
Output is correct |
5 |
Correct |
1282 ms |
349740 KB |
Output is correct |
6 |
Correct |
1128 ms |
349720 KB |
Output is correct |
7 |
Correct |
1599 ms |
349872 KB |
Output is correct |
8 |
Correct |
1460 ms |
349768 KB |
Output is correct |
9 |
Correct |
1463 ms |
349816 KB |
Output is correct |
10 |
Correct |
1030 ms |
349632 KB |
Output is correct |
11 |
Correct |
1084 ms |
349628 KB |
Output is correct |
12 |
Correct |
1022 ms |
349504 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1659 ms |
349884 KB |
Output is correct |
2 |
Correct |
1974 ms |
349744 KB |
Output is correct |
3 |
Correct |
1793 ms |
349732 KB |
Output is correct |
4 |
Correct |
1386 ms |
350120 KB |
Output is correct |
5 |
Correct |
1282 ms |
349740 KB |
Output is correct |
6 |
Correct |
1128 ms |
349720 KB |
Output is correct |
7 |
Correct |
1599 ms |
349872 KB |
Output is correct |
8 |
Correct |
1460 ms |
349768 KB |
Output is correct |
9 |
Correct |
1463 ms |
349816 KB |
Output is correct |
10 |
Correct |
1030 ms |
349632 KB |
Output is correct |
11 |
Correct |
1084 ms |
349628 KB |
Output is correct |
12 |
Correct |
1022 ms |
349504 KB |
Output is correct |
13 |
Correct |
1677 ms |
349880 KB |
Output is correct |
14 |
Correct |
1610 ms |
352652 KB |
Output is correct |
15 |
Correct |
1558 ms |
352408 KB |
Output is correct |
16 |
Correct |
1463 ms |
351912 KB |
Output is correct |
17 |
Correct |
1327 ms |
351896 KB |
Output is correct |
18 |
Correct |
1097 ms |
350748 KB |
Output is correct |
19 |
Correct |
1670 ms |
352792 KB |
Output is correct |
20 |
Correct |
1654 ms |
352768 KB |
Output is correct |
21 |
Correct |
1682 ms |
352700 KB |
Output is correct |
22 |
Correct |
1018 ms |
351396 KB |
Output is correct |
23 |
Correct |
1082 ms |
351296 KB |
Output is correct |
24 |
Correct |
928 ms |
350428 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
31 ms |
7856 KB |
Output is correct |
8 |
Correct |
32 ms |
7852 KB |
Output is correct |
9 |
Correct |
29 ms |
7764 KB |
Output is correct |
10 |
Correct |
28 ms |
7852 KB |
Output is correct |
11 |
Correct |
27 ms |
7868 KB |
Output is correct |
12 |
Correct |
24 ms |
7736 KB |
Output is correct |
13 |
Correct |
30 ms |
7892 KB |
Output is correct |
14 |
Correct |
30 ms |
7988 KB |
Output is correct |
15 |
Correct |
29 ms |
7976 KB |
Output is correct |
16 |
Correct |
25 ms |
8012 KB |
Output is correct |
17 |
Correct |
24 ms |
7892 KB |
Output is correct |
18 |
Correct |
21 ms |
7896 KB |
Output is correct |
19 |
Correct |
1659 ms |
349884 KB |
Output is correct |
20 |
Correct |
1974 ms |
349744 KB |
Output is correct |
21 |
Correct |
1793 ms |
349732 KB |
Output is correct |
22 |
Correct |
1386 ms |
350120 KB |
Output is correct |
23 |
Correct |
1282 ms |
349740 KB |
Output is correct |
24 |
Correct |
1128 ms |
349720 KB |
Output is correct |
25 |
Correct |
1599 ms |
349872 KB |
Output is correct |
26 |
Correct |
1460 ms |
349768 KB |
Output is correct |
27 |
Correct |
1463 ms |
349816 KB |
Output is correct |
28 |
Correct |
1030 ms |
349632 KB |
Output is correct |
29 |
Correct |
1084 ms |
349628 KB |
Output is correct |
30 |
Correct |
1022 ms |
349504 KB |
Output is correct |
31 |
Correct |
1677 ms |
349880 KB |
Output is correct |
32 |
Correct |
1610 ms |
352652 KB |
Output is correct |
33 |
Correct |
1558 ms |
352408 KB |
Output is correct |
34 |
Correct |
1463 ms |
351912 KB |
Output is correct |
35 |
Correct |
1327 ms |
351896 KB |
Output is correct |
36 |
Correct |
1097 ms |
350748 KB |
Output is correct |
37 |
Correct |
1670 ms |
352792 KB |
Output is correct |
38 |
Correct |
1654 ms |
352768 KB |
Output is correct |
39 |
Correct |
1682 ms |
352700 KB |
Output is correct |
40 |
Correct |
1018 ms |
351396 KB |
Output is correct |
41 |
Correct |
1082 ms |
351296 KB |
Output is correct |
42 |
Correct |
928 ms |
350428 KB |
Output is correct |
43 |
Correct |
1760 ms |
354652 KB |
Output is correct |
44 |
Correct |
1720 ms |
354732 KB |
Output is correct |
45 |
Correct |
1835 ms |
354568 KB |
Output is correct |
46 |
Correct |
1526 ms |
353020 KB |
Output is correct |
47 |
Correct |
1453 ms |
352980 KB |
Output is correct |
48 |
Correct |
1137 ms |
350620 KB |
Output is correct |
49 |
Correct |
1691 ms |
354712 KB |
Output is correct |
50 |
Correct |
1744 ms |
354672 KB |
Output is correct |
51 |
Correct |
1759 ms |
354464 KB |
Output is correct |
52 |
Correct |
1366 ms |
352992 KB |
Output is correct |
53 |
Correct |
1174 ms |
352148 KB |
Output is correct |