#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define ld double
#define pb push_back
#define pf push_front
#define vi vector<ll>
#define vii vector<vi>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define all(a) a.begin(), a.end()
#define fi first
#define se second
using namespace std;
const ll mod = 1e9+7;
const ll inf = 2e18;
const ll base = 31;
const ll blocksz = 320;
const ll N = 2e5+8;
ll n,q;
struct point{
ll x,y,z,id;
} a[N];
struct Binary_Indexed_Tree{
ll BIT[N];
void update(ll i, ll x){
while(i <= n+q){
BIT[i] += x;
i += (i&-i);
}
}
ll get(ll i){
ll ans = 0;
while(i){
ans += BIT[i];
i -= (i&-i);
}
return ans;
}
} bit;
ll ans[N];
void cdq(ll l, ll r){
if(l == r) return;
ll m = l+r>>1;
cdq(l,m),cdq(m+1,r);
vector<point> pts;
vi reset;
ll i = l, j = m+1, cnt = 0;
while(i <= m && j <= r){
if(a[i].y > a[j].y){
if(a[i].id <= n) bit.update(a[i].z,1),cnt++,reset.pb(a[i].z);
pts.pb(a[i++]);
}
else{
if(a[j].id > n) ans[a[j].id] += cnt-bit.get(a[j].z);
pts.pb(a[j++]);
}
}
while(i <= m){
if(a[i].id <= n) bit.update(a[i].z,1),cnt++,reset.pb(a[i].z);
pts.pb(a[i++]);
}
while(j <= r){
if(a[j].id > n) ans[a[j].id] += cnt-bit.get(a[j].z);
pts.pb(a[j++]);
}
for (ll i = l; i <= r; ++i) a[i] = pts[i-l];
for (ll i:reset) bit.update(i,-1);
}
map<ll,ll> comp;
void solve(){
cin >> n >> q;
vi compress;
for(ll i = 1; i <= n; i++){
cin >> a[i].x >> a[i].y;
a[i].id = i;
a[i].z = a[i].x+a[i].y;
compress.pb(a[i].z);
}
for(ll i = n+1; i <= n+q; i++){
cin >> a[i].x >> a[i].y >> a[i].z;
a[i].x--, a[i].y--, a[i].z--;
a[i].id = i;
compress.pb(a[i].z);
}
sort(all(compress));
compress.erase(unique(all(compress)),compress.end());
for(ll i = 1; i <= compress.size(); i++){
comp[compress[i-1]] = i;
}
for(ll i = 1; i <= n+q; i++) a[i].z = comp[a[i].z];
sort(a+1,a+n+q+1,[&](point x, point y){
return x.x > y.x || (x.x == y.x && (x.y < y.y || (x.y == y.y && x.z < y.z)));
});
cdq(1,n+q);
for(ll i = n+1; i <= n+q; i++){
cout << ans[i] << '\n';
}
}
signed main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
if(fopen("test.inp","r")){
freopen("test.inp","r",stdin);
freopen("test.out","w",stdout);
}
ll T = 1;
// cin >> T;
while(T--){
solve();
cout << '\n';
}
}
Compilation message
examination.cpp: In function 'void cdq(long long int, long long int)':
examination.cpp:44:13: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
44 | ll m = l+r>>1;
| ~^~
examination.cpp: In function 'void solve()':
examination.cpp:88:21: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
88 | for(ll i = 1; i <= compress.size(); i++){
| ~~^~~~~~~~~~~~~~~~~~
examination.cpp: In function 'int main()':
examination.cpp:103:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
103 | freopen("test.inp","r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
examination.cpp:104:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
104 | freopen("test.out","w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 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 |
6 ms |
1692 KB |
Output is correct |
8 |
Correct |
6 ms |
1716 KB |
Output is correct |
9 |
Correct |
6 ms |
1564 KB |
Output is correct |
10 |
Correct |
6 ms |
1596 KB |
Output is correct |
11 |
Correct |
6 ms |
1604 KB |
Output is correct |
12 |
Correct |
4 ms |
1196 KB |
Output is correct |
13 |
Correct |
5 ms |
1432 KB |
Output is correct |
14 |
Correct |
5 ms |
1388 KB |
Output is correct |
15 |
Correct |
6 ms |
1412 KB |
Output is correct |
16 |
Correct |
5 ms |
1288 KB |
Output is correct |
17 |
Correct |
6 ms |
1596 KB |
Output is correct |
18 |
Correct |
3 ms |
1208 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
237 ms |
30092 KB |
Output is correct |
2 |
Correct |
219 ms |
30168 KB |
Output is correct |
3 |
Correct |
215 ms |
30164 KB |
Output is correct |
4 |
Correct |
198 ms |
28884 KB |
Output is correct |
5 |
Correct |
193 ms |
29008 KB |
Output is correct |
6 |
Correct |
141 ms |
24300 KB |
Output is correct |
7 |
Correct |
206 ms |
28648 KB |
Output is correct |
8 |
Correct |
197 ms |
28680 KB |
Output is correct |
9 |
Correct |
186 ms |
28544 KB |
Output is correct |
10 |
Correct |
196 ms |
27876 KB |
Output is correct |
11 |
Correct |
174 ms |
27864 KB |
Output is correct |
12 |
Correct |
162 ms |
23524 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
237 ms |
30092 KB |
Output is correct |
2 |
Correct |
219 ms |
30168 KB |
Output is correct |
3 |
Correct |
215 ms |
30164 KB |
Output is correct |
4 |
Correct |
198 ms |
28884 KB |
Output is correct |
5 |
Correct |
193 ms |
29008 KB |
Output is correct |
6 |
Correct |
141 ms |
24300 KB |
Output is correct |
7 |
Correct |
206 ms |
28648 KB |
Output is correct |
8 |
Correct |
197 ms |
28680 KB |
Output is correct |
9 |
Correct |
186 ms |
28544 KB |
Output is correct |
10 |
Correct |
196 ms |
27876 KB |
Output is correct |
11 |
Correct |
174 ms |
27864 KB |
Output is correct |
12 |
Correct |
162 ms |
23524 KB |
Output is correct |
13 |
Correct |
262 ms |
32268 KB |
Output is correct |
14 |
Correct |
252 ms |
31448 KB |
Output is correct |
15 |
Correct |
217 ms |
28524 KB |
Output is correct |
16 |
Correct |
246 ms |
29652 KB |
Output is correct |
17 |
Correct |
245 ms |
29584 KB |
Output is correct |
18 |
Correct |
153 ms |
23512 KB |
Output is correct |
19 |
Correct |
275 ms |
32240 KB |
Output is correct |
20 |
Correct |
275 ms |
31648 KB |
Output is correct |
21 |
Correct |
265 ms |
32220 KB |
Output is correct |
22 |
Correct |
174 ms |
27860 KB |
Output is correct |
23 |
Correct |
184 ms |
27864 KB |
Output is correct |
24 |
Correct |
153 ms |
23564 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
348 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 |
6 ms |
1692 KB |
Output is correct |
8 |
Correct |
6 ms |
1716 KB |
Output is correct |
9 |
Correct |
6 ms |
1564 KB |
Output is correct |
10 |
Correct |
6 ms |
1596 KB |
Output is correct |
11 |
Correct |
6 ms |
1604 KB |
Output is correct |
12 |
Correct |
4 ms |
1196 KB |
Output is correct |
13 |
Correct |
5 ms |
1432 KB |
Output is correct |
14 |
Correct |
5 ms |
1388 KB |
Output is correct |
15 |
Correct |
6 ms |
1412 KB |
Output is correct |
16 |
Correct |
5 ms |
1288 KB |
Output is correct |
17 |
Correct |
6 ms |
1596 KB |
Output is correct |
18 |
Correct |
3 ms |
1208 KB |
Output is correct |
19 |
Correct |
237 ms |
30092 KB |
Output is correct |
20 |
Correct |
219 ms |
30168 KB |
Output is correct |
21 |
Correct |
215 ms |
30164 KB |
Output is correct |
22 |
Correct |
198 ms |
28884 KB |
Output is correct |
23 |
Correct |
193 ms |
29008 KB |
Output is correct |
24 |
Correct |
141 ms |
24300 KB |
Output is correct |
25 |
Correct |
206 ms |
28648 KB |
Output is correct |
26 |
Correct |
197 ms |
28680 KB |
Output is correct |
27 |
Correct |
186 ms |
28544 KB |
Output is correct |
28 |
Correct |
196 ms |
27876 KB |
Output is correct |
29 |
Correct |
174 ms |
27864 KB |
Output is correct |
30 |
Correct |
162 ms |
23524 KB |
Output is correct |
31 |
Correct |
262 ms |
32268 KB |
Output is correct |
32 |
Correct |
252 ms |
31448 KB |
Output is correct |
33 |
Correct |
217 ms |
28524 KB |
Output is correct |
34 |
Correct |
246 ms |
29652 KB |
Output is correct |
35 |
Correct |
245 ms |
29584 KB |
Output is correct |
36 |
Correct |
153 ms |
23512 KB |
Output is correct |
37 |
Correct |
275 ms |
32240 KB |
Output is correct |
38 |
Correct |
275 ms |
31648 KB |
Output is correct |
39 |
Correct |
265 ms |
32220 KB |
Output is correct |
40 |
Correct |
174 ms |
27860 KB |
Output is correct |
41 |
Correct |
184 ms |
27864 KB |
Output is correct |
42 |
Correct |
153 ms |
23564 KB |
Output is correct |
43 |
Correct |
303 ms |
37608 KB |
Output is correct |
44 |
Correct |
306 ms |
37632 KB |
Output is correct |
45 |
Correct |
333 ms |
37404 KB |
Output is correct |
46 |
Correct |
289 ms |
37588 KB |
Output is correct |
47 |
Correct |
314 ms |
37584 KB |
Output is correct |
48 |
Correct |
162 ms |
23536 KB |
Output is correct |
49 |
Correct |
315 ms |
37480 KB |
Output is correct |
50 |
Correct |
337 ms |
37556 KB |
Output is correct |
51 |
Correct |
327 ms |
37492 KB |
Output is correct |
52 |
Correct |
299 ms |
37612 KB |
Output is correct |
53 |
Correct |
203 ms |
30448 KB |
Output is correct |