Advertisement
MAGCARI

Magic Hat

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