// In the name of the God
#include <bits/stdc++.h>
#define ll long long
// #define int long long
#define pb push_back
#define F first
#define S second
#define mp make_pair
#define pii pair <int, int>
#define smin(x, y) (x) = min((x), (y))
#define smax(x, y) (x) = max((x), (y))
#define all(x) (x).begin(), (x).end()
using namespace std;
const int inf = 1e9+7;
const int mod = 998244353;
const int maxn = 1e5+5;
int n, q, ans[maxn];
vector <vector <int> > fen[2];
vector <int> a;
vector <pair <int, pii> > vec;
vector <pair <pii, pii> > qs;
void upd3(int i, int j) {
// cout << i << ' ' << j << ' ' << fen[0][i-1].size() << '\n';
for (j = fen[0][i-1].size()-j; j <= fen[0][i-1].size(); j += j&-j) {
// assert(j < 0);
fen[1][i-1][j-1]++;
}
}
void upd1(int i, int x) {
for (i = fen[0].size()-i; i <= fen[0].size(); i += i&-i) fen[0][i-1].pb(x);
}
void upd2(int i, int x) {
// cout << x << "DD\n";
for (i = fen[0].size()-i; i <= fen[0].size(); i += i&-i) {
int j = lower_bound(all(fen[0][i-1]), x)-fen[0][i-1].begin();
upd3(i, j);
}
}
int get1(int i, int j) {
int ans = 0;
for (j = fen[0][i-1].size()-j; j; j -= j&-j) ans += fen[1][i-1][j-1];
return ans;
}
int get(int i, int x) {
int ans = 0;
for (i = fen[0].size()-i; i; i -= i&-i) {
int j = lower_bound(all(fen[0][i-1]), x)-fen[0][i-1].begin();
ans += get1(i, j);
}
return ans;
}
int32_t main() {
ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
cin >> n >> q;
for (int i = 0; i < n; i++) {
int s, t; cin >> s >> t;
a.pb(s);
vec.pb(mp(s+t, mp(s, t)));
}
sort(all(a)), sort(all(vec));
a.resize(unique(all(a))-a.begin());
fen[0].resize(a.size());
fen[1].resize(a.size());
for (int i = 0; i < n; i++) {
int j = lower_bound(all(a), vec[i].S.F)-a.begin();
upd1(j, vec[i].S.S);
}
for (int i = 0; i < fen[0].size(); i++) {
sort(all(fen[0][i]));
fen[0][i].resize(unique(all(fen[0][i]))-fen[0][i].begin());
fen[1][i].resize(fen[0][i].size());
}
for (int i = 0; i < q; i++) {
int x, y, z; cin >> x >> y >> z;
qs.pb(mp(mp(z, x), mp(y, i)));
}
sort(all(qs));
for (int i = q-1; i >= 0; i--) {
while (vec.size() and vec.back().F >= qs[i].F.F) {
int j = lower_bound(all(a), vec.back().S.F)-a.begin();
upd2(j, vec.back().S.S);
vec.pop_back();
}
int j = lower_bound(all(a), qs[i].F.S)-a.begin();
ans[qs[i].S.S] = get(j, qs[i].S.F);
}
for (int i = 0; i < q; i++) cout << ans[i] << '\n';
return 0;
}
Compilation message
examination.cpp: In function 'void upd3(int, int)':
examination.cpp:27:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
27 | for (j = fen[0][i-1].size()-j; j <= fen[0][i-1].size(); j += j&-j) {
| ~~^~~~~~~~~~~~~~~~~~~~~
examination.cpp: In function 'void upd1(int, int)':
examination.cpp:34:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
34 | for (i = fen[0].size()-i; i <= fen[0].size(); i += i&-i) fen[0][i-1].pb(x);
| ~~^~~~~~~~~~~~~~~~
examination.cpp: In function 'void upd2(int, int)':
examination.cpp:38:33: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
38 | for (i = fen[0].size()-i; i <= fen[0].size(); i += i&-i) {
| ~~^~~~~~~~~~~~~~~~
examination.cpp: In function 'int32_t main()':
examination.cpp:75:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::vector<int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
75 | for (int i = 0; i < fen[0].size(); i++) {
| ~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
6 ms |
1144 KB |
Output is correct |
8 |
Correct |
6 ms |
1116 KB |
Output is correct |
9 |
Correct |
7 ms |
992 KB |
Output is correct |
10 |
Correct |
6 ms |
1116 KB |
Output is correct |
11 |
Correct |
3 ms |
604 KB |
Output is correct |
12 |
Correct |
2 ms |
604 KB |
Output is correct |
13 |
Correct |
6 ms |
1116 KB |
Output is correct |
14 |
Correct |
5 ms |
1368 KB |
Output is correct |
15 |
Correct |
5 ms |
1112 KB |
Output is correct |
16 |
Correct |
2 ms |
604 KB |
Output is correct |
17 |
Correct |
3 ms |
1116 KB |
Output is correct |
18 |
Correct |
2 ms |
616 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
263 ms |
20516 KB |
Output is correct |
2 |
Correct |
269 ms |
20488 KB |
Output is correct |
3 |
Correct |
281 ms |
20496 KB |
Output is correct |
4 |
Correct |
147 ms |
17572 KB |
Output is correct |
5 |
Correct |
99 ms |
8988 KB |
Output is correct |
6 |
Correct |
58 ms |
7860 KB |
Output is correct |
7 |
Correct |
286 ms |
20440 KB |
Output is correct |
8 |
Correct |
261 ms |
20564 KB |
Output is correct |
9 |
Correct |
249 ms |
20464 KB |
Output is correct |
10 |
Correct |
72 ms |
7640 KB |
Output is correct |
11 |
Correct |
103 ms |
16996 KB |
Output is correct |
12 |
Correct |
43 ms |
6516 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
263 ms |
20516 KB |
Output is correct |
2 |
Correct |
269 ms |
20488 KB |
Output is correct |
3 |
Correct |
281 ms |
20496 KB |
Output is correct |
4 |
Correct |
147 ms |
17572 KB |
Output is correct |
5 |
Correct |
99 ms |
8988 KB |
Output is correct |
6 |
Correct |
58 ms |
7860 KB |
Output is correct |
7 |
Correct |
286 ms |
20440 KB |
Output is correct |
8 |
Correct |
261 ms |
20564 KB |
Output is correct |
9 |
Correct |
249 ms |
20464 KB |
Output is correct |
10 |
Correct |
72 ms |
7640 KB |
Output is correct |
11 |
Correct |
103 ms |
16996 KB |
Output is correct |
12 |
Correct |
43 ms |
6516 KB |
Output is correct |
13 |
Correct |
352 ms |
20940 KB |
Output is correct |
14 |
Correct |
328 ms |
20896 KB |
Output is correct |
15 |
Correct |
288 ms |
20484 KB |
Output is correct |
16 |
Correct |
147 ms |
17972 KB |
Output is correct |
17 |
Correct |
117 ms |
9428 KB |
Output is correct |
18 |
Correct |
58 ms |
7688 KB |
Output is correct |
19 |
Correct |
335 ms |
20928 KB |
Output is correct |
20 |
Correct |
336 ms |
20860 KB |
Output is correct |
21 |
Correct |
309 ms |
20720 KB |
Output is correct |
22 |
Correct |
71 ms |
7636 KB |
Output is correct |
23 |
Correct |
120 ms |
17116 KB |
Output is correct |
24 |
Correct |
43 ms |
6876 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
1 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
604 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
6 ms |
1144 KB |
Output is correct |
8 |
Correct |
6 ms |
1116 KB |
Output is correct |
9 |
Correct |
7 ms |
992 KB |
Output is correct |
10 |
Correct |
6 ms |
1116 KB |
Output is correct |
11 |
Correct |
3 ms |
604 KB |
Output is correct |
12 |
Correct |
2 ms |
604 KB |
Output is correct |
13 |
Correct |
6 ms |
1116 KB |
Output is correct |
14 |
Correct |
5 ms |
1368 KB |
Output is correct |
15 |
Correct |
5 ms |
1112 KB |
Output is correct |
16 |
Correct |
2 ms |
604 KB |
Output is correct |
17 |
Correct |
3 ms |
1116 KB |
Output is correct |
18 |
Correct |
2 ms |
616 KB |
Output is correct |
19 |
Correct |
263 ms |
20516 KB |
Output is correct |
20 |
Correct |
269 ms |
20488 KB |
Output is correct |
21 |
Correct |
281 ms |
20496 KB |
Output is correct |
22 |
Correct |
147 ms |
17572 KB |
Output is correct |
23 |
Correct |
99 ms |
8988 KB |
Output is correct |
24 |
Correct |
58 ms |
7860 KB |
Output is correct |
25 |
Correct |
286 ms |
20440 KB |
Output is correct |
26 |
Correct |
261 ms |
20564 KB |
Output is correct |
27 |
Correct |
249 ms |
20464 KB |
Output is correct |
28 |
Correct |
72 ms |
7640 KB |
Output is correct |
29 |
Correct |
103 ms |
16996 KB |
Output is correct |
30 |
Correct |
43 ms |
6516 KB |
Output is correct |
31 |
Correct |
352 ms |
20940 KB |
Output is correct |
32 |
Correct |
328 ms |
20896 KB |
Output is correct |
33 |
Correct |
288 ms |
20484 KB |
Output is correct |
34 |
Correct |
147 ms |
17972 KB |
Output is correct |
35 |
Correct |
117 ms |
9428 KB |
Output is correct |
36 |
Correct |
58 ms |
7688 KB |
Output is correct |
37 |
Correct |
335 ms |
20928 KB |
Output is correct |
38 |
Correct |
336 ms |
20860 KB |
Output is correct |
39 |
Correct |
309 ms |
20720 KB |
Output is correct |
40 |
Correct |
71 ms |
7636 KB |
Output is correct |
41 |
Correct |
120 ms |
17116 KB |
Output is correct |
42 |
Correct |
43 ms |
6876 KB |
Output is correct |
43 |
Correct |
395 ms |
26944 KB |
Output is correct |
44 |
Correct |
365 ms |
26896 KB |
Output is correct |
45 |
Correct |
363 ms |
26584 KB |
Output is correct |
46 |
Correct |
174 ms |
23052 KB |
Output is correct |
47 |
Correct |
125 ms |
10720 KB |
Output is correct |
48 |
Correct |
65 ms |
7588 KB |
Output is correct |
49 |
Correct |
350 ms |
26536 KB |
Output is correct |
50 |
Correct |
352 ms |
26648 KB |
Output is correct |
51 |
Correct |
314 ms |
26496 KB |
Output is correct |
52 |
Correct |
87 ms |
9608 KB |
Output is correct |
53 |
Correct |
143 ms |
21720 KB |
Output is correct |