入门赛最后一题
  • 板块学术版
  • 楼主Lemon_zqp
  • 当前回复8
  • 已保存回复8
  • 发布时间2024/8/16 22:28
  • 上次更新2024/8/17 10:08:34
查看原帖
入门赛最后一题
551630
Lemon_zqp楼主2024/8/16 22:28

没有AK,tcl,用了一坨STL,仅过了 30%30\% 的样例。

#include<bits/stdc++.h>
#define int long long
using namespace std;

priority_queue <int, vector<int>, greater<int> > pq[105][105];
stack<int> st[105][105];
queue<int> l[105][105];

signed main(){
	int n, m, k, t;
	cin >> n >> m >> k >> t;
	while(t--){
		int a, x, y, cnt = 0, ans = 0;
		cin >> a >> x >> y;
		if(pq[x][y].size() < k){
			pq[x][y].push(a);
			st[x][y].push(a);
			cout << -1 << endl;
			continue;
		}
		// cout << pq[x][y].top() << endl;
		while(st[x][y].top() != pq[x][y].top()){
			cnt++;
			l[x][y].push(st[x][y].top());
			st[x][y].pop();
		}
		ans = st[x][y].top();
		st[x][y].pop();
		pq[x][y].pop();
		st[x][y].push(a);
		while(!l[x][y].empty()){
			st[x][y].push(l[x][y].front());
			l[x][y].pop();
		}
		pq[x][y].push(a);
		cout << ans << " " << cnt << endl;
	}
	return 0;
}
2024/8/16 22:28
加载中...