#include <bits/stdc++.h>
#define fr(i, n, m) for(int i = (n); i < (m); i ++)
#define pb push_back
#define st first
#define nd second
#define pq priority_queue
#define all(x) begin(x), end(x)
#include <time.h>
#include <cmath>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
const int i_inf = 1e9;
const ll inf = 1e18;
const ll mod = 1000000007;
const ld eps = 1e-13;
const ld pi = 3.14159265359;
mt19937 _rand(time(NULL));
clock_t timer = clock();
const int mxn = 3e5;
const ll A = 911382323;
const ll B = 972663749;
int n, m;
int s[mxn], t[mxn];
int a[mxn], b[mxn], c[mxn];
int ans[mxn];
int arr[mxn];
int range1;
int range2;
void compress(){
vector<pii> v;
vector<pii> g;
fr(i, 0, n){
v.pb({s[i], i+1});
g.pb({t[i], i+1});
}
fr(i, 0, m){
v.pb({a[i],-i-1});
g.pb({b[i],-i-1});
}
sort(all(v));
sort(all(g));
int nwv = 0;
for(auto u : v){
nwv ++;
if(u.nd > 0) s[u.nd-1] = nwv;
if(u.nd < 0) a[-u.nd-1] = nwv;
}
range1 = nwv;
nwv = 0;
for(auto u : g){
nwv ++;
if(u.nd > 0) t[u.nd-1] = nwv;
if(u.nd < 0) b[-u.nd-1] = nwv;
}
range2 = nwv;
}
const int bsz = 500;
int bit[500][mxn];
int cnt[mxn];
void update(int block, int k, int v){
while(k < mxn){
bit[block][k] += v;
k += k&-k;
}
}
int sum(int block, int k){
int s = 0;
while(k > 0){
s += bit[block][k];
k -= k&-k;
}
return s;
}
void solve(){
cin >> n >> m;
vector<int> v;
fr(i, 0, n){
cin >> s[i] >> t[i];
v.pb(i);
}
sort(all(v), [](const int &i, const int &j){
return s[i]+t[i] > s[j] + t[j];
});
int oldsum[n];
fr(i, 0, n){
oldsum[i] = s[v[i]] + t[v[i]];
}
vector<int> g;
fr(i, 0, m){
cin >> a[i] >> b[i] >> c[i];
g.pb(i);
}
sort(all(g), [](const int &i, const int &j){
return c[i] > c[j];
});
compress();
int pos = 0;
int totb = (range1+bsz-1)/bsz;
for(auto u : g){
while(pos < n && oldsum[pos] >= c[u]){
arr[s[v[pos]]] = t[v[pos]];
int bi = (s[v[pos]]-1)/bsz;
update(bi, t[v[pos]], +1);
++cnt[bi];
++pos;
}
int bi = (a[u]-1)/bsz;
int p = a[u];
while((p-1)/bsz == bi){
if(arr[p] >= b[u]) ans[u] ++;
++p;
}
fr(j, bi+1, totb+1){
ans[u] += cnt[j]-sum(j, b[u]-1);
}
}
fr(i, 0, m){
cout<<ans[i]<<endl;
}
}
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int tc = 1;
//cin >> tc;
while(tc--) solve();
}/*
10 1
41304 98327
91921 28251
85635 59191
30361 72671
28949 96958
99041 37826
10245 2726
19387 20282
60366 87723
95388 49726
52302 69501 66009*/
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
13 ms |
1508 KB |
Output is correct |
8 |
Correct |
13 ms |
1508 KB |
Output is correct |
9 |
Correct |
13 ms |
1508 KB |
Output is correct |
10 |
Correct |
13 ms |
1380 KB |
Output is correct |
11 |
Correct |
13 ms |
1380 KB |
Output is correct |
12 |
Correct |
15 ms |
1380 KB |
Output is correct |
13 |
Correct |
14 ms |
1508 KB |
Output is correct |
14 |
Correct |
14 ms |
1508 KB |
Output is correct |
15 |
Correct |
14 ms |
1508 KB |
Output is correct |
16 |
Correct |
11 ms |
1124 KB |
Output is correct |
17 |
Correct |
13 ms |
1380 KB |
Output is correct |
18 |
Correct |
11 ms |
996 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2582 ms |
302116 KB |
Output is correct |
2 |
Correct |
2569 ms |
302700 KB |
Output is correct |
3 |
Correct |
2535 ms |
302568 KB |
Output is correct |
4 |
Correct |
1707 ms |
208084 KB |
Output is correct |
5 |
Correct |
2045 ms |
173732 KB |
Output is correct |
6 |
Correct |
1359 ms |
45348 KB |
Output is correct |
7 |
Execution timed out |
3049 ms |
232960 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2582 ms |
302116 KB |
Output is correct |
2 |
Correct |
2569 ms |
302700 KB |
Output is correct |
3 |
Correct |
2535 ms |
302568 KB |
Output is correct |
4 |
Correct |
1707 ms |
208084 KB |
Output is correct |
5 |
Correct |
2045 ms |
173732 KB |
Output is correct |
6 |
Correct |
1359 ms |
45348 KB |
Output is correct |
7 |
Execution timed out |
3049 ms |
232960 KB |
Time limit exceeded |
8 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
512 KB |
Output is correct |
3 |
Correct |
1 ms |
384 KB |
Output is correct |
4 |
Correct |
1 ms |
384 KB |
Output is correct |
5 |
Correct |
1 ms |
384 KB |
Output is correct |
6 |
Correct |
1 ms |
384 KB |
Output is correct |
7 |
Correct |
13 ms |
1508 KB |
Output is correct |
8 |
Correct |
13 ms |
1508 KB |
Output is correct |
9 |
Correct |
13 ms |
1508 KB |
Output is correct |
10 |
Correct |
13 ms |
1380 KB |
Output is correct |
11 |
Correct |
13 ms |
1380 KB |
Output is correct |
12 |
Correct |
15 ms |
1380 KB |
Output is correct |
13 |
Correct |
14 ms |
1508 KB |
Output is correct |
14 |
Correct |
14 ms |
1508 KB |
Output is correct |
15 |
Correct |
14 ms |
1508 KB |
Output is correct |
16 |
Correct |
11 ms |
1124 KB |
Output is correct |
17 |
Correct |
13 ms |
1380 KB |
Output is correct |
18 |
Correct |
11 ms |
996 KB |
Output is correct |
19 |
Correct |
2582 ms |
302116 KB |
Output is correct |
20 |
Correct |
2569 ms |
302700 KB |
Output is correct |
21 |
Correct |
2535 ms |
302568 KB |
Output is correct |
22 |
Correct |
1707 ms |
208084 KB |
Output is correct |
23 |
Correct |
2045 ms |
173732 KB |
Output is correct |
24 |
Correct |
1359 ms |
45348 KB |
Output is correct |
25 |
Execution timed out |
3049 ms |
232960 KB |
Time limit exceeded |
26 |
Halted |
0 ms |
0 KB |
- |