#include <bits/stdc++.h>
#include <bits/extc++.h>
#define pii pair<int, int>
#define ff first
#define ss second
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define FOR(i, a, b) for(int i = a; i <= b; ++i)
#define FORR(i, a, b) for(int i = a; i >= b; --i)
using namespace std;
using namespace __gnu_pbds;
const int N = 1e5 + 9;
int n, q, s[N], t[N];
struct query
{
int x, y, z, ind, ans;
};
vector<query> qs;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> omultiset;
omultiset d[4 * N];
void Update(int p, int v, int nod = 1, int st = 1, int dr = n)
{
d[nod].insert(v);
if(st == dr)return;
int m = (st + dr) >> 1;
if(p <= m)Update(p, v, nod << 1, st, m);
else Update(p, v, nod << 1 | 1, m + 1, dr);
}
int Query(int l, int r, int v, int nod = 1, int st = 1, int dr = n)///cate is mai mari sau eg cu v
{
if(l <= st && dr <= r)return d[nod].size() - d[nod].order_of_key(v);
int m = (st + dr) >> 1;
if(r <= m)return Query(l, r, v, nod << 1, st, m);
else if(l > m)return Query(l, r, v, nod << 1 | 1, m + 1, dr);
return Query(l, r, v, nod << 1, st, m) + Query(l, r, v, nod << 1 | 1, m + 1, dr);
}
vector<int> nor;
int index_of(int x)
{
return distance(nor.begin(), lower_bound(nor.begin(), nor.end(), x)) + 1;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0), cout.tie(0);
cin >> n >> q;
FOR(i, 1, n)cin >> s[i] >> t[i];
FOR(i, 1, n)nor.pb(s[i]);
sort(nor.begin(), nor.end());
nor.erase(unique(nor.begin(), nor.end()), nor.end());
qs.resize(q);
FOR(i, 0, q - 1)
{
cin >> qs[i].x >> qs[i].y >> qs[i].z;
qs[i].ind = i;
qs[i].ans = -1;
}
sort(qs.begin(), qs.end(), [](query const& a, query const& b){return a.z > b.z;});
vector<int> v;
FOR(i, 1, n)v.pb(i);
sort(v.begin(), v.end(), [](int a, int b){return s[a] + t[a] > s[b] + t[b];});
auto it = v.begin();
for(auto& e : qs)
{
while(it != v.end() && s[*it] + t[*it] >= e.z)
{
Update(index_of(s[*it]), t[*it]);
++ it;
}
if(index_of(e.x) == n + 1)e.ans = 0;
else e.ans = Query(index_of(e.x), n, e.y);
}
sort(qs.begin(), qs.end(), [](query const& a, query const& b){return a.ind < b.ind;});
for(auto e : qs)cout << e.ans << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
31580 KB |
Output is correct |
2 |
Correct |
21 ms |
31580 KB |
Output is correct |
3 |
Correct |
22 ms |
31580 KB |
Output is correct |
4 |
Correct |
31 ms |
31580 KB |
Output is correct |
5 |
Correct |
39 ms |
31688 KB |
Output is correct |
6 |
Correct |
26 ms |
31780 KB |
Output is correct |
7 |
Correct |
41 ms |
33620 KB |
Output is correct |
8 |
Correct |
35 ms |
33620 KB |
Output is correct |
9 |
Correct |
40 ms |
33628 KB |
Output is correct |
10 |
Correct |
58 ms |
33616 KB |
Output is correct |
11 |
Correct |
35 ms |
33780 KB |
Output is correct |
12 |
Correct |
45 ms |
33616 KB |
Output is correct |
13 |
Correct |
38 ms |
33592 KB |
Output is correct |
14 |
Correct |
36 ms |
33784 KB |
Output is correct |
15 |
Correct |
36 ms |
33616 KB |
Output is correct |
16 |
Correct |
35 ms |
33800 KB |
Output is correct |
17 |
Correct |
35 ms |
33628 KB |
Output is correct |
18 |
Correct |
33 ms |
33624 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1837 ms |
121380 KB |
Output is correct |
2 |
Correct |
1924 ms |
121392 KB |
Output is correct |
3 |
Correct |
1924 ms |
121328 KB |
Output is correct |
4 |
Correct |
991 ms |
120656 KB |
Output is correct |
5 |
Correct |
784 ms |
121080 KB |
Output is correct |
6 |
Correct |
699 ms |
120404 KB |
Output is correct |
7 |
Correct |
1367 ms |
121292 KB |
Output is correct |
8 |
Correct |
1276 ms |
121116 KB |
Output is correct |
9 |
Correct |
1199 ms |
121248 KB |
Output is correct |
10 |
Correct |
596 ms |
121772 KB |
Output is correct |
11 |
Correct |
769 ms |
120512 KB |
Output is correct |
12 |
Correct |
945 ms |
120908 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1837 ms |
121380 KB |
Output is correct |
2 |
Correct |
1924 ms |
121392 KB |
Output is correct |
3 |
Correct |
1924 ms |
121328 KB |
Output is correct |
4 |
Correct |
991 ms |
120656 KB |
Output is correct |
5 |
Correct |
784 ms |
121080 KB |
Output is correct |
6 |
Correct |
699 ms |
120404 KB |
Output is correct |
7 |
Correct |
1367 ms |
121292 KB |
Output is correct |
8 |
Correct |
1276 ms |
121116 KB |
Output is correct |
9 |
Correct |
1199 ms |
121248 KB |
Output is correct |
10 |
Correct |
596 ms |
121772 KB |
Output is correct |
11 |
Correct |
769 ms |
120512 KB |
Output is correct |
12 |
Correct |
945 ms |
120908 KB |
Output is correct |
13 |
Correct |
1474 ms |
121676 KB |
Output is correct |
14 |
Correct |
1618 ms |
121680 KB |
Output is correct |
15 |
Correct |
1595 ms |
121376 KB |
Output is correct |
16 |
Correct |
907 ms |
120908 KB |
Output is correct |
17 |
Correct |
829 ms |
121676 KB |
Output is correct |
18 |
Correct |
748 ms |
120396 KB |
Output is correct |
19 |
Correct |
1353 ms |
121796 KB |
Output is correct |
20 |
Correct |
1495 ms |
121676 KB |
Output is correct |
21 |
Correct |
1249 ms |
121688 KB |
Output is correct |
22 |
Correct |
652 ms |
121928 KB |
Output is correct |
23 |
Correct |
688 ms |
120352 KB |
Output is correct |
24 |
Correct |
954 ms |
121000 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
22 ms |
31580 KB |
Output is correct |
2 |
Correct |
21 ms |
31580 KB |
Output is correct |
3 |
Correct |
22 ms |
31580 KB |
Output is correct |
4 |
Correct |
31 ms |
31580 KB |
Output is correct |
5 |
Correct |
39 ms |
31688 KB |
Output is correct |
6 |
Correct |
26 ms |
31780 KB |
Output is correct |
7 |
Correct |
41 ms |
33620 KB |
Output is correct |
8 |
Correct |
35 ms |
33620 KB |
Output is correct |
9 |
Correct |
40 ms |
33628 KB |
Output is correct |
10 |
Correct |
58 ms |
33616 KB |
Output is correct |
11 |
Correct |
35 ms |
33780 KB |
Output is correct |
12 |
Correct |
45 ms |
33616 KB |
Output is correct |
13 |
Correct |
38 ms |
33592 KB |
Output is correct |
14 |
Correct |
36 ms |
33784 KB |
Output is correct |
15 |
Correct |
36 ms |
33616 KB |
Output is correct |
16 |
Correct |
35 ms |
33800 KB |
Output is correct |
17 |
Correct |
35 ms |
33628 KB |
Output is correct |
18 |
Correct |
33 ms |
33624 KB |
Output is correct |
19 |
Correct |
1837 ms |
121380 KB |
Output is correct |
20 |
Correct |
1924 ms |
121392 KB |
Output is correct |
21 |
Correct |
1924 ms |
121328 KB |
Output is correct |
22 |
Correct |
991 ms |
120656 KB |
Output is correct |
23 |
Correct |
784 ms |
121080 KB |
Output is correct |
24 |
Correct |
699 ms |
120404 KB |
Output is correct |
25 |
Correct |
1367 ms |
121292 KB |
Output is correct |
26 |
Correct |
1276 ms |
121116 KB |
Output is correct |
27 |
Correct |
1199 ms |
121248 KB |
Output is correct |
28 |
Correct |
596 ms |
121772 KB |
Output is correct |
29 |
Correct |
769 ms |
120512 KB |
Output is correct |
30 |
Correct |
945 ms |
120908 KB |
Output is correct |
31 |
Correct |
1474 ms |
121676 KB |
Output is correct |
32 |
Correct |
1618 ms |
121680 KB |
Output is correct |
33 |
Correct |
1595 ms |
121376 KB |
Output is correct |
34 |
Correct |
907 ms |
120908 KB |
Output is correct |
35 |
Correct |
829 ms |
121676 KB |
Output is correct |
36 |
Correct |
748 ms |
120396 KB |
Output is correct |
37 |
Correct |
1353 ms |
121796 KB |
Output is correct |
38 |
Correct |
1495 ms |
121676 KB |
Output is correct |
39 |
Correct |
1249 ms |
121688 KB |
Output is correct |
40 |
Correct |
652 ms |
121928 KB |
Output is correct |
41 |
Correct |
688 ms |
120352 KB |
Output is correct |
42 |
Correct |
954 ms |
121000 KB |
Output is correct |
43 |
Correct |
1381 ms |
123720 KB |
Output is correct |
44 |
Correct |
1284 ms |
123592 KB |
Output is correct |
45 |
Correct |
1545 ms |
123564 KB |
Output is correct |
46 |
Correct |
869 ms |
122432 KB |
Output is correct |
47 |
Correct |
764 ms |
122828 KB |
Output is correct |
48 |
Correct |
707 ms |
120392 KB |
Output is correct |
49 |
Correct |
1370 ms |
123472 KB |
Output is correct |
50 |
Correct |
1154 ms |
123716 KB |
Output is correct |
51 |
Correct |
1188 ms |
123460 KB |
Output is correct |
52 |
Correct |
947 ms |
123496 KB |
Output is correct |
53 |
Correct |
669 ms |
121164 KB |
Output is correct |