This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |