MAGCARI

Table

Jan 21st, 2023
1,074
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.49 KB | None | 0 0
  1. /*
  2.     Task    : Table
  3.     Author  : Phumipat C. [MAGCARI]
  4.     Language: C++
  5.     Created : 22 January 2023 [08:56]
  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],lastEdit[310][5010];
  17. int main(){
  18.     cin.tie(0)->sync_with_stdio(0);
  19.     cin.exceptions(cin.failbit);
  20.     int r,c,m;
  21.     cin >> r >> c >> m;
  22.     for(int i=1;i<=r;i++)
  23.         for(int j=1;j<=c;j++)
  24.             heap.push({0,i,j,0});
  25.     for(int x=1;x<=m;x++){
  26.         // x is current time
  27.         int k;
  28.         cin >> k;
  29.         if(k == 1){
  30.             int i,j,val;
  31.             cin >> i >> j >> val;
  32.             a[i][j] = val;
  33.             lastEdit[i][j] = x;
  34.             heap.push({val,i,j,x});
  35.         }else if(k == 2){
  36.             int i,val;
  37.             cin >> i >> val;
  38.             a[i][0] = val;
  39.             lastEdit[i][0] = x;
  40.             heap.push({val,i,0,x});
  41.         }else if(k == 3){
  42.             int i,j;
  43.             cin >> i >> j;
  44.             if(lastEdit[i][j] > lastEdit[i][0]) cout << a[i][j] << '\n';
  45.             else                                cout << a[i][0] << '\n';
  46.         }else if(k == 4){
  47.             while(!heap.empty()){
  48.                 A now = heap.top();
  49.                 if(now.j != 0){
  50.                     if(now.time < lastEdit[now.i][now.j] || now.time < lastEdit[now.i][0]){
  51.                         heap.pop();
  52.                         continue;
  53.                     }
  54.                     cout << now.val << '\n';
  55.                     break;
  56.                 }else{
  57.                     if(now.time < lastEdit[now.i][0]){
  58.                         heap.pop();
  59.                         continue;
  60.                     }
  61.                     int ch = 1;
  62.                     for(int j=1;j<=c;j++){
  63.                         if(lastEdit[now.i][j] < now.time){
  64.                             cout << now.val << '\n';
  65.                             ch = 0;
  66.                             break;
  67.                         }
  68.                     }
  69.                     if(ch)  heap.pop();
  70.                     else    break;
  71.                 }
  72.             }
  73.         }
  74.     }
  75.     return 0;
  76. }
Advertisement
Add Comment
Please, Sign In to add comment