Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Task : _example
- Author : Phumipat C. [MAGCARI]
- Language: C++
- Created : 16 January 2023 [20:35]
- */
- #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(){
- 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});
- for(int x=1;x<=m;x++){
- int k;
- cin >> k;
- if(k == 1){
- // setValue
- int i,j,v;
- cin >> i >> j >> v;
- a[i][j] = v;
- timeA[i][j] = x;
- heap.push({a[i][j],i,j,x});
- }else if(k == 2){
- // setRowValue
- int i,v;
- cin >> i >> v;
- a[i][0] = v;
- timeA[i][0] = x;
- heap.push({a[i][0],i,0,x});
- }else if(k == 3){
- // getValue
- int i,j;
- cin >> i >> j;
- if(timeA[i][j] >= timeA[i][0])
- cout << a[i][j] << '\n';
- else
- cout << a[i][0] << '\n';
- }else{
- // getMin
- while(!heap.empty()){
- A now = heap.top();
- if(now.j != 0){
- // now.time < timeA[i][j] or timeA[i][0]
- if(now.time < timeA[now.i][now.j] || now.time < timeA[now.i][0]){
- heap.pop();
- continue;
- }
- cout << now.val << '\n';
- break;
- }else{
- if(now.time < timeA[now.i][0]){
- heap.pop();
- continue;
- }
- for(int j=1;j<=c;j++){
- if(timeA[now.i][j] < now.time){
- cout << now.val << '\n';
- goto finished;
- }
- }
- heap.pop();
- }
- }
- finished:;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment