#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxn = 100000;
void build(ll tl, ll tr, ll v, multiset<ll> t[]){
multiset<ll> temp;
if (tl==tr){
t[v] = temp;
}
else{
t[v] = temp;
ll tm = (tl+tr)>>1;
build(tl,tm,v*2,t);
build(tm+1,tr,v*2+1,t);
}
}
ll query(ll v, ll tl, ll tr, ll l, ll r,multiset<ll> t[], ll c){
if (tr<l||tl>r) return 0;
if (tl>=l&&tr<=r){
return t[v].size()-distance(t[v].begin(),t[v].lower_bound(c));
}
ll tm = (tl+tr)>>1;
return query(v*2,tl,tm,l,r,t,c)+query(v*2+1,tm+1,tr,l,r,t,c);
}
void update(ll v, ll tl, ll tr, ll l, ll x, multiset<ll> t[]){
t[v].insert(x);
ll tm = (tl+tr)>>1;
if (l<=tm) {
if (tl==tr) return;
else update(v*2,tl,tm,l,x,t);
}
else update(v*2+1,tm+1,tr,l,x,t);
}
int main(){
ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll n;
cin >> n;
ll q;
cin >> q;
vector<pair<ll,pair<ll,ll>>> aa;
for (int i=0;i<n;i++){
ll s,t;
cin >> s >> t;
aa.push_back({s,{t,s+t}});
}
sort(aa.begin(),aa.end());
multiset<ll> t[n*4];
build(0,n-1,1,t);
priority_queue<pair<pair<ll,ll>,pair<ll,ll>>> pq;
for (int i=0;i<aa.size();i++){
pq.push({{aa[i].second.first,i},{aa[i].first,aa[i].second.second}});
}
vector<pair<pair<ll,ll>,pair<ll,ll>>> aaa;
ll cont = 0;
ll ans[q+5];
ll q2 = q;
while (q--){
ll x,y,z;
cin >> x >> y >> z;
aaa.push_back({{y,cont},{x,z}});
cont++;
}
sort(aaa.begin(),aaa.end());
for (int i=aaa.size()-1;i>=0;i--){
ll x = aaa[i].second.first;
ll z = aaa[i].second.second;
ll y = aaa[i].first.first;
pair<ll,pair<ll,ll>> temp = {x,{-1,-1}};
ll ind = lower_bound(aa.begin(),aa.end(),temp)-aa.begin();
while (!pq.empty() && pq.top().first.first >= y){
update(1,0,n-1,pq.top().first.second,pq.top().second.second,t);
pq.pop();
}
ans[aaa[i].first.second] = query(1,0,n-1,ind,n-1,t,z);
}
for (int i=0;i<q2;i++){
cout << ans[i] << "\n";
}
}
Compilation message
examination.cpp: In function 'int main()':
examination.cpp:57:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, std::pair<long long int, long long int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | for (int i=0;i<aa.size();i++){
| ~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
16 ms |
3252 KB |
Output is correct |
8 |
Correct |
19 ms |
3164 KB |
Output is correct |
9 |
Correct |
18 ms |
3164 KB |
Output is correct |
10 |
Correct |
14 ms |
3052 KB |
Output is correct |
11 |
Correct |
15 ms |
3164 KB |
Output is correct |
12 |
Correct |
14 ms |
2904 KB |
Output is correct |
13 |
Correct |
8 ms |
3164 KB |
Output is correct |
14 |
Correct |
12 ms |
3084 KB |
Output is correct |
15 |
Correct |
9 ms |
3164 KB |
Output is correct |
16 |
Correct |
6 ms |
2932 KB |
Output is correct |
17 |
Correct |
14 ms |
3160 KB |
Output is correct |
18 |
Correct |
11 ms |
2908 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
847 ms |
114736 KB |
Output is correct |
2 |
Correct |
820 ms |
114732 KB |
Output is correct |
3 |
Correct |
905 ms |
115500 KB |
Output is correct |
4 |
Correct |
509 ms |
115500 KB |
Output is correct |
5 |
Correct |
481 ms |
113968 KB |
Output is correct |
6 |
Correct |
324 ms |
114216 KB |
Output is correct |
7 |
Correct |
851 ms |
115012 KB |
Output is correct |
8 |
Correct |
874 ms |
114648 KB |
Output is correct |
9 |
Correct |
853 ms |
114960 KB |
Output is correct |
10 |
Correct |
364 ms |
113824 KB |
Output is correct |
11 |
Correct |
472 ms |
113972 KB |
Output is correct |
12 |
Correct |
353 ms |
114420 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
847 ms |
114736 KB |
Output is correct |
2 |
Correct |
820 ms |
114732 KB |
Output is correct |
3 |
Correct |
905 ms |
115500 KB |
Output is correct |
4 |
Correct |
509 ms |
115500 KB |
Output is correct |
5 |
Correct |
481 ms |
113968 KB |
Output is correct |
6 |
Correct |
324 ms |
114216 KB |
Output is correct |
7 |
Correct |
851 ms |
115012 KB |
Output is correct |
8 |
Correct |
874 ms |
114648 KB |
Output is correct |
9 |
Correct |
853 ms |
114960 KB |
Output is correct |
10 |
Correct |
364 ms |
113824 KB |
Output is correct |
11 |
Correct |
472 ms |
113972 KB |
Output is correct |
12 |
Correct |
353 ms |
114420 KB |
Output is correct |
13 |
Execution timed out |
3068 ms |
65476 KB |
Time limit exceeded |
14 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
1 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
348 KB |
Output is correct |
7 |
Correct |
16 ms |
3252 KB |
Output is correct |
8 |
Correct |
19 ms |
3164 KB |
Output is correct |
9 |
Correct |
18 ms |
3164 KB |
Output is correct |
10 |
Correct |
14 ms |
3052 KB |
Output is correct |
11 |
Correct |
15 ms |
3164 KB |
Output is correct |
12 |
Correct |
14 ms |
2904 KB |
Output is correct |
13 |
Correct |
8 ms |
3164 KB |
Output is correct |
14 |
Correct |
12 ms |
3084 KB |
Output is correct |
15 |
Correct |
9 ms |
3164 KB |
Output is correct |
16 |
Correct |
6 ms |
2932 KB |
Output is correct |
17 |
Correct |
14 ms |
3160 KB |
Output is correct |
18 |
Correct |
11 ms |
2908 KB |
Output is correct |
19 |
Correct |
847 ms |
114736 KB |
Output is correct |
20 |
Correct |
820 ms |
114732 KB |
Output is correct |
21 |
Correct |
905 ms |
115500 KB |
Output is correct |
22 |
Correct |
509 ms |
115500 KB |
Output is correct |
23 |
Correct |
481 ms |
113968 KB |
Output is correct |
24 |
Correct |
324 ms |
114216 KB |
Output is correct |
25 |
Correct |
851 ms |
115012 KB |
Output is correct |
26 |
Correct |
874 ms |
114648 KB |
Output is correct |
27 |
Correct |
853 ms |
114960 KB |
Output is correct |
28 |
Correct |
364 ms |
113824 KB |
Output is correct |
29 |
Correct |
472 ms |
113972 KB |
Output is correct |
30 |
Correct |
353 ms |
114420 KB |
Output is correct |
31 |
Execution timed out |
3068 ms |
65476 KB |
Time limit exceeded |
32 |
Halted |
0 ms |
0 KB |
- |