#include <bits/stdc++.h>
#define pb push_back
#define f first
#define sc second
using namespace std;
typedef long long int ll;
typedef string str;
const int inf = 1e9;
struct BIT{
int n;
vector<int> sm;
BIT(int _n){
n = _n;
sm.resize(n);
}
void add(int in, int x){
in++;
while(in <= n) sm[in-1]+=x, in+=in&-in;
}
int sum(int in){
in++;
int s = 0;
while(in >= 1) s+=sm[in-1], in-=in&-in;
return s;
}
int sum(int l, int r){
return sum(r)-(l == 0? 0:sum(l-1));
}
};
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, q; cin >> n >> q;
vector<tuple<int, int, int, int>> S;
for(int i = 0; i < n; i++){
int s, t; cin >> s >> t;
S.push_back({s, t, s+t, inf});
}
for(int i = 0; i < q; i++){
int a, b, c; cin >> a >> b >> c;
S.push_back({a, b, c, i});
}
sort(S.begin(), S.end());
int m = S.size();
{
vector<int> srt;
for(auto [_0, _1, x, _2]: S) srt.push_back(x);
sort(srt.begin(), srt.end());
map<int, int> mp;
for(int i = 0; i < m; i++) mp[srt[i]] = i;
for(auto &[_0, _1, x, _2]: S) x = mp[x];
}
BIT bit(m);
vector<int> ans(q, 0);
function<void(int, int)> cdq = [&](int l, int r){
if(l == r) return;
int md = (l+r)/2;
cdq(l, md);
cdq(md+1, r);
vector<tuple<int, int, int>> cur;
for(int i = l; i <= md; i++){
auto [a, b, c, in] = S[i];
if(in < inf) cur.push_back({b, in, c});
}
for(int i = md+1; i <= r; i++){
auto [a, b, c, in] = S[i];
if(in == inf) cur.push_back({b, in, c});
}
sort(cur.rbegin(), cur.rend());
for(auto [b, in, c]: cur){
if(in == inf) bit.add(c, 1);
else ans[in]+=bit.sum(c, m-1);
}
for(auto [b, in, c]: cur){
if(in == inf) bit.add(c, -1);
}
};
cdq(0, m-1);
for(int x: ans) cout << x << "\n";
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
6 ms |
856 KB |
Output is correct |
8 |
Correct |
6 ms |
856 KB |
Output is correct |
9 |
Correct |
6 ms |
856 KB |
Output is correct |
10 |
Correct |
7 ms |
860 KB |
Output is correct |
11 |
Correct |
5 ms |
860 KB |
Output is correct |
12 |
Correct |
4 ms |
604 KB |
Output is correct |
13 |
Correct |
5 ms |
860 KB |
Output is correct |
14 |
Correct |
5 ms |
860 KB |
Output is correct |
15 |
Correct |
5 ms |
860 KB |
Output is correct |
16 |
Correct |
3 ms |
600 KB |
Output is correct |
17 |
Correct |
5 ms |
860 KB |
Output is correct |
18 |
Correct |
3 ms |
604 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
232 ms |
11308 KB |
Output is correct |
2 |
Correct |
230 ms |
10944 KB |
Output is correct |
3 |
Correct |
231 ms |
10944 KB |
Output is correct |
4 |
Correct |
235 ms |
10896 KB |
Output is correct |
5 |
Correct |
168 ms |
10940 KB |
Output is correct |
6 |
Correct |
109 ms |
9216 KB |
Output is correct |
7 |
Correct |
217 ms |
12476 KB |
Output is correct |
8 |
Correct |
218 ms |
11264 KB |
Output is correct |
9 |
Correct |
218 ms |
13808 KB |
Output is correct |
10 |
Correct |
170 ms |
10460 KB |
Output is correct |
11 |
Correct |
179 ms |
10684 KB |
Output is correct |
12 |
Correct |
91 ms |
7360 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
232 ms |
11308 KB |
Output is correct |
2 |
Correct |
230 ms |
10944 KB |
Output is correct |
3 |
Correct |
231 ms |
10944 KB |
Output is correct |
4 |
Correct |
235 ms |
10896 KB |
Output is correct |
5 |
Correct |
168 ms |
10940 KB |
Output is correct |
6 |
Correct |
109 ms |
9216 KB |
Output is correct |
7 |
Correct |
217 ms |
12476 KB |
Output is correct |
8 |
Correct |
218 ms |
11264 KB |
Output is correct |
9 |
Correct |
218 ms |
13808 KB |
Output is correct |
10 |
Correct |
170 ms |
10460 KB |
Output is correct |
11 |
Correct |
179 ms |
10684 KB |
Output is correct |
12 |
Correct |
91 ms |
7360 KB |
Output is correct |
13 |
Correct |
280 ms |
14268 KB |
Output is correct |
14 |
Correct |
252 ms |
13136 KB |
Output is correct |
15 |
Correct |
225 ms |
11084 KB |
Output is correct |
16 |
Correct |
245 ms |
11192 KB |
Output is correct |
17 |
Correct |
195 ms |
11196 KB |
Output is correct |
18 |
Correct |
120 ms |
8892 KB |
Output is correct |
19 |
Correct |
268 ms |
13760 KB |
Output is correct |
20 |
Correct |
253 ms |
14112 KB |
Output is correct |
21 |
Correct |
257 ms |
14816 KB |
Output is correct |
22 |
Correct |
137 ms |
10856 KB |
Output is correct |
23 |
Correct |
174 ms |
10688 KB |
Output is correct |
24 |
Correct |
82 ms |
7608 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
348 KB |
Output is correct |
2 |
Correct |
0 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Correct |
0 ms |
344 KB |
Output is correct |
5 |
Correct |
0 ms |
348 KB |
Output is correct |
6 |
Correct |
0 ms |
344 KB |
Output is correct |
7 |
Correct |
6 ms |
856 KB |
Output is correct |
8 |
Correct |
6 ms |
856 KB |
Output is correct |
9 |
Correct |
6 ms |
856 KB |
Output is correct |
10 |
Correct |
7 ms |
860 KB |
Output is correct |
11 |
Correct |
5 ms |
860 KB |
Output is correct |
12 |
Correct |
4 ms |
604 KB |
Output is correct |
13 |
Correct |
5 ms |
860 KB |
Output is correct |
14 |
Correct |
5 ms |
860 KB |
Output is correct |
15 |
Correct |
5 ms |
860 KB |
Output is correct |
16 |
Correct |
3 ms |
600 KB |
Output is correct |
17 |
Correct |
5 ms |
860 KB |
Output is correct |
18 |
Correct |
3 ms |
604 KB |
Output is correct |
19 |
Correct |
232 ms |
11308 KB |
Output is correct |
20 |
Correct |
230 ms |
10944 KB |
Output is correct |
21 |
Correct |
231 ms |
10944 KB |
Output is correct |
22 |
Correct |
235 ms |
10896 KB |
Output is correct |
23 |
Correct |
168 ms |
10940 KB |
Output is correct |
24 |
Correct |
109 ms |
9216 KB |
Output is correct |
25 |
Correct |
217 ms |
12476 KB |
Output is correct |
26 |
Correct |
218 ms |
11264 KB |
Output is correct |
27 |
Correct |
218 ms |
13808 KB |
Output is correct |
28 |
Correct |
170 ms |
10460 KB |
Output is correct |
29 |
Correct |
179 ms |
10684 KB |
Output is correct |
30 |
Correct |
91 ms |
7360 KB |
Output is correct |
31 |
Correct |
280 ms |
14268 KB |
Output is correct |
32 |
Correct |
252 ms |
13136 KB |
Output is correct |
33 |
Correct |
225 ms |
11084 KB |
Output is correct |
34 |
Correct |
245 ms |
11192 KB |
Output is correct |
35 |
Correct |
195 ms |
11196 KB |
Output is correct |
36 |
Correct |
120 ms |
8892 KB |
Output is correct |
37 |
Correct |
268 ms |
13760 KB |
Output is correct |
38 |
Correct |
253 ms |
14112 KB |
Output is correct |
39 |
Correct |
257 ms |
14816 KB |
Output is correct |
40 |
Correct |
137 ms |
10856 KB |
Output is correct |
41 |
Correct |
174 ms |
10688 KB |
Output is correct |
42 |
Correct |
82 ms |
7608 KB |
Output is correct |
43 |
Correct |
301 ms |
19388 KB |
Output is correct |
44 |
Correct |
298 ms |
19212 KB |
Output is correct |
45 |
Correct |
286 ms |
19388 KB |
Output is correct |
46 |
Correct |
296 ms |
17856 KB |
Output is correct |
47 |
Correct |
244 ms |
17660 KB |
Output is correct |
48 |
Correct |
130 ms |
9120 KB |
Output is correct |
49 |
Correct |
281 ms |
19572 KB |
Output is correct |
50 |
Correct |
291 ms |
20164 KB |
Output is correct |
51 |
Correct |
287 ms |
19136 KB |
Output is correct |
52 |
Correct |
210 ms |
18112 KB |
Output is correct |
53 |
Correct |
221 ms |
12220 KB |
Output is correct |