MAGCARI

Table

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