#include<bits/stdc++.h>
using namespace std;
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<pair<int,int>,null_type,greater<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
int n,q,cate;
pair<int,int> a[100005];
int rez[100005];
pair<pair<int,pair<int,int>>,int> qrys[100005];
map<int,int> mp;
map<int,int> nrm;
bool cmp(pair<int,int> x, pair<int,int> y)
{
return x.first + x.second > y.first + y.second;
}
ordered_set aint[265000];
void upd(int nod, int st, int dr, int poz, pair<int,int> newv)
{
aint[nod].insert(newv);
if(st==dr)
return;
int mij=(st+dr)/2;
if(poz<=mij) upd(nod*2,st,mij,poz,newv);
else upd(nod*2+1,mij+1,dr,poz,newv);
}
int qry(int nod, int st, int dr, int le, int ri, int lim)
{
if(le>ri)
return 0;
if(le==st && dr==ri)
return aint[nod].order_of_key({lim,-1});
int mij=(st+dr)/2;
return qry(nod*2,st,mij,le,min(mij,ri),lim) + qry(nod*2+1,mij+1,dr,max(mij+1,le),ri,lim);
}
signed main()
{
cin>>n>>q;
for(int i=1;i<=n;i++)
{
cin>>a[i].first>>a[i].second;
mp[a[i].first]++;
}
sort(a+1,a+1+n,cmp);
for(int i=1;i<=q;i++)
{
cin>>qrys[i].first.second.first>>qrys[i].first.second.second>>qrys[i].first.first;
qrys[i].second=i;
mp[qrys[i].first.second.first]++;
}
for(auto it:mp)
nrm[it.first]=++cate;
sort(qrys+1,qrys+1+q);
int poz=1;
for(int i=q;i>0;i--)
{
while(poz<=n && a[poz].first+a[poz].second >= qrys[i].first.first)
{
///adauga poz
upd(1,1,cate,nrm[a[poz].first],{a[poz].second,poz});
poz++;
}
rez[qrys[i].second] = qry(1,1,cate,nrm[qrys[i].first.second.first],cate,qrys[i].first.second.second);
}
for(int i=1;i<=q;i++)
cout<<rez[i]<<"\n";
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
27224 KB |
Output is correct |
2 |
Correct |
18 ms |
27256 KB |
Output is correct |
3 |
Correct |
17 ms |
27228 KB |
Output is correct |
4 |
Correct |
17 ms |
27472 KB |
Output is correct |
5 |
Correct |
17 ms |
27224 KB |
Output is correct |
6 |
Correct |
17 ms |
27228 KB |
Output is correct |
7 |
Correct |
41 ms |
30612 KB |
Output is correct |
8 |
Correct |
45 ms |
30548 KB |
Output is correct |
9 |
Correct |
38 ms |
30544 KB |
Output is correct |
10 |
Correct |
37 ms |
30520 KB |
Output is correct |
11 |
Correct |
25 ms |
28252 KB |
Output is correct |
12 |
Correct |
28 ms |
28252 KB |
Output is correct |
13 |
Correct |
39 ms |
30688 KB |
Output is correct |
14 |
Correct |
37 ms |
30556 KB |
Output is correct |
15 |
Correct |
37 ms |
30600 KB |
Output is correct |
16 |
Correct |
22 ms |
27856 KB |
Output is correct |
17 |
Correct |
35 ms |
30556 KB |
Output is correct |
18 |
Correct |
22 ms |
28240 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1756 ms |
148548 KB |
Output is correct |
2 |
Correct |
1770 ms |
148968 KB |
Output is correct |
3 |
Correct |
1802 ms |
148716 KB |
Output is correct |
4 |
Correct |
932 ms |
147764 KB |
Output is correct |
5 |
Correct |
350 ms |
58704 KB |
Output is correct |
6 |
Correct |
308 ms |
58000 KB |
Output is correct |
7 |
Correct |
1638 ms |
143896 KB |
Output is correct |
8 |
Correct |
1761 ms |
148716 KB |
Output is correct |
9 |
Correct |
1668 ms |
143768 KB |
Output is correct |
10 |
Correct |
180 ms |
42576 KB |
Output is correct |
11 |
Correct |
868 ms |
147792 KB |
Output is correct |
12 |
Correct |
364 ms |
47956 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1756 ms |
148548 KB |
Output is correct |
2 |
Correct |
1770 ms |
148968 KB |
Output is correct |
3 |
Correct |
1802 ms |
148716 KB |
Output is correct |
4 |
Correct |
932 ms |
147764 KB |
Output is correct |
5 |
Correct |
350 ms |
58704 KB |
Output is correct |
6 |
Correct |
308 ms |
58000 KB |
Output is correct |
7 |
Correct |
1638 ms |
143896 KB |
Output is correct |
8 |
Correct |
1761 ms |
148716 KB |
Output is correct |
9 |
Correct |
1668 ms |
143768 KB |
Output is correct |
10 |
Correct |
180 ms |
42576 KB |
Output is correct |
11 |
Correct |
868 ms |
147792 KB |
Output is correct |
12 |
Correct |
364 ms |
47956 KB |
Output is correct |
13 |
Correct |
2626 ms |
149132 KB |
Output is correct |
14 |
Correct |
2836 ms |
149196 KB |
Output is correct |
15 |
Correct |
1966 ms |
148660 KB |
Output is correct |
16 |
Correct |
1239 ms |
148332 KB |
Output is correct |
17 |
Correct |
406 ms |
59008 KB |
Output is correct |
18 |
Correct |
312 ms |
58196 KB |
Output is correct |
19 |
Correct |
2190 ms |
149116 KB |
Output is correct |
20 |
Correct |
2380 ms |
148984 KB |
Output is correct |
21 |
Correct |
1937 ms |
147568 KB |
Output is correct |
22 |
Correct |
169 ms |
42620 KB |
Output is correct |
23 |
Correct |
887 ms |
147728 KB |
Output is correct |
24 |
Correct |
352 ms |
47820 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
17 ms |
27224 KB |
Output is correct |
2 |
Correct |
18 ms |
27256 KB |
Output is correct |
3 |
Correct |
17 ms |
27228 KB |
Output is correct |
4 |
Correct |
17 ms |
27472 KB |
Output is correct |
5 |
Correct |
17 ms |
27224 KB |
Output is correct |
6 |
Correct |
17 ms |
27228 KB |
Output is correct |
7 |
Correct |
41 ms |
30612 KB |
Output is correct |
8 |
Correct |
45 ms |
30548 KB |
Output is correct |
9 |
Correct |
38 ms |
30544 KB |
Output is correct |
10 |
Correct |
37 ms |
30520 KB |
Output is correct |
11 |
Correct |
25 ms |
28252 KB |
Output is correct |
12 |
Correct |
28 ms |
28252 KB |
Output is correct |
13 |
Correct |
39 ms |
30688 KB |
Output is correct |
14 |
Correct |
37 ms |
30556 KB |
Output is correct |
15 |
Correct |
37 ms |
30600 KB |
Output is correct |
16 |
Correct |
22 ms |
27856 KB |
Output is correct |
17 |
Correct |
35 ms |
30556 KB |
Output is correct |
18 |
Correct |
22 ms |
28240 KB |
Output is correct |
19 |
Correct |
1756 ms |
148548 KB |
Output is correct |
20 |
Correct |
1770 ms |
148968 KB |
Output is correct |
21 |
Correct |
1802 ms |
148716 KB |
Output is correct |
22 |
Correct |
932 ms |
147764 KB |
Output is correct |
23 |
Correct |
350 ms |
58704 KB |
Output is correct |
24 |
Correct |
308 ms |
58000 KB |
Output is correct |
25 |
Correct |
1638 ms |
143896 KB |
Output is correct |
26 |
Correct |
1761 ms |
148716 KB |
Output is correct |
27 |
Correct |
1668 ms |
143768 KB |
Output is correct |
28 |
Correct |
180 ms |
42576 KB |
Output is correct |
29 |
Correct |
868 ms |
147792 KB |
Output is correct |
30 |
Correct |
364 ms |
47956 KB |
Output is correct |
31 |
Correct |
2626 ms |
149132 KB |
Output is correct |
32 |
Correct |
2836 ms |
149196 KB |
Output is correct |
33 |
Correct |
1966 ms |
148660 KB |
Output is correct |
34 |
Correct |
1239 ms |
148332 KB |
Output is correct |
35 |
Correct |
406 ms |
59008 KB |
Output is correct |
36 |
Correct |
312 ms |
58196 KB |
Output is correct |
37 |
Correct |
2190 ms |
149116 KB |
Output is correct |
38 |
Correct |
2380 ms |
148984 KB |
Output is correct |
39 |
Correct |
1937 ms |
147568 KB |
Output is correct |
40 |
Correct |
169 ms |
42620 KB |
Output is correct |
41 |
Correct |
887 ms |
147728 KB |
Output is correct |
42 |
Correct |
352 ms |
47820 KB |
Output is correct |
43 |
Runtime error |
337 ms |
99664 KB |
Execution killed with signal 11 |
44 |
Halted |
0 ms |
0 KB |
- |