#include<bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i = 0; i < n; i ++)
#define FOR(i,a,b) for(int i = a; i < b; i ++)
#define pii pair<int,int>
#define F first
#define S second
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
typedef tree<pii,null_type,less<pii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
const int MX = 200005;
int n,q;
pair<pii,pii> a[MX],quer[MX];
int ans[MX];
indexed_set seg[2*MX];
int SZ = 0;
void upd(int pos,pii val){
pos += SZ;
while(pos){
seg[pos].insert(val);
pos /= 2;
}
}
int query(int l,int val){
l += SZ;
int r = 2*SZ;
int res = 0;
while(l < r){
if(l%2){
res += seg[l].size()-seg[l].order_of_key({val,-1});
l++;
}
if(r%2){
--r;
res += seg[r].size()-seg[r].order_of_key({val,-1});
}
l /= 2;
r /= 2;
}
return res;
}
signed main(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin >> n >> q;
set<int> s;
map<int,int> m;
REP(i,n){
cin >> a[i].S.F >> a[i].S.S;
a[i].F.F = a[i].S.F+a[i].S.S;
a[i].F.S = i;
s.insert(a[i].S.F);
}
sort(a,a+n);
REP(i,q){
cin >> quer[i].S.F >> quer[i].S.S >> quer[i].F.F;
s.insert(quer[i].S.F);
quer[i].F.S = i;
}
sort(quer,quer+q);
for(auto x:s){
m[x] = SZ++;
}
REP(i,n) a[i].S.F = m[a[i].S.F];
REP(i,q) quer[i].S.F = m[quer[i].S.F];
int ind = n-1;
for(int i = q-1; i >= 0; i --){
while(ind >= 0 and a[ind].F.F >= quer[i].F.F){
upd(a[ind].S.F,{a[ind].S.S,a[ind].F.S});
// cout << "update :: " << a[ind].S.F << " " << a[ind].S.S << " " << a[ind].F.S << endl;
ind--;
}
ans[quer[i].F.S] = query(quer[i].S.F,quer[i].S.S);
// cout << "query :: " << quer[i].F.S << " " << quer[i].S.F << " " << quer[i].S.S << endl;
}
REP(i,q) cout << ans[i] << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
38012 KB |
Output is correct |
2 |
Correct |
38 ms |
37888 KB |
Output is correct |
3 |
Correct |
38 ms |
37888 KB |
Output is correct |
4 |
Correct |
38 ms |
37888 KB |
Output is correct |
5 |
Correct |
37 ms |
37880 KB |
Output is correct |
6 |
Correct |
37 ms |
37880 KB |
Output is correct |
7 |
Correct |
62 ms |
41336 KB |
Output is correct |
8 |
Correct |
66 ms |
41336 KB |
Output is correct |
9 |
Correct |
64 ms |
41336 KB |
Output is correct |
10 |
Correct |
62 ms |
41336 KB |
Output is correct |
11 |
Correct |
51 ms |
39036 KB |
Output is correct |
12 |
Correct |
57 ms |
39020 KB |
Output is correct |
13 |
Correct |
63 ms |
41336 KB |
Output is correct |
14 |
Correct |
64 ms |
41336 KB |
Output is correct |
15 |
Correct |
67 ms |
41340 KB |
Output is correct |
16 |
Correct |
49 ms |
38520 KB |
Output is correct |
17 |
Correct |
61 ms |
41336 KB |
Output is correct |
18 |
Correct |
48 ms |
38648 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2820 ms |
162428 KB |
Output is correct |
2 |
Correct |
2825 ms |
162296 KB |
Output is correct |
3 |
Correct |
2802 ms |
162196 KB |
Output is correct |
4 |
Correct |
1951 ms |
161556 KB |
Output is correct |
5 |
Correct |
760 ms |
72440 KB |
Output is correct |
6 |
Correct |
587 ms |
71672 KB |
Output is correct |
7 |
Correct |
2671 ms |
157516 KB |
Output is correct |
8 |
Correct |
2804 ms |
162324 KB |
Output is correct |
9 |
Correct |
2369 ms |
157692 KB |
Output is correct |
10 |
Correct |
517 ms |
56312 KB |
Output is correct |
11 |
Correct |
1582 ms |
161400 KB |
Output is correct |
12 |
Correct |
532 ms |
61440 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2820 ms |
162428 KB |
Output is correct |
2 |
Correct |
2825 ms |
162296 KB |
Output is correct |
3 |
Correct |
2802 ms |
162196 KB |
Output is correct |
4 |
Correct |
1951 ms |
161556 KB |
Output is correct |
5 |
Correct |
760 ms |
72440 KB |
Output is correct |
6 |
Correct |
587 ms |
71672 KB |
Output is correct |
7 |
Correct |
2671 ms |
157516 KB |
Output is correct |
8 |
Correct |
2804 ms |
162324 KB |
Output is correct |
9 |
Correct |
2369 ms |
157692 KB |
Output is correct |
10 |
Correct |
517 ms |
56312 KB |
Output is correct |
11 |
Correct |
1582 ms |
161400 KB |
Output is correct |
12 |
Correct |
532 ms |
61440 KB |
Output is correct |
13 |
Correct |
2806 ms |
162596 KB |
Output is correct |
14 |
Execution timed out |
3078 ms |
162624 KB |
Time limit exceeded |
15 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
38 ms |
38012 KB |
Output is correct |
2 |
Correct |
38 ms |
37888 KB |
Output is correct |
3 |
Correct |
38 ms |
37888 KB |
Output is correct |
4 |
Correct |
38 ms |
37888 KB |
Output is correct |
5 |
Correct |
37 ms |
37880 KB |
Output is correct |
6 |
Correct |
37 ms |
37880 KB |
Output is correct |
7 |
Correct |
62 ms |
41336 KB |
Output is correct |
8 |
Correct |
66 ms |
41336 KB |
Output is correct |
9 |
Correct |
64 ms |
41336 KB |
Output is correct |
10 |
Correct |
62 ms |
41336 KB |
Output is correct |
11 |
Correct |
51 ms |
39036 KB |
Output is correct |
12 |
Correct |
57 ms |
39020 KB |
Output is correct |
13 |
Correct |
63 ms |
41336 KB |
Output is correct |
14 |
Correct |
64 ms |
41336 KB |
Output is correct |
15 |
Correct |
67 ms |
41340 KB |
Output is correct |
16 |
Correct |
49 ms |
38520 KB |
Output is correct |
17 |
Correct |
61 ms |
41336 KB |
Output is correct |
18 |
Correct |
48 ms |
38648 KB |
Output is correct |
19 |
Correct |
2820 ms |
162428 KB |
Output is correct |
20 |
Correct |
2825 ms |
162296 KB |
Output is correct |
21 |
Correct |
2802 ms |
162196 KB |
Output is correct |
22 |
Correct |
1951 ms |
161556 KB |
Output is correct |
23 |
Correct |
760 ms |
72440 KB |
Output is correct |
24 |
Correct |
587 ms |
71672 KB |
Output is correct |
25 |
Correct |
2671 ms |
157516 KB |
Output is correct |
26 |
Correct |
2804 ms |
162324 KB |
Output is correct |
27 |
Correct |
2369 ms |
157692 KB |
Output is correct |
28 |
Correct |
517 ms |
56312 KB |
Output is correct |
29 |
Correct |
1582 ms |
161400 KB |
Output is correct |
30 |
Correct |
532 ms |
61440 KB |
Output is correct |
31 |
Correct |
2806 ms |
162596 KB |
Output is correct |
32 |
Execution timed out |
3078 ms |
162624 KB |
Time limit exceeded |
33 |
Halted |
0 ms |
0 KB |
- |