The line segment tree is updated to all current cameras, and the queue inserts the camera that appears no matter 3721.
Finally, Judge at the inquiry. One by one, ask if the camera is useful.
The queue uses a priority queue.
The camera has two parameters and prices.
If a parameter is greater than or equal to all the remaining cameras, the camera will not expire.
We need to choose the cheapest in an out-of-date camera. When the price is equal, select the earliest one.
#include <cstdio>#include <vector>#include <algorithm>#include <cmath>#include <queue>using namespace std;#define maxn 10000#define inf 999999999vector <int> x, y;bool type[maxn];#define lson l, m, rt << 1#define rson m + 1, r , rt << 1 | 1class Tree{ public :int val[maxn << 2];void build(int l, int r, int rt){val[rt] = 0;if(l == r) return ;int m = (l + r) >> 1;build(lson); build(rson);}void update(int pos, int cc, int l, int r, int rt){if(l == r){val[rt] = cc;return ;}int m = (l + r) >> 1;if(pos <= m) update(pos, cc, lson);else update(pos, cc, rson);val[rt] = max(val[rt << 1] , val[rt << 1 | 1]);}int find_max(int L, int R, int l, int r, int rt){if(L <= l && r <= R){return val[rt];}int m = (l + r) >> 1;int ret = 0;if(L <= m) ret = max(ret, find_max(L,R, lson));if(r > m) ret = max(ret, find_max(L,R, rson));return ret;}};struct Node{int p, cost, id;int ra;Node(){}Node(int xx, int yy, int cc, int idd):p(xx), ra(yy), cost(cc), id(idd) {}}q[maxn];struct cmp{ bool operator ()(const Node & aa, const Node & bb){ if(bb.cost == aa.cost) return aa.id > bb.id; return aa.cost > bb.cost; }};priority_queue < Node, vector< Node >, cmp > qu;//promise the node in the tree is always the efficient ones//find the smallest --- use Minchar op[10];int ans[maxn], anssub;int main(){int T,n;scanf("%d",&T);while(T --){ x.clear(), y.clear();scanf("%d",&n); double ka;for(int i = 1; i <= n; i ++){scanf("%s",op);if(op[0] == 'P'){scanf("%d%lf%d", &q[i].p, &ka, &q[i].cost);q[i].ra = ka * 1000000 + 1e-8;x.push_back( q[i].p );y.push_back( q[i].ra );type[i] = 0;}else{type[i] = 1;}q[i]. id = i;}sort(x.begin(), x.end());sort(y.begin(), y.end());int nx = unique(x.begin(), x.end()) - x.begin();int ny = unique(y.begin(), y.end()) - y.begin();x.erase( unique(x.begin(), x.end()) , x.end());y.erase( unique(y.begin(), y.end()) , y.end());Tree a, b;a.build(0, nx, 1);b.build(0, ny, 1); while(!qu.empty()) qu.pop(); anssub = 0; //printf("%d %d size \n", x.size(), y.size());for(int i = 1; i <= n; i ++){if(type[i] == 1){//query while(!qu.empty()){ int vx = qu.top().p; int vy = qu.top(). ra; //printf("%d %d %d now to deal\n", vx, vy, qu.top().id); if(vx < b.find_max(vy, ny, 0, ny, 1) || vy < a.find_max(vx, nx, 0, nx, 1)){ qu.pop(); //printf(" kakka %d\n", qu.top().id); continue; } break; } if(qu.empty()) ans[anssub ++] = -1; else { ans[anssub ++] = qu.top().id; }}else{ int vx = lower_bound(x.begin(), x.end(),q[i].p) - x.begin(); int vy = lower_bound(y.begin(), y.end(),q[i].ra) - y.begin(); a.update(vx, vy, 0, nx, 1); b.update(vy, vx, 0, ny, 1); qu.push(Node(vx , vy , q[i].cost, i));}}if(anssub > 0){ for(int i = 0; i < anssub - 1; i ++){ printf("%d ",ans[i]); } printf("%d\n",ans[anssub - 1]);}}return 0;}