I Incoming Asteroids(优先队列)
Posted Harris-H
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了I Incoming Asteroids(优先队列)相关的知识,希望对你有一定的参考价值。
I Incoming Asteroids(优先队列)
考虑递增的速度,用一个定时器维护每个camera的观测值,当到达阈值之后,就进行检测,每个位置用一个优先队列维护。
// Problem: I. Incoming Asteroids
// Contest: Codeforces - 2019-2020 ICPC Asia Hong Kong Regional Contest
// URL: https://codeforces.ml/gym/102452/problem/I
// Memory Limit: 512 MB
// Time Limit: 2000 ms
// Date: 2021-11-25 22:17:28
// --------by Herio--------
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N=2e5+5,M=2e4+5,inf=0x3f3f3f3f,mod=1e9+7;
const int hashmod[4] = 402653189,805306457,1610612741,998244353;
#define mst(a,b) memset(a,b,sizeof a)
#define PII pair<int,int>
#define PLL pair<ll,ll>
#define x first
#define y second
#define pb emplace_back
#define SZ(a) (int)a.size()
#define rep(i,a,b) for(int i=a;i<=b;++i)
#define per(i,a,b) for(int i=a;i>=b;--i)
#define ios ios::sync_with_stdio(false),cin.tie(nullptr)
void Print(int *a,int n)
for(int i=1;i<n;i++)
printf("%d ",a[i]);
printf("%d\\n",a[n]);
template <typename T> //x=max(x,y) x=min(x,y)
void cmx(T &x,T y)
if(x<y) x=y;
template <typename T>
void cmn(T &x,T y)
if(x>y) x=y;
int n,m,last;
int a[N][4],cnt;
int goal[N];
bool vis[N];
ll tim[N];
priority_queue<PII,vector<PLL>,greater<PLL> >q[N];
void solve(int x)
vector<int>ans;
while(!q[x].empty()&&tim[x]>=q[x].top().x)
auto u=q[x].top();q[x].pop();
int id = u.y;
if(vis[id]) continue;
ll rest = goal[id] ;
rep(i,1,a[id][0]) rest -= tim[a[id][i]];
if(rest<=0)
ans.pb(id);
vis[id]=1;
continue;
ll delta = (rest+a[id][0]-1)/a[id][0];
rep(i,1,a[id][0]) q[a[id][i]].push((tim[a[id][i]]+delta),id);
printf("%d",SZ(ans));last=SZ(ans);sort(ans.begin(),ans.end());
for(int x:ans) printf(" %d",x);
puts("");
int main()
scanf("%d%d",&n,&m);
while(m--)
int op;scanf("%d",&op);
if(op==1)
int y,k;scanf("%d%d",&y,&k);
y^=last;
goal[++cnt]=y;
a[cnt][0]=k;
ll delta = (y+k-1)/k;
rep(j,1,k)
scanf("%d",&a[cnt][j]);
a[cnt][j]^=last;
goal[cnt]+=tim[a[cnt][j]];//这里要加上之前的观测值
//因为是从现在开始算,前面的不算贡献
rep(j,1,k)
q[a[cnt][j]].push((tim[a[cnt][j]]+delta),cnt);
else
int x,y;scanf("%d%d",&x,&y);
x^=last,y^=last;
tim[x]+=y;
solve(x);
return 0;
以上是关于I Incoming Asteroids(优先队列)的主要内容,如果未能解决你的问题,请参考以下文章