P8086 『JROI-5』Music

传送门:P8086 『JROI-5』Music

题意

nn 条信息,每条信息形如 x t,若 t2t \ge 2xx 没有在以前的信息中出现过,则累加 tt,否则不处理。问累加和为多少。

注意如果某个 t1t \le 1 那么 xx 不被算为历史。也就是说例如:

3 1
3 2

22 仍然会被累加,而 11 不会,第一次的 3 1 不被记录成历史。

解法

模拟。用一个 bool 数组记录下某个 x 是否有出现过,没有出现且 t2t \ge 2 则累加并更新数组的状态。

数据有点大,开快读好一些。

代码:

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

#define int long long

const int N = 1e7 + 5;
bool a[N];

inline int read()
{
	char ch = getchar();
	int b = 0;
	while (ch < '0' || ch > '9') ch = getchar();
	while (ch >= '0' && ch <= '9')
	{
		b = (b << 1) + (b << 3) + (ch ^ 48);
		ch = getchar();
	}
	return b;
}

signed main()
{
	int n, x, t, ans = 0;
	n = read();
	while (n--)
	{
		x = read(), t = read();
		if (a[x] || t <= 1) continue;
		a[x] = true;
		ans += t; 
	}
	printf("%lld\n", ans);
	return 0;
}

不开 O2 耗时 263263 毫秒。

posted @ 2022-02-02 20:17  HappyBobb  阅读(11)  评论(0)    收藏  举报  来源