没有AK,tcl,用了一坨STL,仅过了 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;
}