// __________________
// | ________________ |
// || ____ ||
// || /\ | ||
// || /__\ | ||
// || / \ |____ ||
// ||________________||
// |__________________|
// \\#################\\
// \\#################\\
// \ ____ \
// \_______\___\_______\
// An AC a day keeps the doctor away.
#pragma GCC optimize("Ofast")
#pragma loop_opt(on)
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define debug(x) (cerr<<#x<<" = "<<(x)<<'\n')
#define all(v) begin(v),end(v)
#define siz(v) (ll(v.size()))
#define get_pos(v,x) (lower_bound(all(v),x)-begin(v))
#define pb emplace_back
#define ff first
#define ss second
#define mid (l+(r-l>>1))
using namespace std;
using namespace __gnu_pbds;
typedef int64_t ll;
typedef long double ld;
typedef pair<ll,ll> pll;
template <typename T> using rkt = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
constexpr ld PI = acos(-1), eps = 1e-9;
constexpr ll N = 200800, INF = 1e18, MOD = 998244353, K = 102425;
constexpr inline ll cdiv(ll x, ll m) { return (x+m-1)/m; } // ceiling divide, x/m for flooring divide
template <typename T> void M(T &x, ll m = MOD){x%=m; if(x<0) x+=m;}
struct Query{
ll k,x,y,z;
} Q[N];
ll v[N],b[N],ans[N];
void add(int p, ll d) {
for(; p < N; p += p&-p) b[p] += d;
}
ll qry(int p) {
ll r = 0;
for(; p > 0; p -= p&-p) r += b[p];
return r;
}
void merges(int l,int m,int r) {
auto cmp = [](int a, int b){return Q[a].y != Q[b].y ? Q[a].y < Q[b].y : a<b;};
vector<int> tmp;
for(int i = l, j = m; i<m || j<r; ) {
if(j==r || (i<m && cmp(v[i],v[j]))) {
auto &q = Q[v[i]];
if(q.k == 0) add(q.z,1);
tmp.pb(v[i++]);
}else {
auto &q = Q[v[j]];
if(q.k == 1) ans[v[j]] += qry(q.z);
tmp.pb(v[j++]);
}
}
for(int i = l; i < m; i++) if(Q[v[i]].k == 0) add(Q[v[i]].z,-1);
for(int i = l; i < r; i++) v[i] = tmp[i-l];
}
void CDQ(int l, int r) {
if(l+1 == r) return;
CDQ(l,mid), CDQ(mid,r);
merges(l,mid,r);
}
signed main() {
ios_base::sync_with_stdio(0), cin.tie(0);
ll n,q,x,y,z,p = 0;
cin >> n >> q;
for(int i = 0; i < n; i++) {
cin >> x >> y, z = x+y;
Q[p++] = {0,-x,-y,-z};
}
for(int i = 0; i < q; i++) {
cin >> x >> y >> z;
Q[p++] = {1,-x,-y,-z};
}
vector<ll> u;
for(int i = 0; i < p; i++) u.pb(Q[i].z);
sort(all(u)), u.erase(unique(all(u)),u.end());
for(int i = 0; i < p; i++) Q[i].z = get_pos(u,Q[i].z)+1;
iota(v,v+p,0);
sort(v,v+p,[](int a, int b){return Q[a].x!=Q[b].x ? Q[a].x < Q[b].x : a<b;});
CDQ(0,p);
for(int i = 0; i < q; i++) cout << ans[i+n] << '\n';
/*
for(int i = 0; i < p; i++) if(Q[i].k == 1) {
auto &p = Q[i];
int ans = 0;
for(int j = 0; j < i; j++) {
auto &q = Q[j];
if(q.k == 0 && q.x >= p.x && q.y >= p.y && q.z >= p.z) ans++;
}
cout << ans << '\n';
}
*/
}
Compilation message
examination.cpp:9:1: warning: multi-line comment [-Wcomment]
// \\#################\\
^
examination.cpp:16:0: warning: ignoring #pragma loop_opt [-Wunknown-pragmas]
#pragma loop_opt(on)
examination.cpp: In function 'void CDQ(int, int)':
examination.cpp:27:18: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
#define mid (l+(r-l>>1))
~^~
examination.cpp:71:11: note: in expansion of macro 'mid'
CDQ(l,mid), CDQ(mid,r);
^~~
examination.cpp:27:18: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
#define mid (l+(r-l>>1))
~^~
examination.cpp:71:21: note: in expansion of macro 'mid'
CDQ(l,mid), CDQ(mid,r);
^~~
examination.cpp:27:18: warning: suggest parentheses around '-' inside '>>' [-Wparentheses]
#define mid (l+(r-l>>1))
~^~
examination.cpp:72:14: note: in expansion of macro 'mid'
merges(l,mid,r);
^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
388 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
380 KB |
Output is correct |
7 |
Correct |
11 ms |
1020 KB |
Output is correct |
8 |
Correct |
11 ms |
888 KB |
Output is correct |
9 |
Correct |
11 ms |
1016 KB |
Output is correct |
10 |
Correct |
10 ms |
888 KB |
Output is correct |
11 |
Correct |
10 ms |
888 KB |
Output is correct |
12 |
Correct |
9 ms |
760 KB |
Output is correct |
13 |
Correct |
11 ms |
888 KB |
Output is correct |
14 |
Correct |
10 ms |
888 KB |
Output is correct |
15 |
Correct |
10 ms |
888 KB |
Output is correct |
16 |
Correct |
9 ms |
928 KB |
Output is correct |
17 |
Correct |
10 ms |
888 KB |
Output is correct |
18 |
Correct |
7 ms |
760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
384 ms |
15572 KB |
Output is correct |
2 |
Correct |
376 ms |
15460 KB |
Output is correct |
3 |
Correct |
379 ms |
15524 KB |
Output is correct |
4 |
Correct |
350 ms |
14640 KB |
Output is correct |
5 |
Correct |
328 ms |
14640 KB |
Output is correct |
6 |
Correct |
263 ms |
13416 KB |
Output is correct |
7 |
Correct |
355 ms |
15496 KB |
Output is correct |
8 |
Correct |
363 ms |
15432 KB |
Output is correct |
9 |
Correct |
349 ms |
15288 KB |
Output is correct |
10 |
Correct |
292 ms |
14636 KB |
Output is correct |
11 |
Correct |
314 ms |
14568 KB |
Output is correct |
12 |
Correct |
242 ms |
13420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
384 ms |
15572 KB |
Output is correct |
2 |
Correct |
376 ms |
15460 KB |
Output is correct |
3 |
Correct |
379 ms |
15524 KB |
Output is correct |
4 |
Correct |
350 ms |
14640 KB |
Output is correct |
5 |
Correct |
328 ms |
14640 KB |
Output is correct |
6 |
Correct |
263 ms |
13416 KB |
Output is correct |
7 |
Correct |
355 ms |
15496 KB |
Output is correct |
8 |
Correct |
363 ms |
15432 KB |
Output is correct |
9 |
Correct |
349 ms |
15288 KB |
Output is correct |
10 |
Correct |
292 ms |
14636 KB |
Output is correct |
11 |
Correct |
314 ms |
14568 KB |
Output is correct |
12 |
Correct |
242 ms |
13420 KB |
Output is correct |
13 |
Correct |
474 ms |
16480 KB |
Output is correct |
14 |
Correct |
437 ms |
16236 KB |
Output is correct |
15 |
Correct |
396 ms |
15464 KB |
Output is correct |
16 |
Correct |
390 ms |
15200 KB |
Output is correct |
17 |
Correct |
375 ms |
15180 KB |
Output is correct |
18 |
Correct |
296 ms |
13564 KB |
Output is correct |
19 |
Correct |
449 ms |
16236 KB |
Output is correct |
20 |
Correct |
445 ms |
16332 KB |
Output is correct |
21 |
Correct |
408 ms |
16232 KB |
Output is correct |
22 |
Correct |
304 ms |
14696 KB |
Output is correct |
23 |
Correct |
316 ms |
14696 KB |
Output is correct |
24 |
Correct |
239 ms |
13416 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
388 KB |
Output is correct |
3 |
Correct |
2 ms |
376 KB |
Output is correct |
4 |
Correct |
2 ms |
376 KB |
Output is correct |
5 |
Correct |
2 ms |
376 KB |
Output is correct |
6 |
Correct |
2 ms |
380 KB |
Output is correct |
7 |
Correct |
11 ms |
1020 KB |
Output is correct |
8 |
Correct |
11 ms |
888 KB |
Output is correct |
9 |
Correct |
11 ms |
1016 KB |
Output is correct |
10 |
Correct |
10 ms |
888 KB |
Output is correct |
11 |
Correct |
10 ms |
888 KB |
Output is correct |
12 |
Correct |
9 ms |
760 KB |
Output is correct |
13 |
Correct |
11 ms |
888 KB |
Output is correct |
14 |
Correct |
10 ms |
888 KB |
Output is correct |
15 |
Correct |
10 ms |
888 KB |
Output is correct |
16 |
Correct |
9 ms |
928 KB |
Output is correct |
17 |
Correct |
10 ms |
888 KB |
Output is correct |
18 |
Correct |
7 ms |
760 KB |
Output is correct |
19 |
Correct |
384 ms |
15572 KB |
Output is correct |
20 |
Correct |
376 ms |
15460 KB |
Output is correct |
21 |
Correct |
379 ms |
15524 KB |
Output is correct |
22 |
Correct |
350 ms |
14640 KB |
Output is correct |
23 |
Correct |
328 ms |
14640 KB |
Output is correct |
24 |
Correct |
263 ms |
13416 KB |
Output is correct |
25 |
Correct |
355 ms |
15496 KB |
Output is correct |
26 |
Correct |
363 ms |
15432 KB |
Output is correct |
27 |
Correct |
349 ms |
15288 KB |
Output is correct |
28 |
Correct |
292 ms |
14636 KB |
Output is correct |
29 |
Correct |
314 ms |
14568 KB |
Output is correct |
30 |
Correct |
242 ms |
13420 KB |
Output is correct |
31 |
Correct |
474 ms |
16480 KB |
Output is correct |
32 |
Correct |
437 ms |
16236 KB |
Output is correct |
33 |
Correct |
396 ms |
15464 KB |
Output is correct |
34 |
Correct |
390 ms |
15200 KB |
Output is correct |
35 |
Correct |
375 ms |
15180 KB |
Output is correct |
36 |
Correct |
296 ms |
13564 KB |
Output is correct |
37 |
Correct |
449 ms |
16236 KB |
Output is correct |
38 |
Correct |
445 ms |
16332 KB |
Output is correct |
39 |
Correct |
408 ms |
16232 KB |
Output is correct |
40 |
Correct |
304 ms |
14696 KB |
Output is correct |
41 |
Correct |
316 ms |
14696 KB |
Output is correct |
42 |
Correct |
239 ms |
13416 KB |
Output is correct |
43 |
Correct |
453 ms |
18792 KB |
Output is correct |
44 |
Correct |
491 ms |
18800 KB |
Output is correct |
45 |
Correct |
461 ms |
18952 KB |
Output is correct |
46 |
Correct |
406 ms |
17448 KB |
Output is correct |
47 |
Correct |
393 ms |
17264 KB |
Output is correct |
48 |
Correct |
286 ms |
13544 KB |
Output is correct |
49 |
Correct |
416 ms |
18592 KB |
Output is correct |
50 |
Correct |
480 ms |
18692 KB |
Output is correct |
51 |
Correct |
423 ms |
18536 KB |
Output is correct |
52 |
Correct |
357 ms |
17288 KB |
Output is correct |
53 |
Correct |
319 ms |
15724 KB |
Output is correct |