#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template<class S> struct BIT {
int n;vector<S> s;
BIT(int n):n(n),s(n+1){}
void add(int i,const S&v){for(i++;i<=n;i+=i&-i)s[i]+=v;}
S sum(int i){S t{};for(;i;i-=i&-i)t+=s[i];return t;}
S sum(int l,int r){return sum(r)-sum(l);}
};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N, Q;
cin >> N >> Q;
vector<int> S(N), T(N), A(Q), B(Q), C(Q);
for (int i = 0; i < N; i++) cin >> S[i] >> T[i];
for (int i = 0; i < Q; i++) cin >> A[i] >> B[i] >> C[i];
vector<int> ans(Q), ss(S), st(T), sp(N);
vector cnt(Q, vector<int>(8));
for (int i = 0; i < N; i++) sp[i] = S[i] + T[i];
sort(ss.begin(), ss.end());
sort(st.begin(), st.end());
sort(sp.begin(), sp.end());
for (int i = 0; i < Q; i++) {
if (A[i] + B[i] >= C[i]) continue;
cnt[i][1] = lower_bound(ss.begin(), ss.end(), A[i]) - ss.begin();
cnt[i][2] = lower_bound(st.begin(), st.end(), B[i]) - st.begin();
cnt[i][4] = lower_bound(sp.begin(), sp.end(), C[i]) - sp.begin();
}
vector<int> vy, vz;
vector<array<int, 2>> X, Y;
for (int i = 0; i < N; i++) {
vy.push_back(T[i]);
vz.push_back(S[i] + T[i]);
X.push_back({S[i], i});
Y.push_back({T[i], i});
}
for (int i = 0; i < Q; i++) {
vy.push_back(B[i]);
vz.push_back(C[i]);
X.push_back({A[i], ~i});
Y.push_back({B[i], ~i});
}
sort(X.begin(), X.end());
sort(Y.begin(), Y.end());
sort(vy.begin(), vy.end());
sort(vz.begin(), vz.end());
vy.erase(unique(vy.begin(), vy.end()), vy.end());
vz.erase(unique(vz.begin(), vz.end()), vz.end());
int ny = vy.size(), nz = vz.size();
auto gety = [&](int v) {return lower_bound(vy.begin(), vy.end(), v) - vy.begin();};
auto getz = [&](int v) {return lower_bound(vz.begin(), vz.end(), v) - vz.begin();};
BIT<int> by(ny), bz(nz);
for (auto [_, i] : X) {
if (i >= 0) {
by.add(gety(T[i]), 1);
bz.add(getz(S[i] + T[i]), 1);
} else {
cnt[~i][3] += by.sum(0, gety(B[~i]));
cnt[~i][5] += bz.sum(0, getz(C[~i]));
}
}
bz = BIT<int>(nz);
for (auto [_, i] : Y) {
if (i >= 0) bz.add(getz(S[i] + T[i]), 1);
else cnt[~i][6] += bz.sum(0, getz(C[~i]));
}
sort(X.rbegin(), X.rend());
by = BIT<int>(ny);
for (auto [_, i] : X) {
if (i >= 0) by.add(gety(T[i]), 1);
else ans[~i] = by.sum(gety(B[~i]), ny);
}
for (int i = 0; i < Q; i++) {
if (A[i] + B[i] >= C[i]) continue;
ans[i] = N;
cnt[i][7] = cnt[i][3];
for (int j = 1; j < 8; j++) {
if (__builtin_parity(j)) ans[i] -= cnt[i][j];
else ans[i] += cnt[i][j];
}
}
for (auto i : ans) cout << i << "\n";
return 6/22;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
6 ms |
1140 KB |
Output is correct |
8 |
Correct |
6 ms |
1116 KB |
Output is correct |
9 |
Correct |
6 ms |
1160 KB |
Output is correct |
10 |
Correct |
7 ms |
1116 KB |
Output is correct |
11 |
Correct |
6 ms |
980 KB |
Output is correct |
12 |
Correct |
4 ms |
856 KB |
Output is correct |
13 |
Correct |
5 ms |
976 KB |
Output is correct |
14 |
Correct |
5 ms |
1116 KB |
Output is correct |
15 |
Correct |
7 ms |
1116 KB |
Output is correct |
16 |
Correct |
5 ms |
1112 KB |
Output is correct |
17 |
Correct |
4 ms |
1116 KB |
Output is correct |
18 |
Correct |
3 ms |
860 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
213 ms |
20024 KB |
Output is correct |
2 |
Correct |
206 ms |
19924 KB |
Output is correct |
3 |
Correct |
207 ms |
19876 KB |
Output is correct |
4 |
Correct |
140 ms |
18516 KB |
Output is correct |
5 |
Correct |
184 ms |
19108 KB |
Output is correct |
6 |
Correct |
106 ms |
17320 KB |
Output is correct |
7 |
Correct |
201 ms |
19880 KB |
Output is correct |
8 |
Correct |
201 ms |
19380 KB |
Output is correct |
9 |
Correct |
190 ms |
19476 KB |
Output is correct |
10 |
Correct |
171 ms |
18876 KB |
Output is correct |
11 |
Correct |
124 ms |
18232 KB |
Output is correct |
12 |
Correct |
95 ms |
17068 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
213 ms |
20024 KB |
Output is correct |
2 |
Correct |
206 ms |
19924 KB |
Output is correct |
3 |
Correct |
207 ms |
19876 KB |
Output is correct |
4 |
Correct |
140 ms |
18516 KB |
Output is correct |
5 |
Correct |
184 ms |
19108 KB |
Output is correct |
6 |
Correct |
106 ms |
17320 KB |
Output is correct |
7 |
Correct |
201 ms |
19880 KB |
Output is correct |
8 |
Correct |
201 ms |
19380 KB |
Output is correct |
9 |
Correct |
190 ms |
19476 KB |
Output is correct |
10 |
Correct |
171 ms |
18876 KB |
Output is correct |
11 |
Correct |
124 ms |
18232 KB |
Output is correct |
12 |
Correct |
95 ms |
17068 KB |
Output is correct |
13 |
Correct |
253 ms |
20436 KB |
Output is correct |
14 |
Correct |
240 ms |
20420 KB |
Output is correct |
15 |
Correct |
204 ms |
20036 KB |
Output is correct |
16 |
Correct |
177 ms |
19112 KB |
Output is correct |
17 |
Correct |
227 ms |
19652 KB |
Output is correct |
18 |
Correct |
109 ms |
17464 KB |
Output is correct |
19 |
Correct |
251 ms |
20452 KB |
Output is correct |
20 |
Correct |
250 ms |
20392 KB |
Output is correct |
21 |
Correct |
255 ms |
20392 KB |
Output is correct |
22 |
Correct |
170 ms |
19076 KB |
Output is correct |
23 |
Correct |
134 ms |
18236 KB |
Output is correct |
24 |
Correct |
92 ms |
16912 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
348 KB |
Output is correct |
5 |
Correct |
1 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
6 ms |
1140 KB |
Output is correct |
8 |
Correct |
6 ms |
1116 KB |
Output is correct |
9 |
Correct |
6 ms |
1160 KB |
Output is correct |
10 |
Correct |
7 ms |
1116 KB |
Output is correct |
11 |
Correct |
6 ms |
980 KB |
Output is correct |
12 |
Correct |
4 ms |
856 KB |
Output is correct |
13 |
Correct |
5 ms |
976 KB |
Output is correct |
14 |
Correct |
5 ms |
1116 KB |
Output is correct |
15 |
Correct |
7 ms |
1116 KB |
Output is correct |
16 |
Correct |
5 ms |
1112 KB |
Output is correct |
17 |
Correct |
4 ms |
1116 KB |
Output is correct |
18 |
Correct |
3 ms |
860 KB |
Output is correct |
19 |
Correct |
213 ms |
20024 KB |
Output is correct |
20 |
Correct |
206 ms |
19924 KB |
Output is correct |
21 |
Correct |
207 ms |
19876 KB |
Output is correct |
22 |
Correct |
140 ms |
18516 KB |
Output is correct |
23 |
Correct |
184 ms |
19108 KB |
Output is correct |
24 |
Correct |
106 ms |
17320 KB |
Output is correct |
25 |
Correct |
201 ms |
19880 KB |
Output is correct |
26 |
Correct |
201 ms |
19380 KB |
Output is correct |
27 |
Correct |
190 ms |
19476 KB |
Output is correct |
28 |
Correct |
171 ms |
18876 KB |
Output is correct |
29 |
Correct |
124 ms |
18232 KB |
Output is correct |
30 |
Correct |
95 ms |
17068 KB |
Output is correct |
31 |
Correct |
253 ms |
20436 KB |
Output is correct |
32 |
Correct |
240 ms |
20420 KB |
Output is correct |
33 |
Correct |
204 ms |
20036 KB |
Output is correct |
34 |
Correct |
177 ms |
19112 KB |
Output is correct |
35 |
Correct |
227 ms |
19652 KB |
Output is correct |
36 |
Correct |
109 ms |
17464 KB |
Output is correct |
37 |
Correct |
251 ms |
20452 KB |
Output is correct |
38 |
Correct |
250 ms |
20392 KB |
Output is correct |
39 |
Correct |
255 ms |
20392 KB |
Output is correct |
40 |
Correct |
170 ms |
19076 KB |
Output is correct |
41 |
Correct |
134 ms |
18236 KB |
Output is correct |
42 |
Correct |
92 ms |
16912 KB |
Output is correct |
43 |
Correct |
279 ms |
23460 KB |
Output is correct |
44 |
Correct |
273 ms |
23464 KB |
Output is correct |
45 |
Correct |
255 ms |
23452 KB |
Output is correct |
46 |
Correct |
186 ms |
21180 KB |
Output is correct |
47 |
Correct |
245 ms |
21924 KB |
Output is correct |
48 |
Correct |
119 ms |
17228 KB |
Output is correct |
49 |
Correct |
260 ms |
23404 KB |
Output is correct |
50 |
Correct |
276 ms |
23240 KB |
Output is correct |
51 |
Correct |
258 ms |
23184 KB |
Output is correct |
52 |
Correct |
240 ms |
22340 KB |
Output is correct |
53 |
Correct |
127 ms |
19252 KB |
Output is correct |