#include "bits/stdc++.h"
using namespace std;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define all(x) x.begin(),x.end()
#define sz(x) int(x.size())
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
const int N = 100000;
const int B = pow(N,.666);
int cnt[N];
int active = 0;
int main(){
cin.tie(NULL),cin.sync_with_stdio(false);
int n,q; cin >> n >> q;
vector<array<int,2>> a(n);
rep(i,0,n) rep(j,0,2) cin >> a[i][j];
vvi ord(3,vi(n));
rep(i,0,3) iota(all(ord[i]),0);
rep(i,0,2) sort(all(ord[i]), [&](int l, int r){
return a[l][i] < a[r][i];
});
sort(all(ord[2]),[&](int l, int r){
return a[l][0] + a[l][1] < a[r][0] + a[r][1];
});
vvi vals(3,vi(n));
rep(i,0,2) rep(j,0,n) vals[i][j] = a[ord[i][j]][i];
rep(j,0,n) vals[2][j] = a[ord[2][j]][0] + a[ord[2][j]][1];
vector<array<int,3>> qs(q), s(q);
vi qi(q);
iota(all(qi),0);
rep(i,0,q){
rep(j,0,3) cin >> qs[i][j],
qs[i][j] = lower_bound(all(vals[j]),qs[i][j]) - begin(vals[j]);
int x = 0;
rep(j,0,3){
s[i][j] = qs[i][j]/B;
if (x) s[i][j] = n - s[i][j];
x ^= s[i][j]&1;
}
}
sort(all(qi),[&](int l, int r){
return s[l] < s[r];
});
array<int,3> cur = {n,n,n}; // none are active yet
vi sol(q);
for(auto id : qi){
rep(j,0,3){
while (cur[j] > qs[id][j]) {
cur[j]--;
cnt[ord[j][cur[j]]]++;
if (cnt[ord[j][cur[j]]] == 3) active++;
}while (cur[j] < qs[id][j]){
cnt[ord[j][cur[j]]]--;
if (cnt[ord[j][cur[j]]] == 2) active--;
cur[j]++;
}
}
sol[id] = active;
}
for(auto c : sol) cout << c << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
15 ms |
812 KB |
Output is correct |
8 |
Correct |
15 ms |
604 KB |
Output is correct |
9 |
Correct |
15 ms |
604 KB |
Output is correct |
10 |
Correct |
14 ms |
604 KB |
Output is correct |
11 |
Correct |
13 ms |
736 KB |
Output is correct |
12 |
Correct |
13 ms |
604 KB |
Output is correct |
13 |
Correct |
13 ms |
604 KB |
Output is correct |
14 |
Correct |
13 ms |
604 KB |
Output is correct |
15 |
Correct |
13 ms |
604 KB |
Output is correct |
16 |
Correct |
4 ms |
732 KB |
Output is correct |
17 |
Correct |
7 ms |
604 KB |
Output is correct |
18 |
Correct |
2 ms |
472 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
461 ms |
9932 KB |
Output is correct |
2 |
Correct |
465 ms |
10128 KB |
Output is correct |
3 |
Correct |
469 ms |
9932 KB |
Output is correct |
4 |
Correct |
220 ms |
9372 KB |
Output is correct |
5 |
Correct |
194 ms |
9416 KB |
Output is correct |
6 |
Correct |
57 ms |
8652 KB |
Output is correct |
7 |
Correct |
343 ms |
9912 KB |
Output is correct |
8 |
Correct |
351 ms |
10028 KB |
Output is correct |
9 |
Correct |
348 ms |
9976 KB |
Output is correct |
10 |
Correct |
168 ms |
9104 KB |
Output is correct |
11 |
Correct |
192 ms |
9164 KB |
Output is correct |
12 |
Correct |
37 ms |
8136 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
461 ms |
9932 KB |
Output is correct |
2 |
Correct |
465 ms |
10128 KB |
Output is correct |
3 |
Correct |
469 ms |
9932 KB |
Output is correct |
4 |
Correct |
220 ms |
9372 KB |
Output is correct |
5 |
Correct |
194 ms |
9416 KB |
Output is correct |
6 |
Correct |
57 ms |
8652 KB |
Output is correct |
7 |
Correct |
343 ms |
9912 KB |
Output is correct |
8 |
Correct |
351 ms |
10028 KB |
Output is correct |
9 |
Correct |
348 ms |
9976 KB |
Output is correct |
10 |
Correct |
168 ms |
9104 KB |
Output is correct |
11 |
Correct |
192 ms |
9164 KB |
Output is correct |
12 |
Correct |
37 ms |
8136 KB |
Output is correct |
13 |
Correct |
1286 ms |
10544 KB |
Output is correct |
14 |
Correct |
892 ms |
10444 KB |
Output is correct |
15 |
Correct |
456 ms |
9928 KB |
Output is correct |
16 |
Correct |
650 ms |
9672 KB |
Output is correct |
17 |
Correct |
492 ms |
9676 KB |
Output is correct |
18 |
Correct |
96 ms |
8648 KB |
Output is correct |
19 |
Correct |
1221 ms |
10440 KB |
Output is correct |
20 |
Correct |
1203 ms |
10544 KB |
Output is correct |
21 |
Correct |
908 ms |
10440 KB |
Output is correct |
22 |
Correct |
179 ms |
9164 KB |
Output is correct |
23 |
Correct |
186 ms |
9072 KB |
Output is correct |
24 |
Correct |
38 ms |
8140 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 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 |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
15 ms |
812 KB |
Output is correct |
8 |
Correct |
15 ms |
604 KB |
Output is correct |
9 |
Correct |
15 ms |
604 KB |
Output is correct |
10 |
Correct |
14 ms |
604 KB |
Output is correct |
11 |
Correct |
13 ms |
736 KB |
Output is correct |
12 |
Correct |
13 ms |
604 KB |
Output is correct |
13 |
Correct |
13 ms |
604 KB |
Output is correct |
14 |
Correct |
13 ms |
604 KB |
Output is correct |
15 |
Correct |
13 ms |
604 KB |
Output is correct |
16 |
Correct |
4 ms |
732 KB |
Output is correct |
17 |
Correct |
7 ms |
604 KB |
Output is correct |
18 |
Correct |
2 ms |
472 KB |
Output is correct |
19 |
Correct |
461 ms |
9932 KB |
Output is correct |
20 |
Correct |
465 ms |
10128 KB |
Output is correct |
21 |
Correct |
469 ms |
9932 KB |
Output is correct |
22 |
Correct |
220 ms |
9372 KB |
Output is correct |
23 |
Correct |
194 ms |
9416 KB |
Output is correct |
24 |
Correct |
57 ms |
8652 KB |
Output is correct |
25 |
Correct |
343 ms |
9912 KB |
Output is correct |
26 |
Correct |
351 ms |
10028 KB |
Output is correct |
27 |
Correct |
348 ms |
9976 KB |
Output is correct |
28 |
Correct |
168 ms |
9104 KB |
Output is correct |
29 |
Correct |
192 ms |
9164 KB |
Output is correct |
30 |
Correct |
37 ms |
8136 KB |
Output is correct |
31 |
Correct |
1286 ms |
10544 KB |
Output is correct |
32 |
Correct |
892 ms |
10444 KB |
Output is correct |
33 |
Correct |
456 ms |
9928 KB |
Output is correct |
34 |
Correct |
650 ms |
9672 KB |
Output is correct |
35 |
Correct |
492 ms |
9676 KB |
Output is correct |
36 |
Correct |
96 ms |
8648 KB |
Output is correct |
37 |
Correct |
1221 ms |
10440 KB |
Output is correct |
38 |
Correct |
1203 ms |
10544 KB |
Output is correct |
39 |
Correct |
908 ms |
10440 KB |
Output is correct |
40 |
Correct |
179 ms |
9164 KB |
Output is correct |
41 |
Correct |
186 ms |
9072 KB |
Output is correct |
42 |
Correct |
38 ms |
8140 KB |
Output is correct |
43 |
Correct |
1280 ms |
12484 KB |
Output is correct |
44 |
Correct |
1249 ms |
12512 KB |
Output is correct |
45 |
Correct |
915 ms |
12272 KB |
Output is correct |
46 |
Correct |
649 ms |
10956 KB |
Output is correct |
47 |
Correct |
510 ms |
10952 KB |
Output is correct |
48 |
Correct |
126 ms |
8396 KB |
Output is correct |
49 |
Correct |
714 ms |
12232 KB |
Output is correct |
50 |
Correct |
735 ms |
12276 KB |
Output is correct |
51 |
Correct |
640 ms |
12240 KB |
Output is correct |
52 |
Correct |
332 ms |
10692 KB |
Output is correct |
53 |
Correct |
191 ms |
9916 KB |
Output is correct |