#include <bits/stdc++.h>
using namespace std;
#define rep(i,s,e) for (int i = s; i <= e; ++i)
#define rrep(i,s,e) for (int i = s; i >= e; --i)
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define aint(a) a.begin(), a.end()
#define len(a) (int)a.size()
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<int> vint;
const int mx = 4e5;
int ftree[mx+1][2];
void upd (int tp, int val, int x) {
while (x <= mx) {
ftree[x][tp] += val;
x += x&(-x);
}
}
int pref (int tp, int x) {
int sum = 0;
while (x>0) {
sum += ftree[x][tp];
x -= x&(-x);
}
return sum;
}
int query (int tp, int l, int r) {
return pref(tp, r)-pref(tp, l-1);
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n, q, x = 1; cin >> n >> q;
vector<pair<int,ii>> peep;
vector<pair<ii,ii>> ques;
set<int> sta, stb;
int ans[q+1];
rep (i,1,n) {
int a, b; cin >> a >> b;
peep.pb({a+b,{a,b}});
sta.insert(a);
stb.insert(b);
}
rep (i,1,q) {
int a, b, c; cin >> a >> b >> c;
ques.pb({{max(a+b,c),i},{a,b}});
sta.insert(a);
stb.insert(b);
}
map<int,int> mpa, mpb;
for (int a : sta) mpa[a] = x++;
x = 1;
for (int b : stb) mpb[b] = x++;
x = 0;
sort(aint(ques));
reverse(aint(ques));
sort(aint(peep));
reverse(aint(peep));
rep (i,0,q-1) {
int c = ques[i].fi.fi, a = mpa[ques[i].se.fi], b = mpb[ques[i].se.se], u = ques[i].fi.se;
while (x < n && peep[x].fi>=c) {
upd (0, 1, mpa[peep[x].se.fi]);
upd (1, 1, mpb[peep[x].se.se]);
x++;
}
ans[u] = query(0,a,mx) + query(1,b,mx) - x;
}
rep (i,1,q) cout << ans[i] << "\n";
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
9 ms |
1620 KB |
Output is correct |
8 |
Correct |
10 ms |
1572 KB |
Output is correct |
9 |
Correct |
10 ms |
1644 KB |
Output is correct |
10 |
Correct |
7 ms |
1040 KB |
Output is correct |
11 |
Correct |
6 ms |
980 KB |
Output is correct |
12 |
Correct |
4 ms |
508 KB |
Output is correct |
13 |
Correct |
12 ms |
1620 KB |
Output is correct |
14 |
Correct |
11 ms |
1636 KB |
Output is correct |
15 |
Correct |
9 ms |
1632 KB |
Output is correct |
16 |
Correct |
5 ms |
980 KB |
Output is correct |
17 |
Correct |
5 ms |
980 KB |
Output is correct |
18 |
Correct |
3 ms |
468 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
360 ms |
21056 KB |
Output is correct |
2 |
Correct |
394 ms |
21028 KB |
Output is correct |
3 |
Correct |
368 ms |
20912 KB |
Output is correct |
4 |
Correct |
205 ms |
12772 KB |
Output is correct |
5 |
Correct |
155 ms |
12752 KB |
Output is correct |
6 |
Correct |
74 ms |
5040 KB |
Output is correct |
7 |
Correct |
293 ms |
19156 KB |
Output is correct |
8 |
Correct |
329 ms |
19136 KB |
Output is correct |
9 |
Correct |
326 ms |
17336 KB |
Output is correct |
10 |
Correct |
156 ms |
12656 KB |
Output is correct |
11 |
Correct |
161 ms |
12644 KB |
Output is correct |
12 |
Correct |
75 ms |
4896 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
360 ms |
21056 KB |
Output is correct |
2 |
Correct |
394 ms |
21028 KB |
Output is correct |
3 |
Correct |
368 ms |
20912 KB |
Output is correct |
4 |
Correct |
205 ms |
12772 KB |
Output is correct |
5 |
Correct |
155 ms |
12752 KB |
Output is correct |
6 |
Correct |
74 ms |
5040 KB |
Output is correct |
7 |
Correct |
293 ms |
19156 KB |
Output is correct |
8 |
Correct |
329 ms |
19136 KB |
Output is correct |
9 |
Correct |
326 ms |
17336 KB |
Output is correct |
10 |
Correct |
156 ms |
12656 KB |
Output is correct |
11 |
Correct |
161 ms |
12644 KB |
Output is correct |
12 |
Correct |
75 ms |
4896 KB |
Output is correct |
13 |
Correct |
406 ms |
20928 KB |
Output is correct |
14 |
Correct |
432 ms |
20992 KB |
Output is correct |
15 |
Correct |
370 ms |
20852 KB |
Output is correct |
16 |
Correct |
195 ms |
12752 KB |
Output is correct |
17 |
Correct |
184 ms |
12956 KB |
Output is correct |
18 |
Correct |
74 ms |
5040 KB |
Output is correct |
19 |
Correct |
388 ms |
21136 KB |
Output is correct |
20 |
Correct |
350 ms |
20996 KB |
Output is correct |
21 |
Correct |
316 ms |
19472 KB |
Output is correct |
22 |
Correct |
198 ms |
12660 KB |
Output is correct |
23 |
Correct |
138 ms |
12608 KB |
Output is correct |
24 |
Correct |
71 ms |
4924 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
340 KB |
Output is correct |
2 |
Correct |
0 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
0 ms |
340 KB |
Output is correct |
7 |
Correct |
9 ms |
1620 KB |
Output is correct |
8 |
Correct |
10 ms |
1572 KB |
Output is correct |
9 |
Correct |
10 ms |
1644 KB |
Output is correct |
10 |
Correct |
7 ms |
1040 KB |
Output is correct |
11 |
Correct |
6 ms |
980 KB |
Output is correct |
12 |
Correct |
4 ms |
508 KB |
Output is correct |
13 |
Correct |
12 ms |
1620 KB |
Output is correct |
14 |
Correct |
11 ms |
1636 KB |
Output is correct |
15 |
Correct |
9 ms |
1632 KB |
Output is correct |
16 |
Correct |
5 ms |
980 KB |
Output is correct |
17 |
Correct |
5 ms |
980 KB |
Output is correct |
18 |
Correct |
3 ms |
468 KB |
Output is correct |
19 |
Correct |
360 ms |
21056 KB |
Output is correct |
20 |
Correct |
394 ms |
21028 KB |
Output is correct |
21 |
Correct |
368 ms |
20912 KB |
Output is correct |
22 |
Correct |
205 ms |
12772 KB |
Output is correct |
23 |
Correct |
155 ms |
12752 KB |
Output is correct |
24 |
Correct |
74 ms |
5040 KB |
Output is correct |
25 |
Correct |
293 ms |
19156 KB |
Output is correct |
26 |
Correct |
329 ms |
19136 KB |
Output is correct |
27 |
Correct |
326 ms |
17336 KB |
Output is correct |
28 |
Correct |
156 ms |
12656 KB |
Output is correct |
29 |
Correct |
161 ms |
12644 KB |
Output is correct |
30 |
Correct |
75 ms |
4896 KB |
Output is correct |
31 |
Correct |
406 ms |
20928 KB |
Output is correct |
32 |
Correct |
432 ms |
20992 KB |
Output is correct |
33 |
Correct |
370 ms |
20852 KB |
Output is correct |
34 |
Correct |
195 ms |
12752 KB |
Output is correct |
35 |
Correct |
184 ms |
12956 KB |
Output is correct |
36 |
Correct |
74 ms |
5040 KB |
Output is correct |
37 |
Correct |
388 ms |
21136 KB |
Output is correct |
38 |
Correct |
350 ms |
20996 KB |
Output is correct |
39 |
Correct |
316 ms |
19472 KB |
Output is correct |
40 |
Correct |
198 ms |
12660 KB |
Output is correct |
41 |
Correct |
138 ms |
12608 KB |
Output is correct |
42 |
Correct |
71 ms |
4924 KB |
Output is correct |
43 |
Correct |
709 ms |
43156 KB |
Output is correct |
44 |
Correct |
689 ms |
48180 KB |
Output is correct |
45 |
Correct |
690 ms |
48176 KB |
Output is correct |
46 |
Correct |
267 ms |
27688 KB |
Output is correct |
47 |
Correct |
278 ms |
27608 KB |
Output is correct |
48 |
Correct |
77 ms |
5956 KB |
Output is correct |
49 |
Correct |
677 ms |
47928 KB |
Output is correct |
50 |
Correct |
712 ms |
47968 KB |
Output is correct |
51 |
Correct |
623 ms |
47828 KB |
Output is correct |
52 |
Correct |
293 ms |
27604 KB |
Output is correct |
53 |
Correct |
249 ms |
26636 KB |
Output is correct |