#include <iostream>
#include <algorithm>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <map>
using namespace std;
using namespace __gnu_pbds;
map<int,int> comp;
pair<int,int> arr[100005];
int x[100005],y[100005],z[100005],p[100005],ans[100005];
bool cmp(int a,int b)
{
return x[a]>x[b];
}
tree<int,null_type,greater_equal<int>,rb_tree_tag,tree_order_statistics_node_update> s[800005];
void update(int node,int st,int en,int idx,int val)
{
s[node].insert(val);
if (st!=en)
{
int mid=(st+en)/2;
if (st<=idx && idx<=mid)
update(2*node,st,mid,idx,val);
else
update(2*node+1,mid+1,en,idx,val);
}
}
int query(int node,int st,int en,int l,int r,int val)
{
if (en<l || st>r || r<l)
return 0;
if (l<=st && en<=r)
return s[node].order_of_key(val-1);
int mid=(st+en)/2;
return query(2*node,st,mid,l,r,val)+query(2*node+1,mid+1,en,l,r,val);
}
int main()
{
int n,q;
scanf("%d%d",&n,&q);
for (int i=0;i<n;i++)
{
scanf("%d%d",&arr[i].first,&arr[i].second);
comp[arr[i].second];
}
for (int i=0;i<q;i++)
{
scanf("%d%d%d",&x[i],&y[i],&z[i]);
p[i]=i;
comp[y[i]];
}
int cur=0;
for (auto &l:comp)
l.second=cur++;
sort(p,p+q,cmp);
sort(arr,arr+n);
int idx=n-1;
for (int i=0;i<q;i++)
{
while (idx>=0 && arr[idx].first>=x[p[i]])
{
update(1,0,cur-1,comp[arr[idx].second],arr[idx].first+arr[idx].second);
idx--;
}
ans[p[i]]=query(1,0,cur-1,comp[y[p[i]]],cur-1,z[p[i]]);
}
for (int i=0;i<q;i++)
printf("%d\n",ans[i]);
}
Compilation message
examination.cpp: In function 'int main()':
examination.cpp:40:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&n,&q);
~~~~~^~~~~~~~~~~~~~
examination.cpp:43:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&arr[i].first,&arr[i].second);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
examination.cpp:48:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d%d",&x[i],&y[i],&z[i]);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
88 ms |
62968 KB |
Output is correct |
2 |
Correct |
88 ms |
62904 KB |
Output is correct |
3 |
Correct |
89 ms |
63096 KB |
Output is correct |
4 |
Correct |
103 ms |
62968 KB |
Output is correct |
5 |
Correct |
88 ms |
62968 KB |
Output is correct |
6 |
Correct |
88 ms |
62968 KB |
Output is correct |
7 |
Correct |
122 ms |
65292 KB |
Output is correct |
8 |
Correct |
111 ms |
65348 KB |
Output is correct |
9 |
Correct |
111 ms |
65244 KB |
Output is correct |
10 |
Correct |
96 ms |
63744 KB |
Output is correct |
11 |
Correct |
107 ms |
65272 KB |
Output is correct |
12 |
Correct |
94 ms |
63740 KB |
Output is correct |
13 |
Correct |
111 ms |
65228 KB |
Output is correct |
14 |
Correct |
125 ms |
65400 KB |
Output is correct |
15 |
Correct |
111 ms |
65276 KB |
Output is correct |
16 |
Correct |
104 ms |
65260 KB |
Output is correct |
17 |
Correct |
93 ms |
63356 KB |
Output is correct |
18 |
Correct |
92 ms |
63480 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2330 ms |
152552 KB |
Output is correct |
2 |
Correct |
2292 ms |
152696 KB |
Output is correct |
3 |
Correct |
2313 ms |
152576 KB |
Output is correct |
4 |
Correct |
483 ms |
87672 KB |
Output is correct |
5 |
Correct |
1426 ms |
152608 KB |
Output is correct |
6 |
Correct |
394 ms |
87672 KB |
Output is correct |
7 |
Correct |
2496 ms |
152696 KB |
Output is correct |
8 |
Correct |
2190 ms |
149624 KB |
Output is correct |
9 |
Correct |
2166 ms |
149484 KB |
Output is correct |
10 |
Correct |
1251 ms |
152432 KB |
Output is correct |
11 |
Correct |
330 ms |
75488 KB |
Output is correct |
12 |
Correct |
334 ms |
79964 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2330 ms |
152552 KB |
Output is correct |
2 |
Correct |
2292 ms |
152696 KB |
Output is correct |
3 |
Correct |
2313 ms |
152576 KB |
Output is correct |
4 |
Correct |
483 ms |
87672 KB |
Output is correct |
5 |
Correct |
1426 ms |
152608 KB |
Output is correct |
6 |
Correct |
394 ms |
87672 KB |
Output is correct |
7 |
Correct |
2496 ms |
152696 KB |
Output is correct |
8 |
Correct |
2190 ms |
149624 KB |
Output is correct |
9 |
Correct |
2166 ms |
149484 KB |
Output is correct |
10 |
Correct |
1251 ms |
152432 KB |
Output is correct |
11 |
Correct |
330 ms |
75488 KB |
Output is correct |
12 |
Correct |
334 ms |
79964 KB |
Output is correct |
13 |
Correct |
2455 ms |
152508 KB |
Output is correct |
14 |
Correct |
2378 ms |
152572 KB |
Output is correct |
15 |
Correct |
2309 ms |
152436 KB |
Output is correct |
16 |
Correct |
543 ms |
87672 KB |
Output is correct |
17 |
Correct |
1430 ms |
152568 KB |
Output is correct |
18 |
Correct |
396 ms |
87744 KB |
Output is correct |
19 |
Correct |
2410 ms |
152580 KB |
Output is correct |
20 |
Correct |
2628 ms |
152584 KB |
Output is correct |
21 |
Correct |
2555 ms |
151636 KB |
Output is correct |
22 |
Correct |
1259 ms |
152312 KB |
Output is correct |
23 |
Correct |
318 ms |
75504 KB |
Output is correct |
24 |
Correct |
374 ms |
80120 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
88 ms |
62968 KB |
Output is correct |
2 |
Correct |
88 ms |
62904 KB |
Output is correct |
3 |
Correct |
89 ms |
63096 KB |
Output is correct |
4 |
Correct |
103 ms |
62968 KB |
Output is correct |
5 |
Correct |
88 ms |
62968 KB |
Output is correct |
6 |
Correct |
88 ms |
62968 KB |
Output is correct |
7 |
Correct |
122 ms |
65292 KB |
Output is correct |
8 |
Correct |
111 ms |
65348 KB |
Output is correct |
9 |
Correct |
111 ms |
65244 KB |
Output is correct |
10 |
Correct |
96 ms |
63744 KB |
Output is correct |
11 |
Correct |
107 ms |
65272 KB |
Output is correct |
12 |
Correct |
94 ms |
63740 KB |
Output is correct |
13 |
Correct |
111 ms |
65228 KB |
Output is correct |
14 |
Correct |
125 ms |
65400 KB |
Output is correct |
15 |
Correct |
111 ms |
65276 KB |
Output is correct |
16 |
Correct |
104 ms |
65260 KB |
Output is correct |
17 |
Correct |
93 ms |
63356 KB |
Output is correct |
18 |
Correct |
92 ms |
63480 KB |
Output is correct |
19 |
Correct |
2330 ms |
152552 KB |
Output is correct |
20 |
Correct |
2292 ms |
152696 KB |
Output is correct |
21 |
Correct |
2313 ms |
152576 KB |
Output is correct |
22 |
Correct |
483 ms |
87672 KB |
Output is correct |
23 |
Correct |
1426 ms |
152608 KB |
Output is correct |
24 |
Correct |
394 ms |
87672 KB |
Output is correct |
25 |
Correct |
2496 ms |
152696 KB |
Output is correct |
26 |
Correct |
2190 ms |
149624 KB |
Output is correct |
27 |
Correct |
2166 ms |
149484 KB |
Output is correct |
28 |
Correct |
1251 ms |
152432 KB |
Output is correct |
29 |
Correct |
330 ms |
75488 KB |
Output is correct |
30 |
Correct |
334 ms |
79964 KB |
Output is correct |
31 |
Correct |
2455 ms |
152508 KB |
Output is correct |
32 |
Correct |
2378 ms |
152572 KB |
Output is correct |
33 |
Correct |
2309 ms |
152436 KB |
Output is correct |
34 |
Correct |
543 ms |
87672 KB |
Output is correct |
35 |
Correct |
1430 ms |
152568 KB |
Output is correct |
36 |
Correct |
396 ms |
87744 KB |
Output is correct |
37 |
Correct |
2410 ms |
152580 KB |
Output is correct |
38 |
Correct |
2628 ms |
152584 KB |
Output is correct |
39 |
Correct |
2555 ms |
151636 KB |
Output is correct |
40 |
Correct |
1259 ms |
152312 KB |
Output is correct |
41 |
Correct |
318 ms |
75504 KB |
Output is correct |
42 |
Correct |
374 ms |
80120 KB |
Output is correct |
43 |
Correct |
2745 ms |
163520 KB |
Output is correct |
44 |
Correct |
2733 ms |
163576 KB |
Output is correct |
45 |
Correct |
2578 ms |
163480 KB |
Output is correct |
46 |
Correct |
544 ms |
87672 KB |
Output is correct |
47 |
Correct |
1586 ms |
163448 KB |
Output is correct |
48 |
Correct |
381 ms |
87416 KB |
Output is correct |
49 |
Correct |
2765 ms |
163556 KB |
Output is correct |
50 |
Correct |
2505 ms |
163552 KB |
Output is correct |
51 |
Correct |
2622 ms |
163704 KB |
Output is correct |
52 |
Correct |
1387 ms |
163448 KB |
Output is correct |
53 |
Correct |
323 ms |
75488 KB |
Output is correct |