Gym_102452I Incoming Asteroids(数据结构)

Incoming Asteroids

time limit per test:2 seconds
memory limit per test:512 megabytes
Problem Description

The International Coalition to Prevent Catastrophes (ICPC) recently discovered several small asteroids in a nearby galaxy. If these asteroids hit the Earth, it will lead to a terrible disaster. So it is important for the ICPC to fully study the orbit trajectories of these asteroids. The ICPC consists of many member states, and due to the difference in development, they may have different goals in the study.

The ICPC has marked n n n astronomy observatories around the world, labelled by 1 , 2 , ⋯ , n 1,2,⋯,n 1,2,,n. According to the ICPC’s prediction, there will be m events of two types, detailed below:

  • “1 y k q[1…k]” ( 1 ≤ y ≤ 1 0 6 1≤y≤10^6 1y106, 1 ≤ k ≤ 3 1≤k≤3 1k3, 1 ≤ q i ≤ n 1≤q_i≤n 1qin for 1 ≤ i ≤ k 1≤i≤k 1ik): A new member of the ICPC joins the study, whose goal is to gather at least y y y minutes of video of the asteroids in total. The new member has k k k cameras and is going to install exactly one camera in each astronomy observatory labelled by q 1 , q 2 , … , q k q_1,q_2,…,q_k q1,q2,,qk. It is guaranteed that these k k k integers q 1 , q 2 , … , q k q_1,q_2,…,q_k q1,q2,,qk are pairwise distinct. Let p p p be the number of events of type 1 before this event, then this member is assigned the ID of p + 1 p+1 p+1.
  • “2 x y” ( 1 ≤ x ≤ n , 1 ≤ y ≤ 1 0 6 1≤x≤n, 1≤y≤10^6 1xn,1y106): Each the camera installed at the x x x-th astronomy observatory successfully gathers y y y minutes of asteroid video. You need to report the number of ICPC members whose goals are just reached after this event, and the IDs of these members. Note that you shouldn’t count the members whose goals have already been reached before this event.

You are an employee at the ICPC and your leader asks you to write a program to simulate these events, so that the ICPC may make appropriate preparations for the study.

Input

The input contains only a single case.

The first line of the input contains two integers n n n and m m m ( 1 ≤ n , m ≤ 2 ⋅ 1 0 5 1≤n,m≤2⋅10^5 1n,m2105), denoting the number of astronomy observatories and the number of events. Each of the next m lines describes an event in formats described in the statement above, except that some parameters are encrypted in order to enforce online processing.

Let last be the number of members you report in the last event of the second type. Note that l a s t = 0 last=0 last=0 before the first event of the second type is processed. For events of the first type, y y y and q i q_i qi ( 1 ≤ i ≤ k 1≤i≤k 1ik) are encrypted. The actual values of y y y and q i q_i qi are y⊕last and qi⊕last. For events of the second type, x , y x,y x,y are encrypted. The actual values of x x x, y y y are x⊕last, y⊕last. In the expressions above, the symbol “⊕” denotes the bitwise exclusive-or operation. Also note that the constraints described in the statement above apply to the corresponding parameters only after decryption, the encrypted values are not subject to those constraints.

Output

For each event of the second type, print a single line. In this line, print an integer c n t cnt cnt first, denoting the number of ICPC members whose goals are just reached after this event. Then print c n t cnt cnt ascending integers, denoting the IDs of these ICPC members.

Sample Input

3 5
1 5 3 1 2 3
2 2 1
1 2 2 1 2
2 3 1
2 1 3

Sample Output

0
0
2 1 2

题意

ICPC联盟有若干个国家,同时有n个观测点。每次会发生以下两种事件中的一种:

  • “1 y k p[1…k]”,表示新加入一个国家,其需要拍摄至少y分钟的视频,该国家在 p 1 , . . . . , p k p_1,....,p_k p1,....,pk观测点设置了拍摄装置。( 1 ≤ k ≤ 3 1\le k \le 3 1k3)
  • “2 x y”,所有在x观测点设置拍摄装置的国家,都可以拍摄到y分钟的视频。

要求在每次事件2过后,输出第一次满足拍摄要求的国家。若该国家之前已经满足过拍摄需求,则忽略。

思路

值得注意的是每个国家最多只会在3个观测点设置拍摄装置。可以考虑先假设需要在k个观测点,每个观测点拍摄 ⌈ y k ⌉ \left\lceil\dfrac{y}{k}\right\rceil ky分钟的视频。当某个观测点的拍摄时间达到要求后,统计该国家上次统计前到现在总计拍摄的时间,若达到拍摄需求,则输出,否则,更新拍摄需求。

对于每个观测点,需要维护数据结构,使其能根据每个国家在当前点的拍摄需求排序,同时能根据国家编号删除节点。可以使用map< pair<int,int>, int>来维护。其中pair<int,int>,first部分维护国家在当前点的拍摄需求,second维护国家编号。

#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<iterator>
#include<string>
#define dbg(x) cout<<#x<<" = "<<x<<endl;
#define INF 0x3f3f3f3f
#define LLINF 0x3f3f3f3f3f3f3f3f
#define eps 1e-6

using namespace std;
typedef long long LL;
typedef pair<int, int> P;
const int maxn = 200100;
const int mod = 998244353;
int a[maxn], b[maxn], c[maxn];
vector<int> g[maxn], s[maxn], ans;
map<P,int> mp[maxn];
void PUSH(int id);

int main()
{
	int op, n, m, cnt = 0, i, j, k, lastans=0;
	scanf("%d %d", &n, &m);
	while(m--){
		int x,  y;
		scanf("%d", &op);
		if(op == 1){
			scanf("%d %d", &x, &y);
			cnt++;
			x ^= lastans;
			while(y--){
				scanf("%d", &j);
				g[cnt].push_back(j^lastans);
				s[cnt].push_back(0);
			}
			a[cnt] = x;
			PUSH(cnt);
		}else{
			ans.clear();
			scanf("%d %d", &x, &y);
			x ^= lastans, y^=lastans;
			c[x] -= y;
			while(mp[x].size()){
				auto it = mp[x].begin();
				P p = it->first;
				if(p.first+c[x] > 0)break;
				else{
					int id = p.second, sum = 0;
					for(i=0;i<g[id].size();i++){
						sum += mp[g[id][i]][P(s[id][i],id)] - c[g[id][i]];
						mp[g[id][i]].erase(P(s[id][i], id));
					}
					if(sum >= a[id])ans.push_back(id);
					else{
						a[id] -= sum;
						PUSH(id);
					}
				} 
			}
			sort(ans.begin(), ans.end());
			lastans = ans.size();
			printf("%d", lastans);
			for(i=0;i<lastans;i++)
				printf(" %d", ans[i]);
			printf("\n");
		}
	}
	return 0;
}

void PUSH(int id)
{
	int y = g[id].size(), j = (a[id]-1)/y+1;
	b[id] = j;
	for(int i=0;i<y;i++){
		int u = g[id][i];
		s[id][i] = -c[u]+j;
		mp[u][P(s[id][i], id)] = c[u];
	}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值