#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)x.size())
#define sumof(x) accumulate(all(x), 0ll)
struct nigga{
int x, y, z, i;
nigga(int a=0, int b=0, int c=0, int d=0): x(a), y(b), z(c), i(d){}
bool operator<(const nigga &a) const {
return make_pair(z, i)<make_pair(a.z, a.i);
}
};
const int N=2e5+1;
int n, q, ans[N];
nigga a[N];
vector<int> node[N];
vector<int> t[N];
void fake_update(int x, int y){
for (int i=x; i<N; i+=i&-i) node[i].push_back(y);
}
void update(int x, int y){
for (int i=x; i<N; i+=i&-i)
for (int j=lower_bound(all(node[i]), y)-node[i].begin()+1; j<=sz(node[i]); j+=j&-j) ++t[i][j];
}
int get(int x, int y){
int res=0;
for (int i=x; i; i-=i&-i)
for (int j=upper_bound(all(node[i]), y)-node[i].begin(); j; j-=j&-j) res+=t[i][j];
return res;
}
void solve(int tc){
// cout << "Case #" << tc << ": ";
cin >> n >> q;
vector<int> r, c;
for (int i=1; i<=n; ++i) cin >> a[i].x >> a[i].y, a[i].x*=-1, a[i].y*=-1, a[i].z=a[i].x+a[i].y, r.push_back(a[i].x), c.push_back(a[i].y), a[i].i=i;
for (int i=n+1; i<=n+q; ++i) cin >> a[i].x >> a[i].y >> a[i].z, a[i].x*=-1, a[i].y*=-1, a[i].z*=-1, r.push_back(a[i].x), c.push_back(a[i].y), a[i].i=i;
sort(all(r)); sort(all(c)); r.resize(unique(all(r))-r.begin()); c.resize(unique(all(c))-c.begin());
for (int i=1; i<=n+q; ++i) a[i].x=lower_bound(all(r), a[i].x)-r.begin()+1, a[i].y=lower_bound(all(c), a[i].y)-c.begin()+1;
for (int i=1; i<=n; ++i) fake_update(a[i].x, a[i].y);
sort(a+1, a+n+q+1);
for (int i=1; i<N; ++i){
node[i].push_back(-1);
node[i].push_back(1e9);
sort(all(node[i]));
node[i].resize(unique(all(node[i]))-node[i].begin());
t[i].resize(sz(node[i])+1);
}
for (int i=1; i<=n+q; ++i){
if (a[i].i<=n) update(a[i].x, a[i].y);
else ans[a[i].i-n]=get(a[i].x, a[i].y);
}
for (int i=1; i<=q; ++i) cout << ans[i] << '\n';
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int ntests=1;
// cin >> ntests;
for (int i=1; i<=ntests; ++i) solve(i);
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
28444 KB |
Output is correct |
2 |
Correct |
32 ms |
28408 KB |
Output is correct |
3 |
Correct |
34 ms |
28496 KB |
Output is correct |
4 |
Correct |
32 ms |
28420 KB |
Output is correct |
5 |
Correct |
32 ms |
28420 KB |
Output is correct |
6 |
Correct |
34 ms |
28508 KB |
Output is correct |
7 |
Correct |
43 ms |
29296 KB |
Output is correct |
8 |
Correct |
44 ms |
29260 KB |
Output is correct |
9 |
Correct |
43 ms |
29240 KB |
Output is correct |
10 |
Correct |
40 ms |
29084 KB |
Output is correct |
11 |
Correct |
41 ms |
29420 KB |
Output is correct |
12 |
Correct |
39 ms |
29140 KB |
Output is correct |
13 |
Correct |
43 ms |
29320 KB |
Output is correct |
14 |
Correct |
43 ms |
29240 KB |
Output is correct |
15 |
Correct |
43 ms |
29288 KB |
Output is correct |
16 |
Correct |
41 ms |
29496 KB |
Output is correct |
17 |
Correct |
39 ms |
29044 KB |
Output is correct |
18 |
Correct |
38 ms |
29096 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
431 ms |
51584 KB |
Output is correct |
2 |
Correct |
448 ms |
51588 KB |
Output is correct |
3 |
Correct |
439 ms |
51680 KB |
Output is correct |
4 |
Correct |
209 ms |
46088 KB |
Output is correct |
5 |
Correct |
325 ms |
56764 KB |
Output is correct |
6 |
Correct |
158 ms |
48316 KB |
Output is correct |
7 |
Correct |
410 ms |
50272 KB |
Output is correct |
8 |
Correct |
404 ms |
51556 KB |
Output is correct |
9 |
Correct |
382 ms |
50188 KB |
Output is correct |
10 |
Correct |
302 ms |
56500 KB |
Output is correct |
11 |
Correct |
170 ms |
45060 KB |
Output is correct |
12 |
Correct |
108 ms |
46852 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
431 ms |
51584 KB |
Output is correct |
2 |
Correct |
448 ms |
51588 KB |
Output is correct |
3 |
Correct |
439 ms |
51680 KB |
Output is correct |
4 |
Correct |
209 ms |
46088 KB |
Output is correct |
5 |
Correct |
325 ms |
56764 KB |
Output is correct |
6 |
Correct |
158 ms |
48316 KB |
Output is correct |
7 |
Correct |
410 ms |
50272 KB |
Output is correct |
8 |
Correct |
404 ms |
51556 KB |
Output is correct |
9 |
Correct |
382 ms |
50188 KB |
Output is correct |
10 |
Correct |
302 ms |
56500 KB |
Output is correct |
11 |
Correct |
170 ms |
45060 KB |
Output is correct |
12 |
Correct |
108 ms |
46852 KB |
Output is correct |
13 |
Correct |
472 ms |
51632 KB |
Output is correct |
14 |
Correct |
465 ms |
51664 KB |
Output is correct |
15 |
Correct |
424 ms |
51628 KB |
Output is correct |
16 |
Correct |
218 ms |
46084 KB |
Output is correct |
17 |
Correct |
341 ms |
56876 KB |
Output is correct |
18 |
Correct |
159 ms |
48268 KB |
Output is correct |
19 |
Correct |
451 ms |
51732 KB |
Output is correct |
20 |
Correct |
461 ms |
51736 KB |
Output is correct |
21 |
Correct |
450 ms |
50864 KB |
Output is correct |
22 |
Correct |
297 ms |
56456 KB |
Output is correct |
23 |
Correct |
182 ms |
45084 KB |
Output is correct |
24 |
Correct |
108 ms |
46972 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
32 ms |
28444 KB |
Output is correct |
2 |
Correct |
32 ms |
28408 KB |
Output is correct |
3 |
Correct |
34 ms |
28496 KB |
Output is correct |
4 |
Correct |
32 ms |
28420 KB |
Output is correct |
5 |
Correct |
32 ms |
28420 KB |
Output is correct |
6 |
Correct |
34 ms |
28508 KB |
Output is correct |
7 |
Correct |
43 ms |
29296 KB |
Output is correct |
8 |
Correct |
44 ms |
29260 KB |
Output is correct |
9 |
Correct |
43 ms |
29240 KB |
Output is correct |
10 |
Correct |
40 ms |
29084 KB |
Output is correct |
11 |
Correct |
41 ms |
29420 KB |
Output is correct |
12 |
Correct |
39 ms |
29140 KB |
Output is correct |
13 |
Correct |
43 ms |
29320 KB |
Output is correct |
14 |
Correct |
43 ms |
29240 KB |
Output is correct |
15 |
Correct |
43 ms |
29288 KB |
Output is correct |
16 |
Correct |
41 ms |
29496 KB |
Output is correct |
17 |
Correct |
39 ms |
29044 KB |
Output is correct |
18 |
Correct |
38 ms |
29096 KB |
Output is correct |
19 |
Correct |
431 ms |
51584 KB |
Output is correct |
20 |
Correct |
448 ms |
51588 KB |
Output is correct |
21 |
Correct |
439 ms |
51680 KB |
Output is correct |
22 |
Correct |
209 ms |
46088 KB |
Output is correct |
23 |
Correct |
325 ms |
56764 KB |
Output is correct |
24 |
Correct |
158 ms |
48316 KB |
Output is correct |
25 |
Correct |
410 ms |
50272 KB |
Output is correct |
26 |
Correct |
404 ms |
51556 KB |
Output is correct |
27 |
Correct |
382 ms |
50188 KB |
Output is correct |
28 |
Correct |
302 ms |
56500 KB |
Output is correct |
29 |
Correct |
170 ms |
45060 KB |
Output is correct |
30 |
Correct |
108 ms |
46852 KB |
Output is correct |
31 |
Correct |
472 ms |
51632 KB |
Output is correct |
32 |
Correct |
465 ms |
51664 KB |
Output is correct |
33 |
Correct |
424 ms |
51628 KB |
Output is correct |
34 |
Correct |
218 ms |
46084 KB |
Output is correct |
35 |
Correct |
341 ms |
56876 KB |
Output is correct |
36 |
Correct |
159 ms |
48268 KB |
Output is correct |
37 |
Correct |
451 ms |
51732 KB |
Output is correct |
38 |
Correct |
461 ms |
51736 KB |
Output is correct |
39 |
Correct |
450 ms |
50864 KB |
Output is correct |
40 |
Correct |
297 ms |
56456 KB |
Output is correct |
41 |
Correct |
182 ms |
45084 KB |
Output is correct |
42 |
Correct |
108 ms |
46972 KB |
Output is correct |
43 |
Correct |
492 ms |
51052 KB |
Output is correct |
44 |
Correct |
472 ms |
51216 KB |
Output is correct |
45 |
Correct |
470 ms |
51244 KB |
Output is correct |
46 |
Correct |
251 ms |
46204 KB |
Output is correct |
47 |
Correct |
356 ms |
61156 KB |
Output is correct |
48 |
Correct |
169 ms |
47988 KB |
Output is correct |
49 |
Correct |
446 ms |
52836 KB |
Output is correct |
50 |
Correct |
465 ms |
51192 KB |
Output is correct |
51 |
Correct |
441 ms |
52736 KB |
Output is correct |
52 |
Correct |
319 ms |
61320 KB |
Output is correct |
53 |
Correct |
205 ms |
45064 KB |
Output is correct |