#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define sortvec(x) sort(all(x))
#define compress(x) x.erase(unique(all(x)), x.end())
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef pair<int, LL> pil;
typedef pair<LL, int> pli;
const LL llinf=1987654321987654321;
const int inf=2000000000;
struct FENWICK{
int tree[200010];
int sum(int i){
LL ans=0;
while(i){
ans+=tree[i];
i-=(i&-i);
}
return ans;
}
void update(int i, int num){
while(i<=200000){
tree[i]+=num;
i+=(i&-i);
}
}
void cl(){memset(tree, 0, sizeof tree);}
}fen;
pair<pli, pll> query[200010];
vector<LL> idx, idy;
int ans[200010], n, q;
bool comp(pair<pli, pll> a, pair<pli, pll> b){
if(a.F.F!=b.F.F)return a.F.F>b.F.F;
return a.F.S<b.F.S;
}
vector<pll> upd;
vector<pair<pll, int> > que;
void DNC(int l, int r){
if(l==r)return;
int mid=(l+r)/2;
DNC(l, mid); DNC(mid+1, r);
upd.clear(); que.clear();
for(int i=l; i<=mid; i++){
if(!query[i].F.S)upd.pb(query[i].S);
}
for(int i=mid+1; i<=r; i++){
if(query[i].F.S)que.pb(mp(query[i].S, query[i].F.S));
}
sort(all(upd), greater<pll>());
sort(all(que), greater<pair<pll, int> >());
int pv=0;
for(auto i:que){
for(; pv<upd.size(); pv++){
if(upd[pv].F<i.F.F)break;
fen.update((int)upd[pv].S, 1);
}
ans[i.S]+=fen.sum(200000)-fen.sum(i.F.S-1);
}
for(int i=0; i<pv; i++)fen.update((int)upd[i].S, -1);
}
int main(){
scanf("%d %d", &n, &q);
for(int i=1; i<=n; i++){
scanf("%lld %lld", &query[i].F.F, &query[i].S.F);
query[i].S.S=query[i].F.F+query[i].S.F;
idx.pb(query[i].S.F);
idy.pb(query[i].S.S);
}
for(int i=n+1; i<=n+q; i++){
scanf("%lld %lld %lld", &query[i].F.F, &query[i].S.F, &query[i].S.S);
query[i].F.S=i-n;
idx.pb(query[i].S.F);
idy.pb(query[i].S.S);
}
sort(query+1, query+n+q+1, comp);
sortvec(idx); sortvec(idy);
compress(idx); compress(idy);
for(int i=1; i<=n+q; i++){
query[i].S.F=lower_bound(all(idx), query[i].S.F)-idx.begin()+1;
query[i].S.S=lower_bound(all(idy), query[i].S.S)-idy.begin()+1;
}
DNC(1, n+q);
for(int i=1; i<=q; i++)printf("%d\n", ans[i]);
}
Compilation message
examination.cpp: In function 'void DNC(int, int)':
examination.cpp:59:17: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for(; pv<upd.size(); pv++){
~~^~~~~~~~~~~
examination.cpp: In function 'int main()':
examination.cpp:68:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &n, &q);
~~~~~^~~~~~~~~~~~~~~~~
examination.cpp:70:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld", &query[i].F.F, &query[i].S.F);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:76:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld %lld", &query[i].F.F, &query[i].S.F, &query[i].S.S);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
14 ms |
888 KB |
Output is correct |
8 |
Correct |
14 ms |
888 KB |
Output is correct |
9 |
Correct |
14 ms |
888 KB |
Output is correct |
10 |
Correct |
13 ms |
888 KB |
Output is correct |
11 |
Correct |
13 ms |
888 KB |
Output is correct |
12 |
Correct |
11 ms |
888 KB |
Output is correct |
13 |
Correct |
13 ms |
888 KB |
Output is correct |
14 |
Correct |
13 ms |
888 KB |
Output is correct |
15 |
Correct |
13 ms |
888 KB |
Output is correct |
16 |
Correct |
11 ms |
888 KB |
Output is correct |
17 |
Correct |
12 ms |
888 KB |
Output is correct |
18 |
Correct |
10 ms |
760 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
355 ms |
15192 KB |
Output is correct |
2 |
Correct |
362 ms |
15268 KB |
Output is correct |
3 |
Correct |
353 ms |
14544 KB |
Output is correct |
4 |
Correct |
317 ms |
15304 KB |
Output is correct |
5 |
Correct |
304 ms |
14988 KB |
Output is correct |
6 |
Correct |
244 ms |
14800 KB |
Output is correct |
7 |
Correct |
340 ms |
15052 KB |
Output is correct |
8 |
Correct |
350 ms |
15188 KB |
Output is correct |
9 |
Correct |
323 ms |
15060 KB |
Output is correct |
10 |
Correct |
279 ms |
14800 KB |
Output is correct |
11 |
Correct |
270 ms |
14936 KB |
Output is correct |
12 |
Correct |
183 ms |
13008 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
355 ms |
15192 KB |
Output is correct |
2 |
Correct |
362 ms |
15268 KB |
Output is correct |
3 |
Correct |
353 ms |
14544 KB |
Output is correct |
4 |
Correct |
317 ms |
15304 KB |
Output is correct |
5 |
Correct |
304 ms |
14988 KB |
Output is correct |
6 |
Correct |
244 ms |
14800 KB |
Output is correct |
7 |
Correct |
340 ms |
15052 KB |
Output is correct |
8 |
Correct |
350 ms |
15188 KB |
Output is correct |
9 |
Correct |
323 ms |
15060 KB |
Output is correct |
10 |
Correct |
279 ms |
14800 KB |
Output is correct |
11 |
Correct |
270 ms |
14936 KB |
Output is correct |
12 |
Correct |
183 ms |
13008 KB |
Output is correct |
13 |
Correct |
397 ms |
15444 KB |
Output is correct |
14 |
Correct |
401 ms |
18240 KB |
Output is correct |
15 |
Correct |
355 ms |
17752 KB |
Output is correct |
16 |
Correct |
357 ms |
17488 KB |
Output is correct |
17 |
Correct |
345 ms |
17240 KB |
Output is correct |
18 |
Correct |
260 ms |
15832 KB |
Output is correct |
19 |
Correct |
408 ms |
18392 KB |
Output is correct |
20 |
Correct |
405 ms |
18256 KB |
Output is correct |
21 |
Correct |
394 ms |
19796 KB |
Output is correct |
22 |
Correct |
281 ms |
16464 KB |
Output is correct |
23 |
Correct |
268 ms |
16728 KB |
Output is correct |
24 |
Correct |
189 ms |
14032 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
5 ms |
376 KB |
Output is correct |
2 |
Correct |
5 ms |
376 KB |
Output is correct |
3 |
Correct |
5 ms |
376 KB |
Output is correct |
4 |
Correct |
5 ms |
376 KB |
Output is correct |
5 |
Correct |
5 ms |
376 KB |
Output is correct |
6 |
Correct |
5 ms |
376 KB |
Output is correct |
7 |
Correct |
14 ms |
888 KB |
Output is correct |
8 |
Correct |
14 ms |
888 KB |
Output is correct |
9 |
Correct |
14 ms |
888 KB |
Output is correct |
10 |
Correct |
13 ms |
888 KB |
Output is correct |
11 |
Correct |
13 ms |
888 KB |
Output is correct |
12 |
Correct |
11 ms |
888 KB |
Output is correct |
13 |
Correct |
13 ms |
888 KB |
Output is correct |
14 |
Correct |
13 ms |
888 KB |
Output is correct |
15 |
Correct |
13 ms |
888 KB |
Output is correct |
16 |
Correct |
11 ms |
888 KB |
Output is correct |
17 |
Correct |
12 ms |
888 KB |
Output is correct |
18 |
Correct |
10 ms |
760 KB |
Output is correct |
19 |
Correct |
355 ms |
15192 KB |
Output is correct |
20 |
Correct |
362 ms |
15268 KB |
Output is correct |
21 |
Correct |
353 ms |
14544 KB |
Output is correct |
22 |
Correct |
317 ms |
15304 KB |
Output is correct |
23 |
Correct |
304 ms |
14988 KB |
Output is correct |
24 |
Correct |
244 ms |
14800 KB |
Output is correct |
25 |
Correct |
340 ms |
15052 KB |
Output is correct |
26 |
Correct |
350 ms |
15188 KB |
Output is correct |
27 |
Correct |
323 ms |
15060 KB |
Output is correct |
28 |
Correct |
279 ms |
14800 KB |
Output is correct |
29 |
Correct |
270 ms |
14936 KB |
Output is correct |
30 |
Correct |
183 ms |
13008 KB |
Output is correct |
31 |
Correct |
397 ms |
15444 KB |
Output is correct |
32 |
Correct |
401 ms |
18240 KB |
Output is correct |
33 |
Correct |
355 ms |
17752 KB |
Output is correct |
34 |
Correct |
357 ms |
17488 KB |
Output is correct |
35 |
Correct |
345 ms |
17240 KB |
Output is correct |
36 |
Correct |
260 ms |
15832 KB |
Output is correct |
37 |
Correct |
408 ms |
18392 KB |
Output is correct |
38 |
Correct |
405 ms |
18256 KB |
Output is correct |
39 |
Correct |
394 ms |
19796 KB |
Output is correct |
40 |
Correct |
281 ms |
16464 KB |
Output is correct |
41 |
Correct |
268 ms |
16728 KB |
Output is correct |
42 |
Correct |
189 ms |
14032 KB |
Output is correct |
43 |
Correct |
427 ms |
20568 KB |
Output is correct |
44 |
Correct |
427 ms |
20564 KB |
Output is correct |
45 |
Correct |
427 ms |
20568 KB |
Output is correct |
46 |
Correct |
374 ms |
19032 KB |
Output is correct |
47 |
Correct |
369 ms |
18900 KB |
Output is correct |
48 |
Correct |
263 ms |
15704 KB |
Output is correct |
49 |
Correct |
400 ms |
20248 KB |
Output is correct |
50 |
Correct |
421 ms |
20532 KB |
Output is correct |
51 |
Correct |
394 ms |
20180 KB |
Output is correct |
52 |
Correct |
348 ms |
18648 KB |
Output is correct |
53 |
Correct |
272 ms |
17704 KB |
Output is correct |