#include "bits/stdc++.h"
using namespace std;
#define fi first
#define se second
#define ll long long
#define dbg(v) cerr<<#v<<" = "<<v<<'\n'
#define vi vector<int>
#define vl vector <ll>
#define pii pair<int,int>
#define vii vector < pii >
#define mp make_pair
#define db long double
#define pb push_back
#define all(s) s.begin(),s.end()
template < class P , class Q > ostream& operator<<(ostream& stream, pair < P , Q > v){ stream << "(" << v.fi << ',' << v.se << ")"; return stream;}
template < class T > ostream& operator<<(ostream& stream, const vector<T> v){ stream << "[ "; for (int i=0; i<(int)v.size(); i++) stream << v[i] << " "; stream << "]"; return stream;}
template < class T > T smin(T &a,T b) {if (a > b) a = b;return a;}
template < class T > T smax(T &a,T b) {if (a < b) a = b;return a;}
const int N = 1e5 + 5;
const int oo = 1e9;
int a[N];
int b[N];
int c[N];
int d[N];
int e[N];
void Upd(int &x) {
x = oo - x;
}
vi V[N * 5];
vi T[N * 5];
vi Q[N * 5];
vi R[N * 5];
int answer[N];
int main(void) {
int n,q;
ios_base :: sync_with_stdio(0);
vi w,W;
cin>>n>>q;
for (int i = 1;i <= n;++i)
cin>>a[i]>>b[i],Upd(a[i]),Upd(b[i]),w.pb(a[i]),w.pb(b[i]),W.pb(a[i] + b[i]);
for (int i = 1;i <= q;++i)
cin>>c[i]>>d[i]>>e[i],e[i] = 2 * oo - e[i],Upd(c[i]),Upd(d[i]),w.pb(c[i]),w.pb(d[i]),W.pb(e[i]);
sort(all(w));
sort(all(W));
w.resize(unique(all(w)) - w.begin());
W.resize(unique(all(W)) - W.begin());
for (int i = 1;i <= n;++i) {
R[lower_bound(all(W),a[i] + b[i]) - W.begin() + 1].pb(i);
a[i] = lower_bound(all(w),a[i]) - w.begin() + 1;
b[i] = lower_bound(all(w),b[i]) - w.begin() + 1;
}
for (int i = 1;i <= q;++i) {
c[i] = lower_bound(all(w),c[i]) - w.begin() + 1;
d[i] = lower_bound(all(w),d[i]) - w.begin() + 1;
e[i] = lower_bound(all(W),e[i]) - W.begin() + 1;
Q[e[i]].pb(i);
}
const int SZ1 = w.size();
const int SZ2 = W.size();
for (int i = 1;i <= n;++i) {
for (int j = a[i];j <= SZ1;j += j&(-j))
V[j].pb(b[i]);
}
for (int i = 1;i <= SZ1;++i) {
sort(all(V[i]));
V[i].resize(unique(all(V[i])) - V[i].begin());
T[i].resize(V[i].size() + 4);
}
auto upd = [&](int x,int y) {
for (int i = x;i <= SZ1;i += i&(-i)) {
const int sz = V[i].size();
for (int j = lower_bound(all(V[i]),y) - V[i].begin() + 1;j <= sz;j += j&(-j))
T[i][j] += 1;
}
};
auto query = [&](int x,int y) {
int ans = 0;
for (int i = x;i;i -= i&(-i)) {
const int sz = V[i].size();
for (int j = lower_bound(all(V[i]),y + 1) - V[i].begin();j;j -= j&(-j))
ans += T[i][j];
}
return ans;
};
for (int i = 1;i <= SZ2;++i) {
for (auto it : R[i])
upd(a[it],b[it]);
for (auto it : Q[i])
answer[it] = query(c[it],d[it]);
}
for (int i = 1;i <= q;++i)
cout << answer[i] << '\n';
return 0;
}
Compilation message
examination.cpp: In lambda function:
examination.cpp:79:17: warning: unused variable 'sz' [-Wunused-variable]
const int sz = V[i].size();
^~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
47360 KB |
Output is correct |
2 |
Correct |
49 ms |
47352 KB |
Output is correct |
3 |
Correct |
52 ms |
47352 KB |
Output is correct |
4 |
Correct |
43 ms |
47352 KB |
Output is correct |
5 |
Correct |
48 ms |
47368 KB |
Output is correct |
6 |
Correct |
46 ms |
47352 KB |
Output is correct |
7 |
Correct |
61 ms |
48504 KB |
Output is correct |
8 |
Correct |
68 ms |
48632 KB |
Output is correct |
9 |
Correct |
60 ms |
48504 KB |
Output is correct |
10 |
Correct |
61 ms |
48124 KB |
Output is correct |
11 |
Correct |
67 ms |
48120 KB |
Output is correct |
12 |
Correct |
52 ms |
47608 KB |
Output is correct |
13 |
Correct |
61 ms |
48376 KB |
Output is correct |
14 |
Correct |
70 ms |
48532 KB |
Output is correct |
15 |
Correct |
62 ms |
48376 KB |
Output is correct |
16 |
Correct |
55 ms |
47864 KB |
Output is correct |
17 |
Correct |
61 ms |
48248 KB |
Output is correct |
18 |
Correct |
55 ms |
47736 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
669 ms |
70144 KB |
Output is correct |
2 |
Correct |
660 ms |
70120 KB |
Output is correct |
3 |
Correct |
721 ms |
70328 KB |
Output is correct |
4 |
Correct |
440 ms |
66336 KB |
Output is correct |
5 |
Correct |
323 ms |
61288 KB |
Output is correct |
6 |
Correct |
149 ms |
56040 KB |
Output is correct |
7 |
Correct |
637 ms |
70124 KB |
Output is correct |
8 |
Correct |
618 ms |
70120 KB |
Output is correct |
9 |
Correct |
632 ms |
69864 KB |
Output is correct |
10 |
Correct |
295 ms |
59876 KB |
Output is correct |
11 |
Correct |
400 ms |
65608 KB |
Output is correct |
12 |
Correct |
125 ms |
55040 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
669 ms |
70144 KB |
Output is correct |
2 |
Correct |
660 ms |
70120 KB |
Output is correct |
3 |
Correct |
721 ms |
70328 KB |
Output is correct |
4 |
Correct |
440 ms |
66336 KB |
Output is correct |
5 |
Correct |
323 ms |
61288 KB |
Output is correct |
6 |
Correct |
149 ms |
56040 KB |
Output is correct |
7 |
Correct |
637 ms |
70124 KB |
Output is correct |
8 |
Correct |
618 ms |
70120 KB |
Output is correct |
9 |
Correct |
632 ms |
69864 KB |
Output is correct |
10 |
Correct |
295 ms |
59876 KB |
Output is correct |
11 |
Correct |
400 ms |
65608 KB |
Output is correct |
12 |
Correct |
125 ms |
55040 KB |
Output is correct |
13 |
Correct |
867 ms |
72600 KB |
Output is correct |
14 |
Correct |
827 ms |
72168 KB |
Output is correct |
15 |
Correct |
763 ms |
70160 KB |
Output is correct |
16 |
Correct |
538 ms |
68400 KB |
Output is correct |
17 |
Correct |
444 ms |
62984 KB |
Output is correct |
18 |
Correct |
173 ms |
56300 KB |
Output is correct |
19 |
Correct |
830 ms |
72680 KB |
Output is correct |
20 |
Correct |
830 ms |
72424 KB |
Output is correct |
21 |
Correct |
831 ms |
72428 KB |
Output is correct |
22 |
Correct |
254 ms |
59880 KB |
Output is correct |
23 |
Correct |
394 ms |
65668 KB |
Output is correct |
24 |
Correct |
139 ms |
55016 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
48 ms |
47360 KB |
Output is correct |
2 |
Correct |
49 ms |
47352 KB |
Output is correct |
3 |
Correct |
52 ms |
47352 KB |
Output is correct |
4 |
Correct |
43 ms |
47352 KB |
Output is correct |
5 |
Correct |
48 ms |
47368 KB |
Output is correct |
6 |
Correct |
46 ms |
47352 KB |
Output is correct |
7 |
Correct |
61 ms |
48504 KB |
Output is correct |
8 |
Correct |
68 ms |
48632 KB |
Output is correct |
9 |
Correct |
60 ms |
48504 KB |
Output is correct |
10 |
Correct |
61 ms |
48124 KB |
Output is correct |
11 |
Correct |
67 ms |
48120 KB |
Output is correct |
12 |
Correct |
52 ms |
47608 KB |
Output is correct |
13 |
Correct |
61 ms |
48376 KB |
Output is correct |
14 |
Correct |
70 ms |
48532 KB |
Output is correct |
15 |
Correct |
62 ms |
48376 KB |
Output is correct |
16 |
Correct |
55 ms |
47864 KB |
Output is correct |
17 |
Correct |
61 ms |
48248 KB |
Output is correct |
18 |
Correct |
55 ms |
47736 KB |
Output is correct |
19 |
Correct |
669 ms |
70144 KB |
Output is correct |
20 |
Correct |
660 ms |
70120 KB |
Output is correct |
21 |
Correct |
721 ms |
70328 KB |
Output is correct |
22 |
Correct |
440 ms |
66336 KB |
Output is correct |
23 |
Correct |
323 ms |
61288 KB |
Output is correct |
24 |
Correct |
149 ms |
56040 KB |
Output is correct |
25 |
Correct |
637 ms |
70124 KB |
Output is correct |
26 |
Correct |
618 ms |
70120 KB |
Output is correct |
27 |
Correct |
632 ms |
69864 KB |
Output is correct |
28 |
Correct |
295 ms |
59876 KB |
Output is correct |
29 |
Correct |
400 ms |
65608 KB |
Output is correct |
30 |
Correct |
125 ms |
55040 KB |
Output is correct |
31 |
Correct |
867 ms |
72600 KB |
Output is correct |
32 |
Correct |
827 ms |
72168 KB |
Output is correct |
33 |
Correct |
763 ms |
70160 KB |
Output is correct |
34 |
Correct |
538 ms |
68400 KB |
Output is correct |
35 |
Correct |
444 ms |
62984 KB |
Output is correct |
36 |
Correct |
173 ms |
56300 KB |
Output is correct |
37 |
Correct |
830 ms |
72680 KB |
Output is correct |
38 |
Correct |
830 ms |
72424 KB |
Output is correct |
39 |
Correct |
831 ms |
72428 KB |
Output is correct |
40 |
Correct |
254 ms |
59880 KB |
Output is correct |
41 |
Correct |
394 ms |
65668 KB |
Output is correct |
42 |
Correct |
139 ms |
55016 KB |
Output is correct |
43 |
Correct |
1049 ms |
88432 KB |
Output is correct |
44 |
Correct |
986 ms |
88548 KB |
Output is correct |
45 |
Correct |
1104 ms |
88552 KB |
Output is correct |
46 |
Correct |
653 ms |
76904 KB |
Output is correct |
47 |
Correct |
446 ms |
70240 KB |
Output is correct |
48 |
Correct |
171 ms |
55912 KB |
Output is correct |
49 |
Correct |
962 ms |
88680 KB |
Output is correct |
50 |
Correct |
911 ms |
88552 KB |
Output is correct |
51 |
Correct |
961 ms |
88244 KB |
Output is correct |
52 |
Correct |
443 ms |
68968 KB |
Output is correct |
53 |
Correct |
531 ms |
72608 KB |
Output is correct |