MAGCARI

Magic Hat

Nov 2nd, 2022
824
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.39 KB | None | 0 0
  1. /*
  2.     Task    : _example
  3.     Author  : Phumipat C. [MAGCARI]
  4.     Language: C++
  5.     Created : 02 November 2022 [21:17]
  6. */
  7. #include<bits/stdc++.h>
  8. using namespace std;
  9. struct A{
  10.     int w,v,d,x,id;
  11.     bool operator < (const A&o) const{
  12.         return w > o.w;
  13.     }
  14. };
  15. priority_queue<A > heap;
  16. struct B{
  17.     int w,v,d,x,id;
  18.     bool operator < (const A&o) const{
  19.         return d > o.d;
  20.     }
  21. };
  22. priority_queue<B > magic;
  23. int mark[200010];
  24. int main(){
  25.     int n,m,opr,typo,w,v,d,x;
  26.     scanf("%d %d",&n,&m);
  27.     for(int i=1;i<=n+m;i++){
  28.         scanf("%d",&opr);
  29.         if(opr == 1){
  30.             scanf("%d",&typo);
  31.             if(typo == 1){
  32.                 scanf("%d %d",&w,&v);
  33.                 heap.push({w,v,0,0,i});
  34.             }else if(typo == 2){
  35.                 scanf("%d %d %d",&w,&v,&d);
  36.                 heap.push({w,v,d,0,i});
  37.             }else{
  38.                 scanf("%d %d %d %d",&w,&v,&d,&x);
  39.                 heap.push({w,v,d,x,i});
  40.                 magic.push({w,v,d,x,i});
  41.             }
  42.         }else{
  43.             while(!magic.empty() && magic.top().d < i){
  44.                 B now = magic.top();
  45.                 magic.pop();
  46.                 if(mark[now.id] == 0)
  47.                     heap.push({now.x,now.v,0,0,now.id});
  48.             }
  49.             while(1){
  50.                 if(heap.empty()){
  51.                     printf("0\n");
  52.                     break;
  53.                 }
  54.                 A now = heap.top();
  55.                 heap.pop();
  56.                 if(mark[now.id])    continue;
  57.                 if(now.d == 0 && now.x == 0){
  58.                     printf("%d\n",now.v);
  59.                     mark[now.id] = 1;
  60.                     break;
  61.                 }
  62.                 if(now.x == 0){
  63.                     if(now.d < i)   continue;
  64.                     printf("%d\n",now.v);
  65.                     mark[now.id] = 1;
  66.                     break;
  67.                 }
  68.                 printf("%d\n",now.v);
  69.                 mark[now.id] = 1;
  70.                 break;
  71.             }
  72.         }
  73.     }
  74.     return 0;
  75. }
Advertisement
Add Comment
Please, Sign In to add comment