總時間限制:
1000ms
內存限制:
65536kB
// 在此處補充你的代碼
描述
程序填空,一開始平面上一個點都沒有
每次可以插入一個點,刪除一個已經存在的點,或者按照x 或y 來查詢一個存在的點
保證任何時候任意兩個點一定是一個點嚴格在另一個點的右下方
即兩點(x1, y1), (x2, y2),必定有x1 > x2 且y1 < y2 ,或者x1 < x2 且y1 > y2
#include <set>
#include <iostream>
#include <string>
using namespace std;
int main() {
string cmd;
set<pair<int, int>, myComp> S;
while (cin >> cmd) {
if (cmd == "A") {
int x, y;
cin >> x >> y;
S.insert(make_pair(x, y));
} else if (cmd == "Qx") {
int x;
cin >> x;
cout << S.lower_bound(make_pair(x, -1))->second << endl;
} else if (cmd == "Qy") {
int y;
cin >> y;
cout << S.lower_bound(make_pair(-1, y))->first << endl;
} else {
int x, y;
cin >> x >> y;
S.erase(make_pair(x, y));
}
}
return 0;
}
輸入
輸入數據的每一行,格式爲以下之一:
A x y
R x y
Qx x
Qy y
其中 x 與 y 都是 0 到 10^9 之間的整數
A x y 表示插入點 (x, y)
R x y 表示刪除點 (x, y),保證存在
Qx x 表示在當前所有點中,找到第一維爲x的點,輸出其第二維的值,保證存在
Qy y 表示在當前所有點中,找到第二維爲y的點,輸出其第一維的值,保證存在
總共操作數不超過100000
輸出
對於每一個 Qx 和 Qy 操作,輸出一行表示對應的答案
樣例輸入
A 3 5
A 4 2
Qx 4
R 4 2
A 4 3
Qy 3
樣例輸出
2
4
// 在此處補充你的代碼
struct myComp{
bool operator()(const pair<int,int> &a,const pair<int,int> &b){
//小於判斷誰在右下方,因爲數據保證,此處可以簡單點,只判斷x
//這樣不行,查詢的時候,數據顯然不滿足,因爲-1的干擾
if(a.first>0&&a.second>0&&b.first>0&&b.second>0){
return a.first>b.first;
}
else{
if(a.first<0||b.first<0){
return a.second<b.second;
}
else if(a.second<0||b.second<0){
return a.first>b.first;
}
}
}
};