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>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
mt19937 mrand(random_device{}());
const ll mod=1000000007;
const ll mod2=998244353;
int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
const int N=601000;
int n,q,s[N],t[N],x[N],y[N],z[N],q1,q2,ans[N];
struct st {
int x,y,z,id;
}c1[N],c2[N];
struct fenwick {
int n,c[N];
void modify(int x,int y) {
for (;x<N;x+=x&-x) c[x]+=y;
}
int query(int x) {
int res=0;
for (--x;x;x-=x&-x) res+=c[x];
return res;
}
};
int main() {
VI v;
scanf("%d%d",&n,&q);
rep(i,1,n+1) scanf("%d%d",s+i,t+i),v.pb(s[i]),v.pb(t[i]),v.pb(s[i]+t[i]);
rep(i,1,q+1) scanf("%d%d%d",x+i,y+i,z+i),v.pb(x[i]),v.pb(y[i]),v.pb(z[i]);
sort(all(v));
v.erase(unique(all(v)),v.end());
map<int,int> val;
rep(i,0,SZ(v)) val[v[i]]=i+1;
rep(i,1,q+1) {
if (z[i]<=x[i]+y[i]) c1[++q1]={x[i],y[i],z[i],i};
else c2[++q2]={x[i],y[i],z[i],i};
}
rep(i,1,n+1) c1[++q1]={s[i],t[i],0,0};
rep(i,1,n+1) c2[++q2]={s[i],t[i],s[i]+t[i],0};
sort(c1+1,c1+q1+1,[&](st A,st B) { if (A.x!=B.x) return A.x>B.x; return A.id<B.id; });
sort(c2+1,c2+q2+1,[&](st A,st B) { if (A.z!=B.z) return A.z>B.z; return A.id<B.id; });
fenwick ds;
int cnt=0;
rep(i,1,q1+1) {
if (c1[i].id==0) {
cnt++;
ds.modify(val[c1[i].y],1);
} else {
ans[c1[i].id]=cnt-ds.query(val[c1[i].y]);
}
}
cnt=0;
fenwick ds1,ds2;
rep(i,1,q2+1) {
if (c2[i].id==0) {
cnt++;
ds1.modify(val[c2[i].x],1);
ds2.modify(val[c2[i].y],1);
} else {
ans[c2[i].id]=cnt-ds1.query(val[c2[i].x])-ds2.query(val[c2[i].y]);
}
}
rep(i,1,q+1) printf("%d\n",ans[i]);
}
Compilation message (stderr)
examination.cpp: In function 'int main()':
examination.cpp:44:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
44 | scanf("%d%d",&n,&q);
| ~~~~~^~~~~~~~~~~~~~
examination.cpp:45:20: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
45 | rep(i,1,n+1) scanf("%d%d",s+i,t+i),v.pb(s[i]),v.pb(t[i]),v.pb(s[i]+t[i]);
| ~~~~~^~~~~~~~~~~~~~~~
examination.cpp:46:20: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
46 | rep(i,1,q+1) scanf("%d%d%d",x+i,y+i,z+i),v.pb(x[i]),v.pb(y[i]),v.pb(z[i]);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~
# | 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... |