Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
193908 | luckypet | 宝藏 | C++ | 解答错误 | 30 | 0 MS | 252 KB | 1479 | 2025-05-27 15:06:08 |
#include <iostream> #include <vector> #include <algorithm> using namespace std; struct Point { int x, y; }; int main() { int N, M, P; cin >> N >> M >> P; vector<Point> points(P); for (int i = 0; i < P; ++i) { cin >> points[i].x >> points[i].y; } // 按x升序,x相同则按y降序排序 sort(points.begin(), points.end(), [](const Point& a, const Point& b) { if (a.x != b.x) return a.x < b.x; return a.y > b.y; }); // 去重x,保留每个x的第一个点(y最大的) vector<Point> unique_points; if (!points.empty()) { unique_points.push_back(points[0]); for (int i = 1; i < points.size(); ++i) { if (points[i].x != unique_points.back().x) { unique_points.push_back(points[i]); } } } // 提取y坐标序列 vector<int> ys; for (const auto& p : unique_points) { ys.push_back(p.y); } // 计算最长严格递减子序列的长度 vector<int> tails; for (int y : ys) { // 使用upper_bound找到第一个不大于y的元素的位置(严格递减) auto it = upper_bound(tails.begin(), tails.end(), y, greater<int>()); if (it == tails.end()) { tails.push_back(y); } else { *it = y; } } cout << tails.size() << endl; return 0; }