AT_abc320_e [ABC320E] Somen Nagashi 题解

感觉别人写的太复杂了。

set,维护当前在队列中的人。每次操作,如果有人,直接累加答案。

然后考虑怎么在 ti+sit_i+s_i 时间回来。只需要离线在 tt 里面跑一个 lower_bound 即可。

#include <bits/stdc++.h>
using namespace std;
//#define int long long

const int N = 5e5 + 5, MOD = 1e9 + 7; // Remember to change

int n, m;

namespace FastIo
{
	#define QUICKCIN ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
	int read()
	{
		char ch = getchar();
		int x = 0, f = 1;
		while ((ch < '0' || ch > '9') && ch != '-') ch = getchar();
		while (ch == '-')
		{
			f = -f;
			ch = getchar();
		}
		while (ch >= '0' && ch <= '9')
		{
			x = (x << 1) + (x << 3) + (ch ^ 48);
			ch = getchar();
		}
		return x * f;
	}
	template<class T>
	void write(T x)
	{
		if (x < 0)
		{
			putchar('-');
			x = -x;
		}
		if (x > 9) write(x / 10);
		putchar(x % 10 + '0');
	}
	template<class T>
	void writeln(T x)
	{
		write(x);
		putchar('\n');
	}
}

long long ans[N];
long long t[N], w[N], s[N];
vector<int> rev[N];

int main()
{
	ios::sync_with_stdio(0), cin.tie(nullptr), cout.tie(nullptr);
	cin >> n >> m;
	set<int> nowt;
	for (int i = 1; i <= n; i++) nowt.insert(i);
	for (int i = 1; i <= m; i++)
	{
		cin >> t[i] >> w[i] >> s[i];
	}
	for (int i = 1; i <= m; i++)
	{
		for (auto &j : rev[i]) nowt.insert(j);
		if (nowt.size())
		{
			ans[*nowt.begin()] += w[i];
			int gg = *nowt.begin();
			nowt.erase(nowt.begin());
			long long np = t[i] + s[i];
			int g = lower_bound(t + 1, t + m + 1, np) - t;
			if (g >= 1 && g <= m) 
			{
				rev[g].emplace_back(gg);
			}
		}
	}
	for (int i = 1; i <= n; i++) cout << ans[i] << "\n";
	return 0;
}
posted @   HappyBobb  阅读(4)  评论(0编辑  收藏  举报  
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示