#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
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 |
1 |
Correct |
5 ms |
21852 KB |
Output is correct |
2 |
Correct |
5 ms |
21852 KB |
Output is correct |
3 |
Correct |
6 ms |
21852 KB |
Output is correct |
4 |
Correct |
5 ms |
21852 KB |
Output is correct |
5 |
Correct |
5 ms |
21852 KB |
Output is correct |
6 |
Correct |
5 ms |
21852 KB |
Output is correct |
7 |
Correct |
12 ms |
22868 KB |
Output is correct |
8 |
Correct |
12 ms |
22804 KB |
Output is correct |
9 |
Correct |
12 ms |
22872 KB |
Output is correct |
10 |
Correct |
10 ms |
22360 KB |
Output is correct |
11 |
Correct |
10 ms |
22360 KB |
Output is correct |
12 |
Correct |
8 ms |
22108 KB |
Output is correct |
13 |
Correct |
11 ms |
22492 KB |
Output is correct |
14 |
Correct |
12 ms |
22620 KB |
Output is correct |
15 |
Correct |
12 ms |
22620 KB |
Output is correct |
16 |
Correct |
9 ms |
22108 KB |
Output is correct |
17 |
Correct |
9 ms |
22364 KB |
Output is correct |
18 |
Correct |
7 ms |
22108 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
215 ms |
38336 KB |
Output is correct |
2 |
Correct |
206 ms |
37460 KB |
Output is correct |
3 |
Correct |
206 ms |
37304 KB |
Output is correct |
4 |
Correct |
133 ms |
36160 KB |
Output is correct |
5 |
Correct |
162 ms |
35616 KB |
Output is correct |
6 |
Correct |
82 ms |
31160 KB |
Output is correct |
7 |
Correct |
212 ms |
38604 KB |
Output is correct |
8 |
Correct |
204 ms |
38052 KB |
Output is correct |
9 |
Correct |
192 ms |
37648 KB |
Output is correct |
10 |
Correct |
156 ms |
35256 KB |
Output is correct |
11 |
Correct |
125 ms |
35440 KB |
Output is correct |
12 |
Correct |
73 ms |
30796 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
215 ms |
38336 KB |
Output is correct |
2 |
Correct |
206 ms |
37460 KB |
Output is correct |
3 |
Correct |
206 ms |
37304 KB |
Output is correct |
4 |
Correct |
133 ms |
36160 KB |
Output is correct |
5 |
Correct |
162 ms |
35616 KB |
Output is correct |
6 |
Correct |
82 ms |
31160 KB |
Output is correct |
7 |
Correct |
212 ms |
38604 KB |
Output is correct |
8 |
Correct |
204 ms |
38052 KB |
Output is correct |
9 |
Correct |
192 ms |
37648 KB |
Output is correct |
10 |
Correct |
156 ms |
35256 KB |
Output is correct |
11 |
Correct |
125 ms |
35440 KB |
Output is correct |
12 |
Correct |
73 ms |
30796 KB |
Output is correct |
13 |
Correct |
230 ms |
39608 KB |
Output is correct |
14 |
Correct |
229 ms |
39528 KB |
Output is correct |
15 |
Correct |
210 ms |
41424 KB |
Output is correct |
16 |
Correct |
149 ms |
39356 KB |
Output is correct |
17 |
Correct |
173 ms |
38324 KB |
Output is correct |
18 |
Correct |
84 ms |
31156 KB |
Output is correct |
19 |
Correct |
237 ms |
42564 KB |
Output is correct |
20 |
Correct |
234 ms |
38776 KB |
Output is correct |
21 |
Correct |
238 ms |
41732 KB |
Output is correct |
22 |
Correct |
151 ms |
36764 KB |
Output is correct |
23 |
Correct |
125 ms |
37304 KB |
Output is correct |
24 |
Correct |
73 ms |
31740 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
21852 KB |
Output is correct |
2 |
Correct |
5 ms |
21852 KB |
Output is correct |
3 |
Correct |
6 ms |
21852 KB |
Output is correct |
4 |
Correct |
5 ms |
21852 KB |
Output is correct |
5 |
Correct |
5 ms |
21852 KB |
Output is correct |
6 |
Correct |
5 ms |
21852 KB |
Output is correct |
7 |
Correct |
12 ms |
22868 KB |
Output is correct |
8 |
Correct |
12 ms |
22804 KB |
Output is correct |
9 |
Correct |
12 ms |
22872 KB |
Output is correct |
10 |
Correct |
10 ms |
22360 KB |
Output is correct |
11 |
Correct |
10 ms |
22360 KB |
Output is correct |
12 |
Correct |
8 ms |
22108 KB |
Output is correct |
13 |
Correct |
11 ms |
22492 KB |
Output is correct |
14 |
Correct |
12 ms |
22620 KB |
Output is correct |
15 |
Correct |
12 ms |
22620 KB |
Output is correct |
16 |
Correct |
9 ms |
22108 KB |
Output is correct |
17 |
Correct |
9 ms |
22364 KB |
Output is correct |
18 |
Correct |
7 ms |
22108 KB |
Output is correct |
19 |
Correct |
215 ms |
38336 KB |
Output is correct |
20 |
Correct |
206 ms |
37460 KB |
Output is correct |
21 |
Correct |
206 ms |
37304 KB |
Output is correct |
22 |
Correct |
133 ms |
36160 KB |
Output is correct |
23 |
Correct |
162 ms |
35616 KB |
Output is correct |
24 |
Correct |
82 ms |
31160 KB |
Output is correct |
25 |
Correct |
212 ms |
38604 KB |
Output is correct |
26 |
Correct |
204 ms |
38052 KB |
Output is correct |
27 |
Correct |
192 ms |
37648 KB |
Output is correct |
28 |
Correct |
156 ms |
35256 KB |
Output is correct |
29 |
Correct |
125 ms |
35440 KB |
Output is correct |
30 |
Correct |
73 ms |
30796 KB |
Output is correct |
31 |
Correct |
230 ms |
39608 KB |
Output is correct |
32 |
Correct |
229 ms |
39528 KB |
Output is correct |
33 |
Correct |
210 ms |
41424 KB |
Output is correct |
34 |
Correct |
149 ms |
39356 KB |
Output is correct |
35 |
Correct |
173 ms |
38324 KB |
Output is correct |
36 |
Correct |
84 ms |
31156 KB |
Output is correct |
37 |
Correct |
237 ms |
42564 KB |
Output is correct |
38 |
Correct |
234 ms |
38776 KB |
Output is correct |
39 |
Correct |
238 ms |
41732 KB |
Output is correct |
40 |
Correct |
151 ms |
36764 KB |
Output is correct |
41 |
Correct |
125 ms |
37304 KB |
Output is correct |
42 |
Correct |
73 ms |
31740 KB |
Output is correct |
43 |
Correct |
432 ms |
65772 KB |
Output is correct |
44 |
Correct |
444 ms |
64056 KB |
Output is correct |
45 |
Correct |
429 ms |
62648 KB |
Output is correct |
46 |
Correct |
216 ms |
53824 KB |
Output is correct |
47 |
Correct |
281 ms |
54400 KB |
Output is correct |
48 |
Correct |
87 ms |
33208 KB |
Output is correct |
49 |
Correct |
421 ms |
65016 KB |
Output is correct |
50 |
Correct |
455 ms |
64684 KB |
Output is correct |
51 |
Correct |
445 ms |
65680 KB |
Output is correct |
52 |
Correct |
247 ms |
49864 KB |
Output is correct |
53 |
Correct |
153 ms |
42716 KB |
Output is correct |