#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#define pipii pair<int, pii>
#define pipi pair<pii, pii>
#pragma GCC optimize("Ofast")
int N = 1<<19;
vector<vector<int>> bin(2*N, vector<int>(1, 0));
vector<vector<int>> bleft(2*N, vector<int>(1, -1));
vector<vector<int>> bright(2*N, vector<int>(1, -1));
int K = 19;
void update(int a, int b)
{
a += N;
while (a)
{
int curr = 0;
for (int i = K; i >= 0; i--)
{
bin[a][curr]++;
if (b&(1<<i))
{
if (bright[a][curr]==-1)
{
bright[a][curr] = bin[a].size();
curr = bin[a].size();
bin[a].push_back(0);
bleft[a].push_back(-1);
bright[a].push_back(-1);
}
else
{
curr = bright[a][curr];
}
}
else
{
if (bleft[a][curr]==-1)
{
bleft[a][curr] = bin[a].size();
curr = bin[a].size();
bin[a].push_back(0);
bleft[a].push_back(-1);
bright[a].push_back(-1);
}
else
{
curr = bleft[a][curr];
}
}
}
bin[a][curr]++;
a/=2;
}
}
int query(int a, int b)
{
int sol = 0;
int curr = 1;
a++; b++;
for (int i = K; i >= 0; i--)
{
if (a&(1<<i))
{
int curr2 = 0;
for (int j = K; j >= 0; j--)
{
if (b&(1<<j))
{
if (bleft[curr][curr2]!=-1) sol += bin[curr][bleft[curr][curr2]];
if (bright[curr][curr2]==-1) break;
curr2 = bright[curr][curr2];
}
else
{
if (bleft[curr][curr2]==-1) break;
curr2 = bleft[curr][curr2];
}
}
curr++;
}
curr*=2;
}
return sol;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
int n, q;
cin >> n >> q;
vector<pipii> scores(n);
map<int, int> comp;
set<int> coord;
for (int i = 0; i < n; i++)
{
int a, b;
cin >> a >> b;
scores[i] = {a+b, {a, b}};
coord.insert(a);
coord.insert(b);
}
sort(scores.begin(), scores.end(), greater<pipii>());
vector<pipi> queries(q);
for (int i = 0; i < q; i++)
{
int a, b, c;
cin >> a >> b >> c;
queries[i] = {{c, i}, {a, b}};
coord.insert(a);
coord.insert(b);
}
sort(queries.begin(), queries.end(), greater<pipi>());
int d = coord.size()+K;
for (int ele:coord)
{
comp[ele] = d--;
}
vector<int> sol(q);
int curr = 0;
for (auto ele:queries)
{
while (curr < scores.size() && scores[curr].first>= ele.first.first)
{
update(comp[scores[curr].second.first], comp[scores[curr].second.second]);
//cout << comp[scores[curr].second.first] << " " << comp[scores[curr].second.second] << endl;
curr++;
}
//cout << 1 << " " << comp[ele.second.first] << " " << comp[ele.second.second] << endl;
sol[ele.first.second] = query(comp[ele.second.first], comp[ele.second.second]);
}
for (int ele:sol) cout << ele << "\n";
return 0;
}
Compilation message
examination.cpp: In function 'int main()':
examination.cpp:131:21: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
131 | while (curr < scores.size() && scores[curr].first>= ele.first.first)
| ~~~~~^~~~~~~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
154 ms |
172624 KB |
Output is correct |
2 |
Correct |
167 ms |
172776 KB |
Output is correct |
3 |
Correct |
152 ms |
172676 KB |
Output is correct |
4 |
Correct |
153 ms |
172724 KB |
Output is correct |
5 |
Correct |
153 ms |
172624 KB |
Output is correct |
6 |
Correct |
158 ms |
172608 KB |
Output is correct |
7 |
Correct |
191 ms |
183636 KB |
Output is correct |
8 |
Correct |
228 ms |
183588 KB |
Output is correct |
9 |
Correct |
192 ms |
183632 KB |
Output is correct |
10 |
Correct |
176 ms |
176704 KB |
Output is correct |
11 |
Correct |
179 ms |
175952 KB |
Output is correct |
12 |
Correct |
159 ms |
172884 KB |
Output is correct |
13 |
Correct |
181 ms |
183708 KB |
Output is correct |
14 |
Correct |
191 ms |
183580 KB |
Output is correct |
15 |
Correct |
208 ms |
183792 KB |
Output is correct |
16 |
Correct |
166 ms |
176564 KB |
Output is correct |
17 |
Correct |
182 ms |
176448 KB |
Output is correct |
18 |
Correct |
140 ms |
172960 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1904 ms |
470452 KB |
Output is correct |
2 |
Correct |
1850 ms |
470596 KB |
Output is correct |
3 |
Correct |
1827 ms |
470448 KB |
Output is correct |
4 |
Correct |
701 ms |
245588 KB |
Output is correct |
5 |
Correct |
686 ms |
233928 KB |
Output is correct |
6 |
Correct |
313 ms |
177492 KB |
Output is correct |
7 |
Correct |
1683 ms |
468272 KB |
Output is correct |
8 |
Correct |
1759 ms |
468344 KB |
Output is correct |
9 |
Correct |
1635 ms |
460816 KB |
Output is correct |
10 |
Correct |
578 ms |
222212 KB |
Output is correct |
11 |
Correct |
655 ms |
237908 KB |
Output is correct |
12 |
Correct |
268 ms |
177260 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1904 ms |
470452 KB |
Output is correct |
2 |
Correct |
1850 ms |
470596 KB |
Output is correct |
3 |
Correct |
1827 ms |
470448 KB |
Output is correct |
4 |
Correct |
701 ms |
245588 KB |
Output is correct |
5 |
Correct |
686 ms |
233928 KB |
Output is correct |
6 |
Correct |
313 ms |
177492 KB |
Output is correct |
7 |
Correct |
1683 ms |
468272 KB |
Output is correct |
8 |
Correct |
1759 ms |
468344 KB |
Output is correct |
9 |
Correct |
1635 ms |
460816 KB |
Output is correct |
10 |
Correct |
578 ms |
222212 KB |
Output is correct |
11 |
Correct |
655 ms |
237908 KB |
Output is correct |
12 |
Correct |
268 ms |
177260 KB |
Output is correct |
13 |
Correct |
1820 ms |
471188 KB |
Output is correct |
14 |
Correct |
1845 ms |
471040 KB |
Output is correct |
15 |
Correct |
1743 ms |
470704 KB |
Output is correct |
16 |
Correct |
671 ms |
245884 KB |
Output is correct |
17 |
Correct |
659 ms |
233980 KB |
Output is correct |
18 |
Correct |
319 ms |
177748 KB |
Output is correct |
19 |
Correct |
1811 ms |
471232 KB |
Output is correct |
20 |
Correct |
1831 ms |
470904 KB |
Output is correct |
21 |
Correct |
1618 ms |
466628 KB |
Output is correct |
22 |
Correct |
572 ms |
222556 KB |
Output is correct |
23 |
Correct |
623 ms |
237872 KB |
Output is correct |
24 |
Correct |
271 ms |
176980 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
154 ms |
172624 KB |
Output is correct |
2 |
Correct |
167 ms |
172776 KB |
Output is correct |
3 |
Correct |
152 ms |
172676 KB |
Output is correct |
4 |
Correct |
153 ms |
172724 KB |
Output is correct |
5 |
Correct |
153 ms |
172624 KB |
Output is correct |
6 |
Correct |
158 ms |
172608 KB |
Output is correct |
7 |
Correct |
191 ms |
183636 KB |
Output is correct |
8 |
Correct |
228 ms |
183588 KB |
Output is correct |
9 |
Correct |
192 ms |
183632 KB |
Output is correct |
10 |
Correct |
176 ms |
176704 KB |
Output is correct |
11 |
Correct |
179 ms |
175952 KB |
Output is correct |
12 |
Correct |
159 ms |
172884 KB |
Output is correct |
13 |
Correct |
181 ms |
183708 KB |
Output is correct |
14 |
Correct |
191 ms |
183580 KB |
Output is correct |
15 |
Correct |
208 ms |
183792 KB |
Output is correct |
16 |
Correct |
166 ms |
176564 KB |
Output is correct |
17 |
Correct |
182 ms |
176448 KB |
Output is correct |
18 |
Correct |
140 ms |
172960 KB |
Output is correct |
19 |
Correct |
1904 ms |
470452 KB |
Output is correct |
20 |
Correct |
1850 ms |
470596 KB |
Output is correct |
21 |
Correct |
1827 ms |
470448 KB |
Output is correct |
22 |
Correct |
701 ms |
245588 KB |
Output is correct |
23 |
Correct |
686 ms |
233928 KB |
Output is correct |
24 |
Correct |
313 ms |
177492 KB |
Output is correct |
25 |
Correct |
1683 ms |
468272 KB |
Output is correct |
26 |
Correct |
1759 ms |
468344 KB |
Output is correct |
27 |
Correct |
1635 ms |
460816 KB |
Output is correct |
28 |
Correct |
578 ms |
222212 KB |
Output is correct |
29 |
Correct |
655 ms |
237908 KB |
Output is correct |
30 |
Correct |
268 ms |
177260 KB |
Output is correct |
31 |
Correct |
1820 ms |
471188 KB |
Output is correct |
32 |
Correct |
1845 ms |
471040 KB |
Output is correct |
33 |
Correct |
1743 ms |
470704 KB |
Output is correct |
34 |
Correct |
671 ms |
245884 KB |
Output is correct |
35 |
Correct |
659 ms |
233980 KB |
Output is correct |
36 |
Correct |
319 ms |
177748 KB |
Output is correct |
37 |
Correct |
1811 ms |
471232 KB |
Output is correct |
38 |
Correct |
1831 ms |
470904 KB |
Output is correct |
39 |
Correct |
1618 ms |
466628 KB |
Output is correct |
40 |
Correct |
572 ms |
222556 KB |
Output is correct |
41 |
Correct |
623 ms |
237872 KB |
Output is correct |
42 |
Correct |
271 ms |
176980 KB |
Output is correct |
43 |
Correct |
2677 ms |
624200 KB |
Output is correct |
44 |
Correct |
2482 ms |
624276 KB |
Output is correct |
45 |
Correct |
2610 ms |
624460 KB |
Output is correct |
46 |
Correct |
880 ms |
307028 KB |
Output is correct |
47 |
Correct |
783 ms |
279084 KB |
Output is correct |
48 |
Correct |
313 ms |
177392 KB |
Output is correct |
49 |
Correct |
2425 ms |
621640 KB |
Output is correct |
50 |
Correct |
2369 ms |
621508 KB |
Output is correct |
51 |
Correct |
2277 ms |
586496 KB |
Output is correct |
52 |
Correct |
740 ms |
262540 KB |
Output is correct |
53 |
Correct |
870 ms |
298896 KB |
Output is correct |