Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Task : _example
- Author : Phumipat C. [MAGCARI]
- Language: C++
- Created : 18 January 2023 [19:45]
- */
- #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],timeA[310][5010];
- int main(){
- int r,c,m;
- scanf("%d %d %d",&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;
- scanf("%d",&k);
- if(k == 1){
- int i,j,v;
- scanf("%d %d %d",&i,&j,&v);
- a[i][j] = v;
- timeA[i][j] = x;
- heap.push({v,i,j,x});
- }else if(k == 2){
- int i,v;
- scanf("%d %d",&i,&v);
- a[i][0] = v;
- timeA[i][0] = x;
- heap.push({v,i,0,x});
- }else if(k == 3){
- int i,j;
- scanf("%d %d",&i,&j);
- if(timeA[i][j] >= timeA[i][0])
- printf("%d\n",a[i][j]);
- else
- printf("%d\n",a[i][0]);
- }else if(k == 4){
- while(!heap.empty()){
- A now = heap.top();
- if(now.j != 0){
- if(now.time < timeA[now.i][now.j] || now.time < timeA[now.i][0]){
- heap.pop();
- continue;
- }
- printf("%d\n",now.val);
- break;
- }else{
- if(now.time < timeA[now.i][0]){
- heap.pop();
- continue;
- }
- int ch = 1;
- for(int j=1;j<=c;j++){
- if(timeA[now.i][j] < now.time){
- printf("%d\n",now.val);
- ch = 0;
- break;
- }
- }
- if(ch == 0) break;
- else heap.pop();
- }
- }
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment