#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 |
4 ms |
7372 KB |
Output is correct |
2 |
Correct |
4 ms |
7372 KB |
Output is correct |
3 |
Correct |
5 ms |
7300 KB |
Output is correct |
4 |
Correct |
3 ms |
7372 KB |
Output is correct |
5 |
Correct |
3 ms |
7372 KB |
Output is correct |
6 |
Correct |
5 ms |
7372 KB |
Output is correct |
7 |
Correct |
15 ms |
8524 KB |
Output is correct |
8 |
Correct |
11 ms |
8500 KB |
Output is correct |
9 |
Correct |
12 ms |
8564 KB |
Output is correct |
10 |
Correct |
13 ms |
8268 KB |
Output is correct |
11 |
Correct |
11 ms |
8188 KB |
Output is correct |
12 |
Correct |
6 ms |
7756 KB |
Output is correct |
13 |
Correct |
10 ms |
8396 KB |
Output is correct |
14 |
Correct |
10 ms |
8396 KB |
Output is correct |
15 |
Correct |
10 ms |
8340 KB |
Output is correct |
16 |
Correct |
8 ms |
7884 KB |
Output is correct |
17 |
Correct |
8 ms |
8140 KB |
Output is correct |
18 |
Correct |
6 ms |
7756 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
272 ms |
23672 KB |
Output is correct |
2 |
Correct |
278 ms |
23680 KB |
Output is correct |
3 |
Correct |
252 ms |
23696 KB |
Output is correct |
4 |
Correct |
151 ms |
21808 KB |
Output is correct |
5 |
Correct |
186 ms |
21800 KB |
Output is correct |
6 |
Correct |
97 ms |
17440 KB |
Output is correct |
7 |
Correct |
281 ms |
23612 KB |
Output is correct |
8 |
Correct |
286 ms |
23596 KB |
Output is correct |
9 |
Correct |
227 ms |
23468 KB |
Output is correct |
10 |
Correct |
174 ms |
21144 KB |
Output is correct |
11 |
Correct |
149 ms |
21212 KB |
Output is correct |
12 |
Correct |
85 ms |
17112 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
272 ms |
23672 KB |
Output is correct |
2 |
Correct |
278 ms |
23680 KB |
Output is correct |
3 |
Correct |
252 ms |
23696 KB |
Output is correct |
4 |
Correct |
151 ms |
21808 KB |
Output is correct |
5 |
Correct |
186 ms |
21800 KB |
Output is correct |
6 |
Correct |
97 ms |
17440 KB |
Output is correct |
7 |
Correct |
281 ms |
23612 KB |
Output is correct |
8 |
Correct |
286 ms |
23596 KB |
Output is correct |
9 |
Correct |
227 ms |
23468 KB |
Output is correct |
10 |
Correct |
174 ms |
21144 KB |
Output is correct |
11 |
Correct |
149 ms |
21212 KB |
Output is correct |
12 |
Correct |
85 ms |
17112 KB |
Output is correct |
13 |
Correct |
287 ms |
24880 KB |
Output is correct |
14 |
Correct |
259 ms |
23848 KB |
Output is correct |
15 |
Correct |
289 ms |
23696 KB |
Output is correct |
16 |
Correct |
171 ms |
21840 KB |
Output is correct |
17 |
Correct |
213 ms |
21948 KB |
Output is correct |
18 |
Correct |
95 ms |
17448 KB |
Output is correct |
19 |
Correct |
287 ms |
24880 KB |
Output is correct |
20 |
Correct |
268 ms |
24236 KB |
Output is correct |
21 |
Correct |
309 ms |
24900 KB |
Output is correct |
22 |
Correct |
227 ms |
21240 KB |
Output is correct |
23 |
Correct |
147 ms |
21232 KB |
Output is correct |
24 |
Correct |
84 ms |
17048 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
7372 KB |
Output is correct |
2 |
Correct |
4 ms |
7372 KB |
Output is correct |
3 |
Correct |
5 ms |
7300 KB |
Output is correct |
4 |
Correct |
3 ms |
7372 KB |
Output is correct |
5 |
Correct |
3 ms |
7372 KB |
Output is correct |
6 |
Correct |
5 ms |
7372 KB |
Output is correct |
7 |
Correct |
15 ms |
8524 KB |
Output is correct |
8 |
Correct |
11 ms |
8500 KB |
Output is correct |
9 |
Correct |
12 ms |
8564 KB |
Output is correct |
10 |
Correct |
13 ms |
8268 KB |
Output is correct |
11 |
Correct |
11 ms |
8188 KB |
Output is correct |
12 |
Correct |
6 ms |
7756 KB |
Output is correct |
13 |
Correct |
10 ms |
8396 KB |
Output is correct |
14 |
Correct |
10 ms |
8396 KB |
Output is correct |
15 |
Correct |
10 ms |
8340 KB |
Output is correct |
16 |
Correct |
8 ms |
7884 KB |
Output is correct |
17 |
Correct |
8 ms |
8140 KB |
Output is correct |
18 |
Correct |
6 ms |
7756 KB |
Output is correct |
19 |
Correct |
272 ms |
23672 KB |
Output is correct |
20 |
Correct |
278 ms |
23680 KB |
Output is correct |
21 |
Correct |
252 ms |
23696 KB |
Output is correct |
22 |
Correct |
151 ms |
21808 KB |
Output is correct |
23 |
Correct |
186 ms |
21800 KB |
Output is correct |
24 |
Correct |
97 ms |
17440 KB |
Output is correct |
25 |
Correct |
281 ms |
23612 KB |
Output is correct |
26 |
Correct |
286 ms |
23596 KB |
Output is correct |
27 |
Correct |
227 ms |
23468 KB |
Output is correct |
28 |
Correct |
174 ms |
21144 KB |
Output is correct |
29 |
Correct |
149 ms |
21212 KB |
Output is correct |
30 |
Correct |
85 ms |
17112 KB |
Output is correct |
31 |
Correct |
287 ms |
24880 KB |
Output is correct |
32 |
Correct |
259 ms |
23848 KB |
Output is correct |
33 |
Correct |
289 ms |
23696 KB |
Output is correct |
34 |
Correct |
171 ms |
21840 KB |
Output is correct |
35 |
Correct |
213 ms |
21948 KB |
Output is correct |
36 |
Correct |
95 ms |
17448 KB |
Output is correct |
37 |
Correct |
287 ms |
24880 KB |
Output is correct |
38 |
Correct |
268 ms |
24236 KB |
Output is correct |
39 |
Correct |
309 ms |
24900 KB |
Output is correct |
40 |
Correct |
227 ms |
21240 KB |
Output is correct |
41 |
Correct |
147 ms |
21232 KB |
Output is correct |
42 |
Correct |
84 ms |
17048 KB |
Output is correct |
43 |
Correct |
633 ms |
45388 KB |
Output is correct |
44 |
Correct |
601 ms |
50428 KB |
Output is correct |
45 |
Correct |
595 ms |
50312 KB |
Output is correct |
46 |
Correct |
286 ms |
38960 KB |
Output is correct |
47 |
Correct |
367 ms |
38908 KB |
Output is correct |
48 |
Correct |
116 ms |
18344 KB |
Output is correct |
49 |
Correct |
626 ms |
50212 KB |
Output is correct |
50 |
Correct |
607 ms |
50284 KB |
Output is correct |
51 |
Correct |
621 ms |
50188 KB |
Output is correct |
52 |
Correct |
334 ms |
34584 KB |
Output is correct |
53 |
Correct |
175 ms |
29080 KB |
Output is correct |