#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
int N, Q;
struct event
{
int x, y, z;
int i;
};
event* E;
bool xsort(event a, event b)
{
return a.x < b.x;
}
bool zsort(event a, event b)
{
if(a.z == b.z) return a.i > b.i;
return a.z > b.z;
}
map<int, int>* Ys = new map<int, int>[200001];
int main()
{
cin >> N >> Q;
E = new event[N+Q];
for(int i = 0; i < N; i++)
{
cin >> E[i].x >> E[i].y;
E[i].z = E[i].x + E[i].y;
E[i].x *= -1;
E[i].y *= -1;
E[i].i = i+1;
}
for(int i = 0; i < Q; i++)
{
cin >> E[N+i].x >> E[N+i].y >> E[N+i].z;
E[N+i].x *= -1;
E[N+i].y *= -1;
E[N+i].i = -(i+1);
}
sort(E, E+N+Q, xsort);
int p = E[0].x, q;
E[0].x = 1;
for(int i = 1; i < N+Q; i++)
{
q = E[i].x;
E[i].x = E[i-1].x + (p != q);
p = q;
}
for(int i = 0; i < N+Q; i++)
{
if(E[i].i > 0)
for(int j = E[i].x; j <= 200000; j += j&-j) Ys[j][E[i].y] = 0;
else
for(int j = E[i].x; j >= 1; j -= j&-j) Ys[j][E[i].y] = 0;
}
for(int i = 1; i <= 200000; i++)
{
int q = 0;
for(auto& ys: Ys[i])
{
q++;
ys.second = q;
}
}
int* BIT[200001];
for(int i = 1; i <= 200000; i++)
{
BIT[i] = new int[Ys[i].size() + 1];
for(int j = 1; j <= Ys[i].size(); j++) BIT[i][j] = 0;
}
int res[Q+1];
sort(E, E+N+Q, zsort);
for(int i = 0; i < N+Q; i++)
{
if(E[i].i > 0)
{
for(int j = E[i].x; j <= 200000; j += j&-j)
for(int k = Ys[ j ][ E[i].y ]; k <= Ys[ j ].size(); k += k&-k)
BIT[j][k]++;
}
else
{
res[-(E[i].i)] = 0;
for(int j = E[i].x; j >= 1; j -= j&-j)
for(int k = Ys[ j ][ E[i].y ]; k >= 1; k -= k&-k)
res[-(E[i].i)] += BIT[j][k];
}
}
for(int i = 1; i <= Q; i++) cout << res[i] << '\n';
return 0;
}
Compilation message
examination.cpp: In function 'int main()':
examination.cpp:83:26: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int j = 1; j <= Ys[i].size(); j++) BIT[i][j] = 0;
~~^~~~~~~~~~~~~~~
examination.cpp:93:50: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(int k = Ys[ j ][ E[i].y ]; k <= Ys[ j ].size(); k += k&-k)
~~^~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
17528 KB |
Output is correct |
2 |
Correct |
20 ms |
17528 KB |
Output is correct |
3 |
Correct |
20 ms |
17532 KB |
Output is correct |
4 |
Correct |
20 ms |
17528 KB |
Output is correct |
5 |
Correct |
21 ms |
17528 KB |
Output is correct |
6 |
Correct |
20 ms |
17528 KB |
Output is correct |
7 |
Correct |
48 ms |
20344 KB |
Output is correct |
8 |
Correct |
47 ms |
20344 KB |
Output is correct |
9 |
Correct |
48 ms |
20344 KB |
Output is correct |
10 |
Correct |
32 ms |
18296 KB |
Output is correct |
11 |
Correct |
41 ms |
20472 KB |
Output is correct |
12 |
Correct |
26 ms |
17656 KB |
Output is correct |
13 |
Correct |
47 ms |
20344 KB |
Output is correct |
14 |
Correct |
46 ms |
20344 KB |
Output is correct |
15 |
Correct |
45 ms |
20476 KB |
Output is correct |
16 |
Correct |
39 ms |
20472 KB |
Output is correct |
17 |
Correct |
29 ms |
18040 KB |
Output is correct |
18 |
Correct |
25 ms |
17656 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2207 ms |
105760 KB |
Output is correct |
2 |
Correct |
2277 ms |
108280 KB |
Output is correct |
3 |
Correct |
2203 ms |
108160 KB |
Output is correct |
4 |
Correct |
424 ms |
40312 KB |
Output is correct |
5 |
Correct |
1242 ms |
85588 KB |
Output is correct |
6 |
Correct |
225 ms |
22648 KB |
Output is correct |
7 |
Correct |
2496 ms |
108920 KB |
Output is correct |
8 |
Correct |
1978 ms |
104744 KB |
Output is correct |
9 |
Correct |
2077 ms |
98936 KB |
Output is correct |
10 |
Correct |
962 ms |
80760 KB |
Output is correct |
11 |
Correct |
301 ms |
29688 KB |
Output is correct |
12 |
Correct |
188 ms |
22264 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2207 ms |
105760 KB |
Output is correct |
2 |
Correct |
2277 ms |
108280 KB |
Output is correct |
3 |
Correct |
2203 ms |
108160 KB |
Output is correct |
4 |
Correct |
424 ms |
40312 KB |
Output is correct |
5 |
Correct |
1242 ms |
85588 KB |
Output is correct |
6 |
Correct |
225 ms |
22648 KB |
Output is correct |
7 |
Correct |
2496 ms |
108920 KB |
Output is correct |
8 |
Correct |
1978 ms |
104744 KB |
Output is correct |
9 |
Correct |
2077 ms |
98936 KB |
Output is correct |
10 |
Correct |
962 ms |
80760 KB |
Output is correct |
11 |
Correct |
301 ms |
29688 KB |
Output is correct |
12 |
Correct |
188 ms |
22264 KB |
Output is correct |
13 |
Correct |
2314 ms |
108480 KB |
Output is correct |
14 |
Correct |
2277 ms |
108536 KB |
Output is correct |
15 |
Correct |
2194 ms |
108256 KB |
Output is correct |
16 |
Correct |
450 ms |
40696 KB |
Output is correct |
17 |
Correct |
1285 ms |
85880 KB |
Output is correct |
18 |
Correct |
227 ms |
22776 KB |
Output is correct |
19 |
Correct |
2285 ms |
108792 KB |
Output is correct |
20 |
Correct |
2298 ms |
108792 KB |
Output is correct |
21 |
Correct |
2353 ms |
108140 KB |
Output is correct |
22 |
Correct |
944 ms |
80800 KB |
Output is correct |
23 |
Correct |
308 ms |
29944 KB |
Output is correct |
24 |
Correct |
181 ms |
22264 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
19 ms |
17528 KB |
Output is correct |
2 |
Correct |
20 ms |
17528 KB |
Output is correct |
3 |
Correct |
20 ms |
17532 KB |
Output is correct |
4 |
Correct |
20 ms |
17528 KB |
Output is correct |
5 |
Correct |
21 ms |
17528 KB |
Output is correct |
6 |
Correct |
20 ms |
17528 KB |
Output is correct |
7 |
Correct |
48 ms |
20344 KB |
Output is correct |
8 |
Correct |
47 ms |
20344 KB |
Output is correct |
9 |
Correct |
48 ms |
20344 KB |
Output is correct |
10 |
Correct |
32 ms |
18296 KB |
Output is correct |
11 |
Correct |
41 ms |
20472 KB |
Output is correct |
12 |
Correct |
26 ms |
17656 KB |
Output is correct |
13 |
Correct |
47 ms |
20344 KB |
Output is correct |
14 |
Correct |
46 ms |
20344 KB |
Output is correct |
15 |
Correct |
45 ms |
20476 KB |
Output is correct |
16 |
Correct |
39 ms |
20472 KB |
Output is correct |
17 |
Correct |
29 ms |
18040 KB |
Output is correct |
18 |
Correct |
25 ms |
17656 KB |
Output is correct |
19 |
Correct |
2207 ms |
105760 KB |
Output is correct |
20 |
Correct |
2277 ms |
108280 KB |
Output is correct |
21 |
Correct |
2203 ms |
108160 KB |
Output is correct |
22 |
Correct |
424 ms |
40312 KB |
Output is correct |
23 |
Correct |
1242 ms |
85588 KB |
Output is correct |
24 |
Correct |
225 ms |
22648 KB |
Output is correct |
25 |
Correct |
2496 ms |
108920 KB |
Output is correct |
26 |
Correct |
1978 ms |
104744 KB |
Output is correct |
27 |
Correct |
2077 ms |
98936 KB |
Output is correct |
28 |
Correct |
962 ms |
80760 KB |
Output is correct |
29 |
Correct |
301 ms |
29688 KB |
Output is correct |
30 |
Correct |
188 ms |
22264 KB |
Output is correct |
31 |
Correct |
2314 ms |
108480 KB |
Output is correct |
32 |
Correct |
2277 ms |
108536 KB |
Output is correct |
33 |
Correct |
2194 ms |
108256 KB |
Output is correct |
34 |
Correct |
450 ms |
40696 KB |
Output is correct |
35 |
Correct |
1285 ms |
85880 KB |
Output is correct |
36 |
Correct |
227 ms |
22776 KB |
Output is correct |
37 |
Correct |
2285 ms |
108792 KB |
Output is correct |
38 |
Correct |
2298 ms |
108792 KB |
Output is correct |
39 |
Correct |
2353 ms |
108140 KB |
Output is correct |
40 |
Correct |
944 ms |
80800 KB |
Output is correct |
41 |
Correct |
308 ms |
29944 KB |
Output is correct |
42 |
Correct |
181 ms |
22264 KB |
Output is correct |
43 |
Correct |
2360 ms |
116352 KB |
Output is correct |
44 |
Correct |
2345 ms |
116472 KB |
Output is correct |
45 |
Correct |
2290 ms |
116344 KB |
Output is correct |
46 |
Correct |
526 ms |
47608 KB |
Output is correct |
47 |
Correct |
1577 ms |
118008 KB |
Output is correct |
48 |
Correct |
227 ms |
22560 KB |
Output is correct |
49 |
Correct |
2398 ms |
121720 KB |
Output is correct |
50 |
Correct |
2245 ms |
116472 KB |
Output is correct |
51 |
Correct |
2274 ms |
121592 KB |
Output is correct |
52 |
Correct |
1286 ms |
116600 KB |
Output is correct |
53 |
Correct |
362 ms |
36088 KB |
Output is correct |