#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(a, b) for(int a = 0; a < (b); ++a)
#define st first
#define nd second
#define pb push_back
#define all(a) a.begin(), a.end()
const int LIM=1e5+7;
pair<ll,ll>T[LIM];
ll wynik[LIM];
pair<pair<ll,ll>,ll>pyt[LIM];
vector<pair<ll,pair<ll,ll>>>A, B;
vector<ll>skal;
map<ll,ll>mp;
ll tr[20*LIM], N=1, akt=0;
void upd(int v, ll x) {
v+=N;
while(v) {
tr[v]+=x;
v/=2;
}
}
ll cnt(int l, int r) {
if(l>r) return 0;
l+=N; r+=N;
ll ans=tr[l];
if(l!=r) ans+=tr[r];
while(l/2!=r/2) {
if(l%2==0) ans+=tr[l+1];
if(r%2==1) ans+=tr[r-1];
l/=2; r/=2;
}
return ans;
}
int main() {
ios_base::sync_with_stdio(0); cin.tie(0);
int n, q;
cin >> n >> q;
rep(i, n) {
cin >> T[i].st >> T[i].nd;
A.pb({-T[i].st, {-1, T[i].nd}});
B.pb({-T[i].st, {-1, T[i].nd+T[i].st}});
}
rep(i, q) {
cin >> pyt[i].st.st >> pyt[i].st.nd >> pyt[i].nd;
pyt[i].nd=max(pyt[i].nd, pyt[i].st.st+pyt[i].st.nd);
A.pb({-max(pyt[i].st.st, pyt[i].nd-pyt[i].st.nd), {i, pyt[i].st.nd}});
B.pb({-pyt[i].st.st, {i, max(pyt[i].st.nd, pyt[i].nd-pyt[i].st.st)+pyt[i].st.st}});
B.pb({-max(pyt[i].st.st, pyt[i].nd-pyt[i].st.nd), {i+q, max(pyt[i].st.nd, pyt[i].nd-pyt[i].st.st)+pyt[i].st.st}});
}
for(auto i : A)
skal.pb(i.nd.nd);
for(auto i : B)
skal.pb(i.nd.nd);
sort(all(skal));
for(auto i : skal)
if(mp.find(i)==mp.end()) mp[i]=akt++;
while(N<akt) N*=2;
sort(all(A));
for(auto i : A) {
if(i.nd.st==-1) upd(mp[i.nd.nd], 1);
else wynik[i.nd.st]+=cnt(mp[i.nd.nd], N-1);
}
rep(i, 2*N) tr[i]=0;
sort(all(B));
for(auto i : B) {
if(i.nd.st==-1) upd(mp[i.nd.nd], 1);
else if(i.nd.st<q) wynik[i.nd.st]+=cnt(mp[i.nd.nd], N-1);
else wynik[i.nd.st-q]-=cnt(mp[i.nd.nd], N-1);
}
rep(i, q) cout << wynik[i] << '\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
9 ms |
6156 KB |
Output is correct |
8 |
Correct |
9 ms |
6048 KB |
Output is correct |
9 |
Correct |
9 ms |
6288 KB |
Output is correct |
10 |
Correct |
6 ms |
5652 KB |
Output is correct |
11 |
Correct |
9 ms |
6168 KB |
Output is correct |
12 |
Correct |
3 ms |
5144 KB |
Output is correct |
13 |
Correct |
8 ms |
6012 KB |
Output is correct |
14 |
Correct |
8 ms |
6168 KB |
Output is correct |
15 |
Correct |
9 ms |
6148 KB |
Output is correct |
16 |
Correct |
7 ms |
5756 KB |
Output is correct |
17 |
Correct |
5 ms |
5656 KB |
Output is correct |
18 |
Correct |
2 ms |
5144 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
303 ms |
37388 KB |
Output is correct |
2 |
Correct |
301 ms |
38160 KB |
Output is correct |
3 |
Correct |
277 ms |
37776 KB |
Output is correct |
4 |
Correct |
177 ms |
32528 KB |
Output is correct |
5 |
Correct |
256 ms |
31344 KB |
Output is correct |
6 |
Correct |
91 ms |
28844 KB |
Output is correct |
7 |
Correct |
261 ms |
37128 KB |
Output is correct |
8 |
Correct |
279 ms |
33300 KB |
Output is correct |
9 |
Correct |
237 ms |
34056 KB |
Output is correct |
10 |
Correct |
242 ms |
31296 KB |
Output is correct |
11 |
Correct |
167 ms |
31680 KB |
Output is correct |
12 |
Correct |
62 ms |
27688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
303 ms |
37388 KB |
Output is correct |
2 |
Correct |
301 ms |
38160 KB |
Output is correct |
3 |
Correct |
277 ms |
37776 KB |
Output is correct |
4 |
Correct |
177 ms |
32528 KB |
Output is correct |
5 |
Correct |
256 ms |
31344 KB |
Output is correct |
6 |
Correct |
91 ms |
28844 KB |
Output is correct |
7 |
Correct |
261 ms |
37128 KB |
Output is correct |
8 |
Correct |
279 ms |
33300 KB |
Output is correct |
9 |
Correct |
237 ms |
34056 KB |
Output is correct |
10 |
Correct |
242 ms |
31296 KB |
Output is correct |
11 |
Correct |
167 ms |
31680 KB |
Output is correct |
12 |
Correct |
62 ms |
27688 KB |
Output is correct |
13 |
Correct |
292 ms |
37368 KB |
Output is correct |
14 |
Correct |
275 ms |
39784 KB |
Output is correct |
15 |
Correct |
274 ms |
40880 KB |
Output is correct |
16 |
Correct |
173 ms |
33808 KB |
Output is correct |
17 |
Correct |
241 ms |
33848 KB |
Output is correct |
18 |
Correct |
79 ms |
27984 KB |
Output is correct |
19 |
Correct |
279 ms |
41312 KB |
Output is correct |
20 |
Correct |
285 ms |
39952 KB |
Output is correct |
21 |
Correct |
298 ms |
41116 KB |
Output is correct |
22 |
Correct |
238 ms |
33552 KB |
Output is correct |
23 |
Correct |
169 ms |
32700 KB |
Output is correct |
24 |
Correct |
84 ms |
29196 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
4440 KB |
Output is correct |
2 |
Correct |
1 ms |
4444 KB |
Output is correct |
3 |
Correct |
1 ms |
4444 KB |
Output is correct |
4 |
Correct |
1 ms |
4444 KB |
Output is correct |
5 |
Correct |
1 ms |
4444 KB |
Output is correct |
6 |
Correct |
1 ms |
4444 KB |
Output is correct |
7 |
Correct |
9 ms |
6156 KB |
Output is correct |
8 |
Correct |
9 ms |
6048 KB |
Output is correct |
9 |
Correct |
9 ms |
6288 KB |
Output is correct |
10 |
Correct |
6 ms |
5652 KB |
Output is correct |
11 |
Correct |
9 ms |
6168 KB |
Output is correct |
12 |
Correct |
3 ms |
5144 KB |
Output is correct |
13 |
Correct |
8 ms |
6012 KB |
Output is correct |
14 |
Correct |
8 ms |
6168 KB |
Output is correct |
15 |
Correct |
9 ms |
6148 KB |
Output is correct |
16 |
Correct |
7 ms |
5756 KB |
Output is correct |
17 |
Correct |
5 ms |
5656 KB |
Output is correct |
18 |
Correct |
2 ms |
5144 KB |
Output is correct |
19 |
Correct |
303 ms |
37388 KB |
Output is correct |
20 |
Correct |
301 ms |
38160 KB |
Output is correct |
21 |
Correct |
277 ms |
37776 KB |
Output is correct |
22 |
Correct |
177 ms |
32528 KB |
Output is correct |
23 |
Correct |
256 ms |
31344 KB |
Output is correct |
24 |
Correct |
91 ms |
28844 KB |
Output is correct |
25 |
Correct |
261 ms |
37128 KB |
Output is correct |
26 |
Correct |
279 ms |
33300 KB |
Output is correct |
27 |
Correct |
237 ms |
34056 KB |
Output is correct |
28 |
Correct |
242 ms |
31296 KB |
Output is correct |
29 |
Correct |
167 ms |
31680 KB |
Output is correct |
30 |
Correct |
62 ms |
27688 KB |
Output is correct |
31 |
Correct |
292 ms |
37368 KB |
Output is correct |
32 |
Correct |
275 ms |
39784 KB |
Output is correct |
33 |
Correct |
274 ms |
40880 KB |
Output is correct |
34 |
Correct |
173 ms |
33808 KB |
Output is correct |
35 |
Correct |
241 ms |
33848 KB |
Output is correct |
36 |
Correct |
79 ms |
27984 KB |
Output is correct |
37 |
Correct |
279 ms |
41312 KB |
Output is correct |
38 |
Correct |
285 ms |
39952 KB |
Output is correct |
39 |
Correct |
298 ms |
41116 KB |
Output is correct |
40 |
Correct |
238 ms |
33552 KB |
Output is correct |
41 |
Correct |
169 ms |
32700 KB |
Output is correct |
42 |
Correct |
84 ms |
29196 KB |
Output is correct |
43 |
Correct |
406 ms |
60944 KB |
Output is correct |
44 |
Correct |
404 ms |
62480 KB |
Output is correct |
45 |
Correct |
436 ms |
62736 KB |
Output is correct |
46 |
Correct |
221 ms |
44552 KB |
Output is correct |
47 |
Correct |
423 ms |
60692 KB |
Output is correct |
48 |
Correct |
88 ms |
28672 KB |
Output is correct |
49 |
Correct |
450 ms |
62844 KB |
Output is correct |
50 |
Correct |
419 ms |
61964 KB |
Output is correct |
51 |
Correct |
421 ms |
62996 KB |
Output is correct |
52 |
Correct |
354 ms |
53260 KB |
Output is correct |
53 |
Correct |
194 ms |
43028 KB |
Output is correct |