#include <bits/stdc++.h>
#pragma GCC target("sse,sse2,avx2")
#pragma GCC optimize("unroll-loops,O2")
#define rep(i,l,r) for (int i = l; i < r; i++)
#define repr(i,r,l) for (int i = r; i >= l; i--)
#define X first
#define Y second
#define all(x) (x).begin() , (x).end()
#define pb push_back
#define endl '\n'
#define debug(x) cerr << #x << " : " << x << endl;
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pll;
constexpr int N = 1e5+10,mod = 998244353,inf = 1e9+10,sq = 700;
inline int mkay(int a,int b){
if (a+b >= mod) return a+b-mod;
if (a+b < 0) return a+b+mod;
return a+b;
}
inline int poww(int a,int k){
if (k < 0) return 0;
int z = 1;
while (k){
if (k&1) z = 1ll*z*a%mod;
a = 1ll*a*a%mod;
k /= 2;
}
return z;
}
int a[N],b[N],ans[N],ind[N],c[N];
ordered_set seg[N*4];
pair<pll,pll> Q[N];
vector<int> vec,vea;
bool cmpc(int i,int j){
return (c[i] > c[j]);
}
bool cmpa(int i,int j){
return (a[i] < a[j]);
}
void upd(int l,int r,int p,int v = 1){
seg[v].insert(b[vea[p]]);
if (r-l == 1) return;
int m = (l+r) >> 1,u = (v << 1);
if (p < m) upd(l,m,p,u);
else upd(m,r,p,u|1);
}
int que(int l,int r,int s,int e,int B,int v = 1){
if (seg[v].empty() || l >= e || s >= r) return 0;
if (s <= l && r <= e){
return seg[v].size()-seg[v].order_of_key(B);
}
int m = (l+r) >> 1,u = (v << 1);
return que(l,m,s,e,B,u)+que(m,r,s,e,B,u|1);
}
int main(){
ios :: sync_with_stdio(0); cin.tie(0);
int n,q;
cin >> n >> q;
vector<pll> ub;
rep(i,0,n){
cin >> a[i] >> b[i];
c[i] = a[i]+b[i];
vec.pb(i);
vea.pb(i);
ub.pb({b[i],i});
}
sort(all(vec),cmpc);
sort(all(vea),cmpa);
rep(i,0,n) ind[vea[i]] = i;
rep(i,0,q){
cin >> Q[i].Y.X >> Q[i].Y.Y >> Q[i].X.X;
Q[i].X.Y = i;
ub.pb({Q[i].Y.Y,-n-i});
}
sort(all(ub));
rep(i,0,n+q){
if(ub[i].Y >= 0){
b[ub[i].Y] = i;
}
else{
Q[-ub[i].Y-n].Y.Y = i;
}
}
sort(Q,Q+q);
reverse(Q,Q+q);
int po = 0;
rep(i,0,q){
int C = Q[i].X.X,A = Q[i].Y.X,B = Q[i].Y.Y;
while (po < n && c[vec[po]] >= C){
upd(0,n,ind[vec[po]],1);
po++;
}
int l = -1,r = n,m;
while (r-l > 1){
m = (l+r) >> 1;
if (A <= a[vea[m]]) r = m;
else l = m;
}
ans[Q[i].X.Y] = que(0,n,r,n,B);
}
rep(i,0,q) cout << ans[i] << endl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
31572 KB |
Output is correct |
2 |
Correct |
28 ms |
31572 KB |
Output is correct |
3 |
Correct |
27 ms |
31596 KB |
Output is correct |
4 |
Correct |
25 ms |
31568 KB |
Output is correct |
5 |
Correct |
26 ms |
31572 KB |
Output is correct |
6 |
Correct |
25 ms |
31636 KB |
Output is correct |
7 |
Correct |
44 ms |
33692 KB |
Output is correct |
8 |
Correct |
40 ms |
33720 KB |
Output is correct |
9 |
Correct |
38 ms |
33780 KB |
Output is correct |
10 |
Correct |
47 ms |
33736 KB |
Output is correct |
11 |
Correct |
36 ms |
33724 KB |
Output is correct |
12 |
Correct |
36 ms |
33588 KB |
Output is correct |
13 |
Correct |
39 ms |
33684 KB |
Output is correct |
14 |
Correct |
38 ms |
33644 KB |
Output is correct |
15 |
Correct |
39 ms |
33748 KB |
Output is correct |
16 |
Correct |
35 ms |
33588 KB |
Output is correct |
17 |
Correct |
36 ms |
33748 KB |
Output is correct |
18 |
Correct |
42 ms |
33612 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1929 ms |
123708 KB |
Output is correct |
2 |
Correct |
1846 ms |
123652 KB |
Output is correct |
3 |
Correct |
1865 ms |
123644 KB |
Output is correct |
4 |
Correct |
1111 ms |
122812 KB |
Output is correct |
5 |
Correct |
1538 ms |
122868 KB |
Output is correct |
6 |
Correct |
1229 ms |
122080 KB |
Output is correct |
7 |
Correct |
1753 ms |
123464 KB |
Output is correct |
8 |
Correct |
1771 ms |
123548 KB |
Output is correct |
9 |
Correct |
1490 ms |
123632 KB |
Output is correct |
10 |
Correct |
1294 ms |
122656 KB |
Output is correct |
11 |
Correct |
977 ms |
122788 KB |
Output is correct |
12 |
Correct |
570 ms |
121804 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1929 ms |
123708 KB |
Output is correct |
2 |
Correct |
1846 ms |
123652 KB |
Output is correct |
3 |
Correct |
1865 ms |
123644 KB |
Output is correct |
4 |
Correct |
1111 ms |
122812 KB |
Output is correct |
5 |
Correct |
1538 ms |
122868 KB |
Output is correct |
6 |
Correct |
1229 ms |
122080 KB |
Output is correct |
7 |
Correct |
1753 ms |
123464 KB |
Output is correct |
8 |
Correct |
1771 ms |
123548 KB |
Output is correct |
9 |
Correct |
1490 ms |
123632 KB |
Output is correct |
10 |
Correct |
1294 ms |
122656 KB |
Output is correct |
11 |
Correct |
977 ms |
122788 KB |
Output is correct |
12 |
Correct |
570 ms |
121804 KB |
Output is correct |
13 |
Correct |
1720 ms |
124008 KB |
Output is correct |
14 |
Correct |
1876 ms |
124104 KB |
Output is correct |
15 |
Correct |
1856 ms |
123536 KB |
Output is correct |
16 |
Correct |
1067 ms |
123256 KB |
Output is correct |
17 |
Correct |
1490 ms |
123420 KB |
Output is correct |
18 |
Correct |
1231 ms |
122116 KB |
Output is correct |
19 |
Correct |
1698 ms |
124152 KB |
Output is correct |
20 |
Correct |
1763 ms |
124032 KB |
Output is correct |
21 |
Correct |
1581 ms |
124056 KB |
Output is correct |
22 |
Correct |
1248 ms |
122696 KB |
Output is correct |
23 |
Correct |
986 ms |
122644 KB |
Output is correct |
24 |
Correct |
563 ms |
121748 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
26 ms |
31572 KB |
Output is correct |
2 |
Correct |
28 ms |
31572 KB |
Output is correct |
3 |
Correct |
27 ms |
31596 KB |
Output is correct |
4 |
Correct |
25 ms |
31568 KB |
Output is correct |
5 |
Correct |
26 ms |
31572 KB |
Output is correct |
6 |
Correct |
25 ms |
31636 KB |
Output is correct |
7 |
Correct |
44 ms |
33692 KB |
Output is correct |
8 |
Correct |
40 ms |
33720 KB |
Output is correct |
9 |
Correct |
38 ms |
33780 KB |
Output is correct |
10 |
Correct |
47 ms |
33736 KB |
Output is correct |
11 |
Correct |
36 ms |
33724 KB |
Output is correct |
12 |
Correct |
36 ms |
33588 KB |
Output is correct |
13 |
Correct |
39 ms |
33684 KB |
Output is correct |
14 |
Correct |
38 ms |
33644 KB |
Output is correct |
15 |
Correct |
39 ms |
33748 KB |
Output is correct |
16 |
Correct |
35 ms |
33588 KB |
Output is correct |
17 |
Correct |
36 ms |
33748 KB |
Output is correct |
18 |
Correct |
42 ms |
33612 KB |
Output is correct |
19 |
Correct |
1929 ms |
123708 KB |
Output is correct |
20 |
Correct |
1846 ms |
123652 KB |
Output is correct |
21 |
Correct |
1865 ms |
123644 KB |
Output is correct |
22 |
Correct |
1111 ms |
122812 KB |
Output is correct |
23 |
Correct |
1538 ms |
122868 KB |
Output is correct |
24 |
Correct |
1229 ms |
122080 KB |
Output is correct |
25 |
Correct |
1753 ms |
123464 KB |
Output is correct |
26 |
Correct |
1771 ms |
123548 KB |
Output is correct |
27 |
Correct |
1490 ms |
123632 KB |
Output is correct |
28 |
Correct |
1294 ms |
122656 KB |
Output is correct |
29 |
Correct |
977 ms |
122788 KB |
Output is correct |
30 |
Correct |
570 ms |
121804 KB |
Output is correct |
31 |
Correct |
1720 ms |
124008 KB |
Output is correct |
32 |
Correct |
1876 ms |
124104 KB |
Output is correct |
33 |
Correct |
1856 ms |
123536 KB |
Output is correct |
34 |
Correct |
1067 ms |
123256 KB |
Output is correct |
35 |
Correct |
1490 ms |
123420 KB |
Output is correct |
36 |
Correct |
1231 ms |
122116 KB |
Output is correct |
37 |
Correct |
1698 ms |
124152 KB |
Output is correct |
38 |
Correct |
1763 ms |
124032 KB |
Output is correct |
39 |
Correct |
1581 ms |
124056 KB |
Output is correct |
40 |
Correct |
1248 ms |
122696 KB |
Output is correct |
41 |
Correct |
986 ms |
122644 KB |
Output is correct |
42 |
Correct |
563 ms |
121748 KB |
Output is correct |
43 |
Correct |
1721 ms |
125948 KB |
Output is correct |
44 |
Correct |
1684 ms |
126016 KB |
Output is correct |
45 |
Correct |
1900 ms |
126012 KB |
Output is correct |
46 |
Correct |
1107 ms |
124340 KB |
Output is correct |
47 |
Correct |
1570 ms |
124444 KB |
Output is correct |
48 |
Correct |
1145 ms |
121932 KB |
Output is correct |
49 |
Correct |
1652 ms |
125924 KB |
Output is correct |
50 |
Correct |
1543 ms |
125944 KB |
Output is correct |
51 |
Correct |
1452 ms |
125804 KB |
Output is correct |
52 |
Correct |
1235 ms |
124256 KB |
Output is correct |
53 |
Correct |
1006 ms |
123408 KB |
Output is correct |