// #define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ld long double
using namespace std;
struct BIT
{
ll n;
vector<vector<ll>> node, bit;
BIT(ll n) : n(n)
{
node.resize(n + 5);
bit.resize(n + 5);
}
void addNode_Update(ll x, ll y)
{
for (x; x <= n; x += x & (-x))
node[x].pb(y);
}
void addNode_Query(ll x, ll y)
{
for (x; x > 0; x -= x & (-x))
node[x].pb(y);
}
void init()
{
for (ll i=0; i<node.size(); i++)
{
sort(node[i].begin(), node[i].end());
node[i].resize(unique(node[i].begin(), node[i].end())-node[i].begin());
bit[i].assign(node[i].size(), 0);
}
}
void addNode_range(ll x1, ll y1, ll x2, ll y2)
{
addNode_Query(x2, y2);
addNode_Query(x1 - 1, y2);
addNode_Query(x2, y1 - 1);
addNode_Query(x1 - 1, y1 - 1);
}
void update(ll x, ll yy, ll val)
{
// cout << x << " " << yy << " " << val << " u\n";
for (x; x <= n; x += x & (-x))
for (ll y = lower_bound(node[x].begin(), node[x].end(), yy) - node[x].begin() + 1; y <= node[x].size(); y += y & (-y))
bit[x][y - 1] += val;
}
ll query(ll x, ll yy)
{
ll ans = 0;
// cout << x << " " << yy << " ";
for (x; x > 0; x -= x & (-x))
for (ll y = lower_bound(node[x].begin(), node[x].end(), yy) - node[x].begin() + 1; y > 0; y -= y & (-y))
assert(y<=node[x].size()), ans += bit[x][y - 1];
// cout << ans << " q\n";
return ans;
}
ll range(ll x1, ll y1, ll x2, ll y2)
{
return query(x2, y2) - query(x1 - 1, y2) - query(x2, y1 - 1) + query(x1 - 1, y1 - 1);
}
};
pll a[200005];
vector<ll> nen;
ll ans[200005];
vector<pair<pll, pll>> Q;
bool cmp(pll a, pll b)
{
return a.fi + a.se > b.fi + b.se;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
ll n, q;
cin >> n >> q;
for (ll i = 1; i <= n; i++)
{
cin >> a[i].fi >> a[i].se;
nen.pb(a[i].fi);
}
sort(a + 1, a + n + 1, cmp);
for (ll i = 1; i <= q; i++)
{
ll a, b, c;
cin >> a >> b >> c;
Q.pb({{c, i}, {a, b}});
nen.pb(a);
}
sort(nen.begin(), nen.end());
nen.resize(unique(nen.begin(), nen.end()) - nen.begin());
ll k = nen.size();
BIT A(k);
for (ll i = 1; i <= n; i++)
A.addNode_Update(lower_bound(nen.begin(), nen.end(), a[i].fi) - nen.begin() + 1, a[i].se);
sort(Q.begin(), Q.end(), greater<pair<pll, pll>>());
for (ll i = 0; i < q; i++)
A.addNode_range(lower_bound(nen.begin(), nen.end(), Q[i].se.fi) - nen.begin() + 1, Q[i].se.se, k, 2e9);
A.init();
ll ptr = 1;
for (ll i = 0; i < q; i++)
{
ll c = Q[i].fi.fi, idx = Q[i].fi.se, aa = Q[i].se.fi, bb = Q[i].se.se;
while (ptr <= n && a[ptr].fi + a[ptr].se >= c)
A.update(lower_bound(nen.begin(), nen.end(), a[ptr].fi) - nen.begin() + 1, a[ptr].se, 1), ptr++;
ans[idx] = A.range(lower_bound(nen.begin(), nen.end(), aa) - nen.begin() + 1, bb, k, 2e9);
//cout << aa << " " << bb << " " << c << endl;
}
// cout << "bruh" << endl;
for (ll i = 1; i <= q; i++)
cout << ans[i] << "\n";
}
Compilation message
examination.cpp: In member function 'void BIT::addNode_Update(long long int, long long int)':
examination.cpp:25:14: warning: statement has no effect [-Wunused-value]
25 | for (x; x <= n; x += x & (-x))
| ^
examination.cpp: In member function 'void BIT::addNode_Query(long long int, long long int)':
examination.cpp:31:14: warning: statement has no effect [-Wunused-value]
31 | for (x; x > 0; x -= x & (-x))
| ^
examination.cpp: In member function 'void BIT::init()':
examination.cpp:37:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::vector<long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
37 | for (ll i=0; i<node.size(); i++)
| ~^~~~~~~~~~~~
examination.cpp: In member function 'void BIT::update(long long int, long long int, long long int)':
examination.cpp:56:14: warning: statement has no effect [-Wunused-value]
56 | for (x; x <= n; x += x & (-x))
| ^
examination.cpp:57:98: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
57 | for (ll y = lower_bound(node[x].begin(), node[x].end(), yy) - node[x].begin() + 1; y <= node[x].size(); y += y & (-y))
| ~~^~~~~~~~~~~~~~~~~
examination.cpp: In member function 'long long int BIT::query(long long int, long long int)':
examination.cpp:65:14: warning: statement has no effect [-Wunused-value]
65 | for (x; x > 0; x -= x & (-x))
| ^
In file included from /usr/include/c++/10/cassert:44,
from /usr/include/x86_64-linux-gnu/c++/10/bits/stdc++.h:33,
from examination.cpp:2:
examination.cpp:67:25: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
67 | assert(y<=node[x].size()), ans += bit[x][y - 1];
| ~^~~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
13 ms |
2388 KB |
Output is correct |
8 |
Correct |
15 ms |
2388 KB |
Output is correct |
9 |
Correct |
12 ms |
2388 KB |
Output is correct |
10 |
Correct |
8 ms |
2004 KB |
Output is correct |
11 |
Correct |
5 ms |
980 KB |
Output is correct |
12 |
Correct |
5 ms |
980 KB |
Output is correct |
13 |
Correct |
12 ms |
2420 KB |
Output is correct |
14 |
Correct |
12 ms |
2388 KB |
Output is correct |
15 |
Correct |
12 ms |
2388 KB |
Output is correct |
16 |
Correct |
3 ms |
852 KB |
Output is correct |
17 |
Correct |
6 ms |
2004 KB |
Output is correct |
18 |
Correct |
3 ms |
852 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
865 ms |
64736 KB |
Output is correct |
2 |
Correct |
847 ms |
64692 KB |
Output is correct |
3 |
Correct |
820 ms |
62724 KB |
Output is correct |
4 |
Correct |
327 ms |
55868 KB |
Output is correct |
5 |
Correct |
211 ms |
22460 KB |
Output is correct |
6 |
Correct |
87 ms |
22192 KB |
Output is correct |
7 |
Correct |
664 ms |
59960 KB |
Output is correct |
8 |
Correct |
753 ms |
62312 KB |
Output is correct |
9 |
Correct |
615 ms |
58904 KB |
Output is correct |
10 |
Correct |
110 ms |
17080 KB |
Output is correct |
11 |
Correct |
284 ms |
50780 KB |
Output is correct |
12 |
Correct |
62 ms |
18772 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
865 ms |
64736 KB |
Output is correct |
2 |
Correct |
847 ms |
64692 KB |
Output is correct |
3 |
Correct |
820 ms |
62724 KB |
Output is correct |
4 |
Correct |
327 ms |
55868 KB |
Output is correct |
5 |
Correct |
211 ms |
22460 KB |
Output is correct |
6 |
Correct |
87 ms |
22192 KB |
Output is correct |
7 |
Correct |
664 ms |
59960 KB |
Output is correct |
8 |
Correct |
753 ms |
62312 KB |
Output is correct |
9 |
Correct |
615 ms |
58904 KB |
Output is correct |
10 |
Correct |
110 ms |
17080 KB |
Output is correct |
11 |
Correct |
284 ms |
50780 KB |
Output is correct |
12 |
Correct |
62 ms |
18772 KB |
Output is correct |
13 |
Correct |
1012 ms |
69304 KB |
Output is correct |
14 |
Correct |
1004 ms |
69308 KB |
Output is correct |
15 |
Correct |
852 ms |
65344 KB |
Output is correct |
16 |
Correct |
360 ms |
57824 KB |
Output is correct |
17 |
Correct |
227 ms |
22960 KB |
Output is correct |
18 |
Correct |
95 ms |
22332 KB |
Output is correct |
19 |
Correct |
848 ms |
62576 KB |
Output is correct |
20 |
Correct |
866 ms |
65296 KB |
Output is correct |
21 |
Correct |
879 ms |
67268 KB |
Output is correct |
22 |
Correct |
111 ms |
17076 KB |
Output is correct |
23 |
Correct |
279 ms |
52540 KB |
Output is correct |
24 |
Correct |
61 ms |
18848 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
0 ms |
340 KB |
Output is correct |
5 |
Correct |
0 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
13 ms |
2388 KB |
Output is correct |
8 |
Correct |
15 ms |
2388 KB |
Output is correct |
9 |
Correct |
12 ms |
2388 KB |
Output is correct |
10 |
Correct |
8 ms |
2004 KB |
Output is correct |
11 |
Correct |
5 ms |
980 KB |
Output is correct |
12 |
Correct |
5 ms |
980 KB |
Output is correct |
13 |
Correct |
12 ms |
2420 KB |
Output is correct |
14 |
Correct |
12 ms |
2388 KB |
Output is correct |
15 |
Correct |
12 ms |
2388 KB |
Output is correct |
16 |
Correct |
3 ms |
852 KB |
Output is correct |
17 |
Correct |
6 ms |
2004 KB |
Output is correct |
18 |
Correct |
3 ms |
852 KB |
Output is correct |
19 |
Correct |
865 ms |
64736 KB |
Output is correct |
20 |
Correct |
847 ms |
64692 KB |
Output is correct |
21 |
Correct |
820 ms |
62724 KB |
Output is correct |
22 |
Correct |
327 ms |
55868 KB |
Output is correct |
23 |
Correct |
211 ms |
22460 KB |
Output is correct |
24 |
Correct |
87 ms |
22192 KB |
Output is correct |
25 |
Correct |
664 ms |
59960 KB |
Output is correct |
26 |
Correct |
753 ms |
62312 KB |
Output is correct |
27 |
Correct |
615 ms |
58904 KB |
Output is correct |
28 |
Correct |
110 ms |
17080 KB |
Output is correct |
29 |
Correct |
284 ms |
50780 KB |
Output is correct |
30 |
Correct |
62 ms |
18772 KB |
Output is correct |
31 |
Correct |
1012 ms |
69304 KB |
Output is correct |
32 |
Correct |
1004 ms |
69308 KB |
Output is correct |
33 |
Correct |
852 ms |
65344 KB |
Output is correct |
34 |
Correct |
360 ms |
57824 KB |
Output is correct |
35 |
Correct |
227 ms |
22960 KB |
Output is correct |
36 |
Correct |
95 ms |
22332 KB |
Output is correct |
37 |
Correct |
848 ms |
62576 KB |
Output is correct |
38 |
Correct |
866 ms |
65296 KB |
Output is correct |
39 |
Correct |
879 ms |
67268 KB |
Output is correct |
40 |
Correct |
111 ms |
17076 KB |
Output is correct |
41 |
Correct |
279 ms |
52540 KB |
Output is correct |
42 |
Correct |
61 ms |
18848 KB |
Output is correct |
43 |
Correct |
1130 ms |
83320 KB |
Output is correct |
44 |
Correct |
1179 ms |
85108 KB |
Output is correct |
45 |
Correct |
1131 ms |
85604 KB |
Output is correct |
46 |
Correct |
426 ms |
67128 KB |
Output is correct |
47 |
Correct |
236 ms |
23100 KB |
Output is correct |
48 |
Correct |
95 ms |
22412 KB |
Output is correct |
49 |
Correct |
1159 ms |
86676 KB |
Output is correct |
50 |
Correct |
1115 ms |
83448 KB |
Output is correct |
51 |
Correct |
1179 ms |
89392 KB |
Output is correct |
52 |
Correct |
131 ms |
17144 KB |
Output is correct |
53 |
Correct |
348 ms |
65108 KB |
Output is correct |