MAGCARI

Table

Jan 16th, 2023
467
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.50 KB | None | 0 0
  1. /*
  2.     Task    : _example
  3.     Author  : Phumipat C. [MAGCARI]
  4.     Language: C++
  5.     Created : 16 January 2023 [20:35]
  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.     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});
  25.     for(int x=1;x<=m;x++){
  26.         int k;
  27.         cin >> k;
  28.         if(k == 1){
  29.             // setValue
  30.             int i,j,v;
  31.             cin >> i >> j >> v;
  32.             a[i][j] = v;
  33.             timeA[i][j] = x;
  34.             heap.push({a[i][j],i,j,x});
  35.         }else if(k == 2){
  36.             // setRowValue
  37.             int i,v;
  38.             cin >> i >> v;
  39.             a[i][0] = v;
  40.             timeA[i][0] = x;
  41.             heap.push({a[i][0],i,0,x});
  42.         }else if(k == 3){
  43.             // getValue
  44.             int i,j;
  45.             cin >> i >> j;
  46.             if(timeA[i][j] >= timeA[i][0])
  47.                 cout << a[i][j] << '\n';
  48.             else
  49.                 cout << a[i][0] << '\n';
  50.         }else{
  51.             // getMin
  52.             while(!heap.empty()){
  53.                 A now = heap.top();
  54.                 if(now.j != 0){
  55.                     // now.time < timeA[i][j] or timeA[i][0]
  56.                     if(now.time < timeA[now.i][now.j] || now.time < timeA[now.i][0]){
  57.                         heap.pop();
  58.                         continue;
  59.                     }
  60.                     cout << now.val << '\n';
  61.                     break;
  62.                 }else{
  63.                     if(now.time < timeA[now.i][0]){
  64.                         heap.pop();
  65.                         continue;
  66.                     }
  67.                     for(int j=1;j<=c;j++){
  68.                         if(timeA[now.i][j] < now.time){
  69.                             cout << now.val << '\n';
  70.                             goto finished;
  71.                         }
  72.                     }
  73.                     heap.pop();
  74.                 }
  75.             }
  76.             finished:;
  77.         }
  78.     }
  79.     return 0;
  80. }
Advertisement
Add Comment
Please, Sign In to add comment