#include "bits/stdc++.h"
using namespace std;
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
using namespace __gnu_pbds;
template<class T> using oset = tree<T, null_type, less_equal<T>,
rb_tree_tag, tree_order_statistics_node_update>;
#define ar array
typedef int64_t ll;
#define sow cerr<<"here"<<endl;
const int N = 1e5 + 5;
struct ST{
oset<int> tree[N << 2];
void add(int i, int v, int lx = 0, int rx = N, int x = 1){
tree[x].insert(v);
if(lx == rx) return;
int m = (lx + rx) >> 1;
if(i <= m) add(i, v, lx, m, x << 1);
else add(i, v, m + 1, rx, x << 1 | 1);
}
int get(int l, int v, int lx = 0, int rx = N, int x = 1){
if(rx < l) return 0;
if(lx >= l){
return tree[x].size() - tree[x].order_of_key(v);
} int m = (lx + rx) >> 1;
return get(l, v, lx, m, x << 1) + get(l, v, m + 1, rx, x << 1 | 1);
}
}T;
int s[N], t[N], x[N], y[N], z[N], res[N];
signed main(){
ios::sync_with_stdio(0); cin.tie(0);
int n, q; cin >> n >> q;
vector<int> P(n), zh;
for(int i=0;i<n;i++){
cin >> s[i] >> t[i];
P[i] = i;
zh.push_back(t[i]);
}
sort(zh.begin(), zh.end());
zh.erase(unique(zh.begin(), zh.end()), zh.end());
vector<int> p(q);
for(int i=0;i<q;i++){
cin >> x[i] >> y[i] >> z[i];
p[i] = i;
}
sort(p.begin(), p.end(), [&](int i, int j){
return x[i] > x[j];
});
sort(P.begin(), P.end(), [&](int i, int j){
return s[i] > s[j];
});
auto add = [&](int i){
int x = lower_bound(zh.begin(), zh.end(), t[i]) - zh.begin();
T.add(x, s[i] + t[i]);
//~ sow
};
int j = 0;
for(auto i : p){
while(j < n && s[P[j]] >= x[i]){
add(P[j++]);
}
int k = lower_bound(zh.begin(), zh.end(), y[i]) - zh.begin();
res[i] = T.get(k, z[i]);
}
for(int i=0;i<q;i++) cout<<res[i]<<"\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
31616 KB |
Output is correct |
2 |
Correct |
28 ms |
31572 KB |
Output is correct |
3 |
Correct |
36 ms |
31648 KB |
Output is correct |
4 |
Correct |
38 ms |
31572 KB |
Output is correct |
5 |
Correct |
33 ms |
31648 KB |
Output is correct |
6 |
Correct |
32 ms |
31624 KB |
Output is correct |
7 |
Correct |
55 ms |
34332 KB |
Output is correct |
8 |
Correct |
44 ms |
34340 KB |
Output is correct |
9 |
Correct |
58 ms |
34364 KB |
Output is correct |
10 |
Correct |
64 ms |
34360 KB |
Output is correct |
11 |
Correct |
53 ms |
34232 KB |
Output is correct |
12 |
Correct |
63 ms |
34188 KB |
Output is correct |
13 |
Correct |
56 ms |
34380 KB |
Output is correct |
14 |
Correct |
54 ms |
34284 KB |
Output is correct |
15 |
Correct |
60 ms |
34260 KB |
Output is correct |
16 |
Correct |
50 ms |
34252 KB |
Output is correct |
17 |
Correct |
45 ms |
34428 KB |
Output is correct |
18 |
Correct |
61 ms |
34316 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2100 ms |
119052 KB |
Output is correct |
2 |
Correct |
2115 ms |
119020 KB |
Output is correct |
3 |
Correct |
1979 ms |
119004 KB |
Output is correct |
4 |
Correct |
1284 ms |
119660 KB |
Output is correct |
5 |
Correct |
1647 ms |
119004 KB |
Output is correct |
6 |
Correct |
1122 ms |
119636 KB |
Output is correct |
7 |
Correct |
2043 ms |
119044 KB |
Output is correct |
8 |
Correct |
1725 ms |
119076 KB |
Output is correct |
9 |
Correct |
1728 ms |
118984 KB |
Output is correct |
10 |
Correct |
1180 ms |
118896 KB |
Output is correct |
11 |
Correct |
1033 ms |
120324 KB |
Output is correct |
12 |
Correct |
1453 ms |
120160 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2100 ms |
119052 KB |
Output is correct |
2 |
Correct |
2115 ms |
119020 KB |
Output is correct |
3 |
Correct |
1979 ms |
119004 KB |
Output is correct |
4 |
Correct |
1284 ms |
119660 KB |
Output is correct |
5 |
Correct |
1647 ms |
119004 KB |
Output is correct |
6 |
Correct |
1122 ms |
119636 KB |
Output is correct |
7 |
Correct |
2043 ms |
119044 KB |
Output is correct |
8 |
Correct |
1725 ms |
119076 KB |
Output is correct |
9 |
Correct |
1728 ms |
118984 KB |
Output is correct |
10 |
Correct |
1180 ms |
118896 KB |
Output is correct |
11 |
Correct |
1033 ms |
120324 KB |
Output is correct |
12 |
Correct |
1453 ms |
120160 KB |
Output is correct |
13 |
Correct |
2197 ms |
119004 KB |
Output is correct |
14 |
Correct |
2175 ms |
118976 KB |
Output is correct |
15 |
Correct |
2197 ms |
119072 KB |
Output is correct |
16 |
Correct |
1386 ms |
119556 KB |
Output is correct |
17 |
Correct |
1951 ms |
119052 KB |
Output is correct |
18 |
Correct |
1220 ms |
119684 KB |
Output is correct |
19 |
Correct |
2680 ms |
118940 KB |
Output is correct |
20 |
Correct |
2463 ms |
119044 KB |
Output is correct |
21 |
Correct |
2633 ms |
119080 KB |
Output is correct |
22 |
Correct |
1542 ms |
118864 KB |
Output is correct |
23 |
Correct |
946 ms |
120332 KB |
Output is correct |
24 |
Correct |
1363 ms |
120136 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
28 ms |
31616 KB |
Output is correct |
2 |
Correct |
28 ms |
31572 KB |
Output is correct |
3 |
Correct |
36 ms |
31648 KB |
Output is correct |
4 |
Correct |
38 ms |
31572 KB |
Output is correct |
5 |
Correct |
33 ms |
31648 KB |
Output is correct |
6 |
Correct |
32 ms |
31624 KB |
Output is correct |
7 |
Correct |
55 ms |
34332 KB |
Output is correct |
8 |
Correct |
44 ms |
34340 KB |
Output is correct |
9 |
Correct |
58 ms |
34364 KB |
Output is correct |
10 |
Correct |
64 ms |
34360 KB |
Output is correct |
11 |
Correct |
53 ms |
34232 KB |
Output is correct |
12 |
Correct |
63 ms |
34188 KB |
Output is correct |
13 |
Correct |
56 ms |
34380 KB |
Output is correct |
14 |
Correct |
54 ms |
34284 KB |
Output is correct |
15 |
Correct |
60 ms |
34260 KB |
Output is correct |
16 |
Correct |
50 ms |
34252 KB |
Output is correct |
17 |
Correct |
45 ms |
34428 KB |
Output is correct |
18 |
Correct |
61 ms |
34316 KB |
Output is correct |
19 |
Correct |
2100 ms |
119052 KB |
Output is correct |
20 |
Correct |
2115 ms |
119020 KB |
Output is correct |
21 |
Correct |
1979 ms |
119004 KB |
Output is correct |
22 |
Correct |
1284 ms |
119660 KB |
Output is correct |
23 |
Correct |
1647 ms |
119004 KB |
Output is correct |
24 |
Correct |
1122 ms |
119636 KB |
Output is correct |
25 |
Correct |
2043 ms |
119044 KB |
Output is correct |
26 |
Correct |
1725 ms |
119076 KB |
Output is correct |
27 |
Correct |
1728 ms |
118984 KB |
Output is correct |
28 |
Correct |
1180 ms |
118896 KB |
Output is correct |
29 |
Correct |
1033 ms |
120324 KB |
Output is correct |
30 |
Correct |
1453 ms |
120160 KB |
Output is correct |
31 |
Correct |
2197 ms |
119004 KB |
Output is correct |
32 |
Correct |
2175 ms |
118976 KB |
Output is correct |
33 |
Correct |
2197 ms |
119072 KB |
Output is correct |
34 |
Correct |
1386 ms |
119556 KB |
Output is correct |
35 |
Correct |
1951 ms |
119052 KB |
Output is correct |
36 |
Correct |
1220 ms |
119684 KB |
Output is correct |
37 |
Correct |
2680 ms |
118940 KB |
Output is correct |
38 |
Correct |
2463 ms |
119044 KB |
Output is correct |
39 |
Correct |
2633 ms |
119080 KB |
Output is correct |
40 |
Correct |
1542 ms |
118864 KB |
Output is correct |
41 |
Correct |
946 ms |
120332 KB |
Output is correct |
42 |
Correct |
1363 ms |
120136 KB |
Output is correct |
43 |
Correct |
2539 ms |
118968 KB |
Output is correct |
44 |
Correct |
2694 ms |
119000 KB |
Output is correct |
45 |
Correct |
2718 ms |
119076 KB |
Output is correct |
46 |
Correct |
1318 ms |
119648 KB |
Output is correct |
47 |
Correct |
1518 ms |
119040 KB |
Output is correct |
48 |
Correct |
1103 ms |
119412 KB |
Output is correct |
49 |
Correct |
2120 ms |
119008 KB |
Output is correct |
50 |
Correct |
2684 ms |
118976 KB |
Output is correct |
51 |
Execution timed out |
3093 ms |
119072 KB |
Time limit exceeded |
52 |
Halted |
0 ms |
0 KB |
- |