Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Task : _example
- Author : Phumipat C. [MAGCARI]
- Language: C++
- Created : 02 November 2022 [21:17]
- */
- #include<bits/stdc++.h>
- using namespace std;
- struct A{
- int w,v,d,x,id;
- bool operator < (const A&o) const{
- return w > o.w;
- }
- };
- priority_queue<A > heap;
- struct B{
- int w,v,d,x,id;
- bool operator < (const A&o) const{
- return d > o.d;
- }
- };
- priority_queue<B > magic;
- int mark[200010];
- int main(){
- int n,m,opr,typo,w,v,d,x;
- scanf("%d %d",&n,&m);
- for(int i=1;i<=n+m;i++){
- scanf("%d",&opr);
- if(opr == 1){
- scanf("%d",&typo);
- if(typo == 1){
- scanf("%d %d",&w,&v);
- heap.push({w,v,0,0,i});
- }else if(typo == 2){
- scanf("%d %d %d",&w,&v,&d);
- heap.push({w,v,d,0,i});
- }else{
- scanf("%d %d %d %d",&w,&v,&d,&x);
- heap.push({w,v,d,x,i});
- magic.push({w,v,d,x,i});
- }
- }else{
- while(!magic.empty() && magic.top().d < i){
- B now = magic.top();
- magic.pop();
- if(mark[now.id] == 0)
- heap.push({now.x,now.v,0,0,now.id});
- }
- while(1){
- if(heap.empty()){
- printf("0\n");
- break;
- }
- A now = heap.top();
- heap.pop();
- if(mark[now.id]) continue;
- if(now.d == 0 && now.x == 0){
- printf("%d\n",now.v);
- mark[now.id] = 1;
- break;
- }
- if(now.x == 0){
- if(now.d < i) continue;
- printf("%d\n",now.v);
- mark[now.id] = 1;
- break;
- }
- printf("%d\n",now.v);
- mark[now.id] = 1;
- break;
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment