#include <bits/stdc++.h>
#define ll int
#define fr(i, d, c) for(ll i = d; i <= c; i++)
#define fl(i, d, c) for(ll i = d; i >= c; i--)
const int N = 1e5 + 9;
using namespace std;
ll n, q, kq[N];
vector<tuple<ll, ll, ll, ll, ll>> qr;
vector<ll> nen;
struct node {
ll nx[2], cnt;
};
struct trie {
vector<node> t;
trie() {
t.emplace_back();
}
void up(ll x, ll val) {
ll cur = 0;
for(ll j = 30; j >= 0; j--) {
ll y = 0;
if(x >> j & 1) y = 1;
if(!t[cur].nx[y]) {
t[cur].nx[y] = t.size();
t.emplace_back();
}
cur = t[cur].nx[y];
t[cur].cnt += val;
}
}
ll get(ll x) {
ll cur = 0, ans = 0;
for(ll j = 30; j >= 0; j--) {
ll y = 0;
if(x >> j & 1) y = 1;
if(y == 0) {
ll z = t[cur].nx[1];
if(z) ans += t[z].cnt;
}
if(!t[cur].nx[y]) break;
cur = t[cur].nx[y];
if(j == 0) ans += t[cur].cnt;
}
return ans;
}
} tree[10 * N];
void up(ll pos, ll val, ll num, ll id = 1, ll l = 1, ll r = nen.size()) {
if(l == r) {
tree[id].up(val, num);
}
else {
ll mid = (l + r) / 2;
if(pos <= mid) up(pos, val, num, id * 2, l, mid);
else up(pos, val, num, id * 2 + 1, mid + 1, r);
tree[id].up(val, num);
}
}
ll get(ll st, ll en, ll val, ll id = 1, ll l = 1, ll r = nen.size()) {
if(st > r || en < l) return 0;
if(st <= l && r <= en) return tree[id].get(val);
ll mid = (l + r) / 2;
return get(st, en, val, id * 2, l, mid) + get(st, en, val, id * 2 + 1, mid + 1, r);
}
int32_t main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> q;
fr(i, 1, n) {
ll x, y;
cin>> x >> y;
nen.push_back(y);
qr.push_back({x, 1, y, 0, 0});
}
fr(i, 1, q) {
ll x, y, z;
cin>> x >> y >> z;
nen.push_back(y);
qr.push_back({x, 0, y, z, i});
}
sort(nen.begin(), nen.end());
nen.erase(unique(nen.begin(), nen.end()), nen.end());
sort(qr.begin(), qr.end());
reverse(qr.begin(), qr.end());
for(auto [x, t, y, z, id]: qr) {
if(t == 1) {
ll pos = upper_bound(nen.begin(), nen.end(), y) - nen.begin();
up(pos, x + y, 1);
}
else {
ll pos = upper_bound(nen.begin(), nen.end(), y) - nen.begin();
kq[id] = get(pos, nen.size(), z);
}
}
fr(i, 1, q) cout<<kq[i]<<'\n';
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
55116 KB |
Output is correct |
2 |
Correct |
46 ms |
55020 KB |
Output is correct |
3 |
Correct |
61 ms |
55052 KB |
Output is correct |
4 |
Correct |
54 ms |
55120 KB |
Output is correct |
5 |
Correct |
52 ms |
55120 KB |
Output is correct |
6 |
Correct |
57 ms |
55124 KB |
Output is correct |
7 |
Correct |
76 ms |
71496 KB |
Output is correct |
8 |
Correct |
81 ms |
71236 KB |
Output is correct |
9 |
Correct |
75 ms |
70936 KB |
Output is correct |
10 |
Correct |
60 ms |
59972 KB |
Output is correct |
11 |
Correct |
72 ms |
68036 KB |
Output is correct |
12 |
Correct |
56 ms |
55380 KB |
Output is correct |
13 |
Correct |
73 ms |
71024 KB |
Output is correct |
14 |
Correct |
73 ms |
71300 KB |
Output is correct |
15 |
Correct |
73 ms |
70976 KB |
Output is correct |
16 |
Correct |
74 ms |
68532 KB |
Output is correct |
17 |
Correct |
56 ms |
57272 KB |
Output is correct |
18 |
Correct |
54 ms |
55368 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1026 ms |
353552 KB |
Output is correct |
2 |
Correct |
1036 ms |
353504 KB |
Output is correct |
3 |
Correct |
1014 ms |
352976 KB |
Output is correct |
4 |
Correct |
179 ms |
86932 KB |
Output is correct |
5 |
Correct |
612 ms |
186840 KB |
Output is correct |
6 |
Correct |
155 ms |
62728 KB |
Output is correct |
7 |
Correct |
1079 ms |
352984 KB |
Output is correct |
8 |
Correct |
975 ms |
338108 KB |
Output is correct |
9 |
Correct |
966 ms |
338388 KB |
Output is correct |
10 |
Correct |
448 ms |
171460 KB |
Output is correct |
11 |
Correct |
130 ms |
70336 KB |
Output is correct |
12 |
Correct |
125 ms |
62704 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1026 ms |
353552 KB |
Output is correct |
2 |
Correct |
1036 ms |
353504 KB |
Output is correct |
3 |
Correct |
1014 ms |
352976 KB |
Output is correct |
4 |
Correct |
179 ms |
86932 KB |
Output is correct |
5 |
Correct |
612 ms |
186840 KB |
Output is correct |
6 |
Correct |
155 ms |
62728 KB |
Output is correct |
7 |
Correct |
1079 ms |
352984 KB |
Output is correct |
8 |
Correct |
975 ms |
338108 KB |
Output is correct |
9 |
Correct |
966 ms |
338388 KB |
Output is correct |
10 |
Correct |
448 ms |
171460 KB |
Output is correct |
11 |
Correct |
130 ms |
70336 KB |
Output is correct |
12 |
Correct |
125 ms |
62704 KB |
Output is correct |
13 |
Correct |
1131 ms |
353232 KB |
Output is correct |
14 |
Correct |
1016 ms |
353040 KB |
Output is correct |
15 |
Correct |
985 ms |
353396 KB |
Output is correct |
16 |
Correct |
190 ms |
86020 KB |
Output is correct |
17 |
Correct |
622 ms |
187792 KB |
Output is correct |
18 |
Correct |
159 ms |
62916 KB |
Output is correct |
19 |
Correct |
1143 ms |
353844 KB |
Output is correct |
20 |
Correct |
1112 ms |
353748 KB |
Output is correct |
21 |
Correct |
1177 ms |
345412 KB |
Output is correct |
22 |
Correct |
448 ms |
171732 KB |
Output is correct |
23 |
Correct |
132 ms |
70100 KB |
Output is correct |
24 |
Correct |
124 ms |
62688 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
55 ms |
55116 KB |
Output is correct |
2 |
Correct |
46 ms |
55020 KB |
Output is correct |
3 |
Correct |
61 ms |
55052 KB |
Output is correct |
4 |
Correct |
54 ms |
55120 KB |
Output is correct |
5 |
Correct |
52 ms |
55120 KB |
Output is correct |
6 |
Correct |
57 ms |
55124 KB |
Output is correct |
7 |
Correct |
76 ms |
71496 KB |
Output is correct |
8 |
Correct |
81 ms |
71236 KB |
Output is correct |
9 |
Correct |
75 ms |
70936 KB |
Output is correct |
10 |
Correct |
60 ms |
59972 KB |
Output is correct |
11 |
Correct |
72 ms |
68036 KB |
Output is correct |
12 |
Correct |
56 ms |
55380 KB |
Output is correct |
13 |
Correct |
73 ms |
71024 KB |
Output is correct |
14 |
Correct |
73 ms |
71300 KB |
Output is correct |
15 |
Correct |
73 ms |
70976 KB |
Output is correct |
16 |
Correct |
74 ms |
68532 KB |
Output is correct |
17 |
Correct |
56 ms |
57272 KB |
Output is correct |
18 |
Correct |
54 ms |
55368 KB |
Output is correct |
19 |
Correct |
1026 ms |
353552 KB |
Output is correct |
20 |
Correct |
1036 ms |
353504 KB |
Output is correct |
21 |
Correct |
1014 ms |
352976 KB |
Output is correct |
22 |
Correct |
179 ms |
86932 KB |
Output is correct |
23 |
Correct |
612 ms |
186840 KB |
Output is correct |
24 |
Correct |
155 ms |
62728 KB |
Output is correct |
25 |
Correct |
1079 ms |
352984 KB |
Output is correct |
26 |
Correct |
975 ms |
338108 KB |
Output is correct |
27 |
Correct |
966 ms |
338388 KB |
Output is correct |
28 |
Correct |
448 ms |
171460 KB |
Output is correct |
29 |
Correct |
130 ms |
70336 KB |
Output is correct |
30 |
Correct |
125 ms |
62704 KB |
Output is correct |
31 |
Correct |
1131 ms |
353232 KB |
Output is correct |
32 |
Correct |
1016 ms |
353040 KB |
Output is correct |
33 |
Correct |
985 ms |
353396 KB |
Output is correct |
34 |
Correct |
190 ms |
86020 KB |
Output is correct |
35 |
Correct |
622 ms |
187792 KB |
Output is correct |
36 |
Correct |
159 ms |
62916 KB |
Output is correct |
37 |
Correct |
1143 ms |
353844 KB |
Output is correct |
38 |
Correct |
1112 ms |
353748 KB |
Output is correct |
39 |
Correct |
1177 ms |
345412 KB |
Output is correct |
40 |
Correct |
448 ms |
171732 KB |
Output is correct |
41 |
Correct |
132 ms |
70100 KB |
Output is correct |
42 |
Correct |
124 ms |
62688 KB |
Output is correct |
43 |
Correct |
1463 ms |
689208 KB |
Output is correct |
44 |
Correct |
1427 ms |
687088 KB |
Output is correct |
45 |
Correct |
1498 ms |
686268 KB |
Output is correct |
46 |
Correct |
272 ms |
178044 KB |
Output is correct |
47 |
Correct |
1128 ms |
520696 KB |
Output is correct |
48 |
Correct |
168 ms |
62688 KB |
Output is correct |
49 |
Correct |
1717 ms |
688236 KB |
Output is correct |
50 |
Correct |
1423 ms |
688504 KB |
Output is correct |
51 |
Correct |
1530 ms |
688468 KB |
Output is correct |
52 |
Correct |
745 ms |
503956 KB |
Output is correct |
53 |
Correct |
162 ms |
105672 KB |
Output is correct |