当前位置:网站首页>Public key box

Public key box

2022-07-06 14:53:00 < WRM>

#include<bits/stdc++.h>

using namespace std;

const int N = 10010;

struct node {
    
	int id;
	int type;
	int time;


} a[N];

int q[N];

bool compare(node x, node y) {
    
	if (x.time != y.time) return x.time < y.time;
	if (x.type != y.type) return x.type > y.type;
	if (x.id != y.id) return x.id < y.id;
}
int main() {
    
	int n, k;
	scanf("%d%d", &n, &k);
	for (int i = 1; i <= n; i++) {
    
		q[i] = i;
	}
	int pos = 0;
	while (k--) {
    
		int id, start, length;
		scanf("%d%d%d", &id, &start, &length);
		a[pos++] = {
    id, 0, start}; // Take the key 
		a[pos++] = {
    id, 1, start + length}; // Change the key 
	}
	sort(a, a + pos,compare);
	for (int i = 0; i < pos; i++) {
    
		if (a[i].type == 0) {
    
			for (int j = 1; j <= n; j++) {
    
				if (a[i].id == q[j]) {
    
					q[j] = 0;
					break;
				}
			}
		} else {
    
			for (int j = 1; j <= n; j++) {
    
				if (!q[j]) {
    
					q[j] = a[i].id;
					break;
				}
			}
		}
	}
	for(int i=1;i<=n;i++) printf("%d ",q[i]);
	return 0;
}
原网站

版权声明
本文为[&lt; WRM&gt;]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202131336079417.html