#include <bits/stdc++.h>
using ll = long long;
using ull = unsigned long long;
using pair = std::array<int, 2>;
using pairll = std::array<ll, 2>;
using tri = std::array<int, 3>;
using trill = std::array<ll, 3>;
constexpr long long MOD = 998244353;
int main() {
std::ios::sync_with_stdio(false);
std::cin.tie(nullptr);
int N, Q;
std::cin >> N >> Q;
std::vector<tri> points;
std::map<int, std::map<int, int>> lol;
std::vector<int> col, row;
for (int i = 0; i < N; i++) {
int a, b;
std::cin >> a >> b;
tri score = {a, b, 1};
points.push_back(score);
row.push_back(a);
col.push_back(b);
}
std::sort(points.begin(), points.end(), [](tri a, tri b) {
if (a[0] != b[0]) {
return a[0] > b[0];
} else {
return a[1] > b[1];
}
});
// unique
for (int i = points.size() - 1; i >= 0; i--) {
if (points[i][0] == points[i+1][0] && points[i][1] == points[i+1][1]) {
points[i][2] += points[i+1][2];
}
}
points.erase(std::unique(points.begin(), points.end(), [](tri a, tri b){return a[0] == b[0] && a[1] == b[1];}), points.end());
for (auto point : points) {
// std::cout << point[0] << ' ' << point[1] << ' ' << point[2] << '\n';
}
for (int i = 1; i < points.size(); i++) {
points[i][2] += points[i-1][2];
}
for (auto point : points) {
// std::cout << point[0] << ' ' << point[1] << ' ' << point[2] << '\n';
lol[point[0]][point[1]] = point[2];
}
while (Q--) {
int x, y ,z;
std::cin >> x >> y >> z;
auto nrow = std::upper_bound(row.begin(), row.end(), x, [](int val, int el) {return el >= val;});
if (nrow == row.end()) {
std::cout << "0\n";
continue;
}
auto ncol = std::upper_bound(col.begin(), col.end(), *nrow, [](int val, int el) {return el >= val;});
if (ncol == col.end()) {
std::cout << "0\n";
continue;
}
std::cout << lol[*nrow][*ncol] << '\n';
}
}
Compilation message
examination.cpp: In function 'int main()':
examination.cpp:50:15: warning: variable 'point' set but not used [-Wunused-but-set-variable]
50 | for (auto point : points) {
| ^~~~~
examination.cpp:54:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::array<int, 3> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
54 | for (int i = 1; i < points.size(); i++) {
| ~~^~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
74 ms |
15748 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
74 ms |
15748 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |