Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Task : Table
- Author : Phumipat C. [MAGCARI]
- Language: C++
- Created : 22 January 2023 [08:56]
- */
- #include<bits/stdc++.h>
- using namespace std;
- struct A{
- int val,i,j,time;
- bool operator < (const A&o) const{
- return val > o.val;
- }
- };
- priority_queue<A > heap;
- int a[310][5010],lastEdit[310][5010];
- int main(){
- cin.tie(0)->sync_with_stdio(0);
- cin.exceptions(cin.failbit);
- int r,c,m;
- cin >> r >> c >> m;
- for(int i=1;i<=r;i++)
- for(int j=1;j<=c;j++)
- heap.push({0,i,j,0});
- for(int x=1;x<=m;x++){
- // x is current time
- int k;
- cin >> k;
- if(k == 1){
- int i,j,val;
- cin >> i >> j >> val;
- a[i][j] = val;
- lastEdit[i][j] = x;
- heap.push({val,i,j,x});
- }else if(k == 2){
- int i,val;
- cin >> i >> val;
- a[i][0] = val;
- lastEdit[i][0] = x;
- heap.push({val,i,0,x});
- }else if(k == 3){
- int i,j;
- cin >> i >> j;
- if(lastEdit[i][j] > lastEdit[i][0]) cout << a[i][j] << '\n';
- else cout << a[i][0] << '\n';
- }else if(k == 4){
- while(!heap.empty()){
- A now = heap.top();
- if(now.j != 0){
- if(now.time < lastEdit[now.i][now.j] || now.time < lastEdit[now.i][0]){
- heap.pop();
- continue;
- }
- cout << now.val << '\n';
- break;
- }else{
- if(now.time < lastEdit[now.i][0]){
- heap.pop();
- continue;
- }
- int ch = 1;
- for(int j=1;j<=c;j++){
- if(lastEdit[now.i][j] < now.time){
- cout << now.val << '\n';
- ch = 0;
- break;
- }
- }
- if(ch) heap.pop();
- else break;
- }
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment