AT_abc320_e [ABC320E] Somen Nagashi 题解
感觉别人写的太复杂了。
用 set,维护当前在队列中的人。每次操作,如果有人,直接累加答案。
然后考虑怎么在 时间回来。只需要离线在 里面跑一个 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;
}

浙公网安备 33010602011771号