#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);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
10 ms |
5276 KB |
Output is correct |
8 |
Correct |
7 ms |
3368 KB |
Output is correct |
9 |
Correct |
7 ms |
5276 KB |
Output is correct |
10 |
Correct |
6 ms |
3388 KB |
Output is correct |
11 |
Correct |
6 ms |
5292 KB |
Output is correct |
12 |
Correct |
4 ms |
5044 KB |
Output is correct |
13 |
Correct |
5 ms |
3228 KB |
Output is correct |
14 |
Correct |
6 ms |
5212 KB |
Output is correct |
15 |
Correct |
5 ms |
3228 KB |
Output is correct |
16 |
Correct |
5 ms |
5180 KB |
Output is correct |
17 |
Correct |
8 ms |
5316 KB |
Output is correct |
18 |
Correct |
3 ms |
3000 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
229 ms |
31000 KB |
Output is correct |
2 |
Correct |
252 ms |
30376 KB |
Output is correct |
3 |
Correct |
263 ms |
30644 KB |
Output is correct |
4 |
Correct |
220 ms |
30420 KB |
Output is correct |
5 |
Correct |
216 ms |
30640 KB |
Output is correct |
6 |
Correct |
196 ms |
26712 KB |
Output is correct |
7 |
Correct |
226 ms |
30936 KB |
Output is correct |
8 |
Correct |
196 ms |
31380 KB |
Output is correct |
9 |
Correct |
216 ms |
31696 KB |
Output is correct |
10 |
Correct |
215 ms |
28992 KB |
Output is correct |
11 |
Correct |
193 ms |
30784 KB |
Output is correct |
12 |
Correct |
165 ms |
25464 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
229 ms |
31000 KB |
Output is correct |
2 |
Correct |
252 ms |
30376 KB |
Output is correct |
3 |
Correct |
263 ms |
30644 KB |
Output is correct |
4 |
Correct |
220 ms |
30420 KB |
Output is correct |
5 |
Correct |
216 ms |
30640 KB |
Output is correct |
6 |
Correct |
196 ms |
26712 KB |
Output is correct |
7 |
Correct |
226 ms |
30936 KB |
Output is correct |
8 |
Correct |
196 ms |
31380 KB |
Output is correct |
9 |
Correct |
216 ms |
31696 KB |
Output is correct |
10 |
Correct |
215 ms |
28992 KB |
Output is correct |
11 |
Correct |
193 ms |
30784 KB |
Output is correct |
12 |
Correct |
165 ms |
25464 KB |
Output is correct |
13 |
Correct |
294 ms |
32700 KB |
Output is correct |
14 |
Correct |
311 ms |
33644 KB |
Output is correct |
15 |
Correct |
230 ms |
30572 KB |
Output is correct |
16 |
Correct |
257 ms |
32072 KB |
Output is correct |
17 |
Correct |
259 ms |
32688 KB |
Output is correct |
18 |
Correct |
164 ms |
26804 KB |
Output is correct |
19 |
Correct |
290 ms |
34004 KB |
Output is correct |
20 |
Correct |
310 ms |
33984 KB |
Output is correct |
21 |
Correct |
284 ms |
33764 KB |
Output is correct |
22 |
Correct |
204 ms |
30012 KB |
Output is correct |
23 |
Correct |
194 ms |
30916 KB |
Output is correct |
24 |
Correct |
150 ms |
25884 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
2396 KB |
Output is correct |
6 |
Correct |
1 ms |
2396 KB |
Output is correct |
7 |
Correct |
10 ms |
5276 KB |
Output is correct |
8 |
Correct |
7 ms |
3368 KB |
Output is correct |
9 |
Correct |
7 ms |
5276 KB |
Output is correct |
10 |
Correct |
6 ms |
3388 KB |
Output is correct |
11 |
Correct |
6 ms |
5292 KB |
Output is correct |
12 |
Correct |
4 ms |
5044 KB |
Output is correct |
13 |
Correct |
5 ms |
3228 KB |
Output is correct |
14 |
Correct |
6 ms |
5212 KB |
Output is correct |
15 |
Correct |
5 ms |
3228 KB |
Output is correct |
16 |
Correct |
5 ms |
5180 KB |
Output is correct |
17 |
Correct |
8 ms |
5316 KB |
Output is correct |
18 |
Correct |
3 ms |
3000 KB |
Output is correct |
19 |
Correct |
229 ms |
31000 KB |
Output is correct |
20 |
Correct |
252 ms |
30376 KB |
Output is correct |
21 |
Correct |
263 ms |
30644 KB |
Output is correct |
22 |
Correct |
220 ms |
30420 KB |
Output is correct |
23 |
Correct |
216 ms |
30640 KB |
Output is correct |
24 |
Correct |
196 ms |
26712 KB |
Output is correct |
25 |
Correct |
226 ms |
30936 KB |
Output is correct |
26 |
Correct |
196 ms |
31380 KB |
Output is correct |
27 |
Correct |
216 ms |
31696 KB |
Output is correct |
28 |
Correct |
215 ms |
28992 KB |
Output is correct |
29 |
Correct |
193 ms |
30784 KB |
Output is correct |
30 |
Correct |
165 ms |
25464 KB |
Output is correct |
31 |
Correct |
294 ms |
32700 KB |
Output is correct |
32 |
Correct |
311 ms |
33644 KB |
Output is correct |
33 |
Correct |
230 ms |
30572 KB |
Output is correct |
34 |
Correct |
257 ms |
32072 KB |
Output is correct |
35 |
Correct |
259 ms |
32688 KB |
Output is correct |
36 |
Correct |
164 ms |
26804 KB |
Output is correct |
37 |
Correct |
290 ms |
34004 KB |
Output is correct |
38 |
Correct |
310 ms |
33984 KB |
Output is correct |
39 |
Correct |
284 ms |
33764 KB |
Output is correct |
40 |
Correct |
204 ms |
30012 KB |
Output is correct |
41 |
Correct |
194 ms |
30916 KB |
Output is correct |
42 |
Correct |
150 ms |
25884 KB |
Output is correct |
43 |
Correct |
320 ms |
38680 KB |
Output is correct |
44 |
Correct |
328 ms |
39000 KB |
Output is correct |
45 |
Correct |
309 ms |
38540 KB |
Output is correct |
46 |
Correct |
277 ms |
38644 KB |
Output is correct |
47 |
Correct |
273 ms |
38100 KB |
Output is correct |
48 |
Correct |
169 ms |
26744 KB |
Output is correct |
49 |
Correct |
278 ms |
38684 KB |
Output is correct |
50 |
Correct |
292 ms |
39396 KB |
Output is correct |
51 |
Correct |
282 ms |
38628 KB |
Output is correct |
52 |
Correct |
267 ms |
38620 KB |
Output is correct |
53 |
Correct |
189 ms |
31220 KB |
Output is correct |