Gym_102452I Incoming Asteroids(資料結構)
Incoming Asteroids
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 1≤y≤106, 1 ≤ k ≤ 3 1≤k≤3 1≤k≤3, 1 ≤ q i ≤ n 1≤q_i≤n 1≤qi≤n for 1 ≤ i ≤ k 1≤i≤k 1≤i≤k): 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 1≤x≤n,1≤y≤106): 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 1≤n,m≤2⋅105), 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 1≤i≤k) 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 1≤k≤3)
- “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];
}
}
相關文章
- 結構化資料、半結構化資料和非結構化資料
- 【資料結構篇】認識資料結構資料結構
- 資料結構小白系列之資料結構概述資料結構
- 資料結構資料結構
- 資料結構與演算法-資料結構(棧)資料結構演算法
- HDU 1240 Asteroids!AST
- 【PHP資料結構】PHP資料結構及演算法總結PHP資料結構演算法
- leetcode演算法資料結構題解---資料結構LeetCode演算法資料結構
- 資料結構——樹資料結構
- Redis資料結構Redis資料結構
- 資料結構-樹資料結構
- 資料結構-Tree資料結構
- Python資料結構Python資料結構
- 資料結構-堆資料結構
- 資料結構-集合資料結構
- 資料結構 - 字串資料結構字串
- 資料結構---串資料結構
- 資料結構-棧資料結構
- Map 資料結構資料結構
- 【模板】資料結構資料結構
- 模板 - 資料結構資料結構
- 14 資料結構資料結構
- 資料結構 - 堆資料結構
- [資料結構]堆資料結構
- 資料結構 - 圖資料結構
- 資料結構 - 棧資料結構
- 資料結構——列表資料結構
- Redis 資料結構Redis資料結構
- 資料結構——堆資料結構
- spacy資料結構資料結構
- Java資料結構Java資料結構
- 資料結構|前言資料結構
- mysql資料庫-資料結構MySql資料庫資料結構
- 集合資料結構總結資料結構
- 資料結構-連結串列資料結構
- 連結串列-資料結構資料結構
- 資料結構 - 連結串列資料結構
- 資料結構--連結串列資料結構