蒟蒻求问
  • 板块学术版
  • 楼主MnZnOIer
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/3/7 21:39
  • 上次更新2024/3/8 11:35:56
查看原帖
蒟蒻求问
677091
MnZnOIer楼主2024/3/7 21:39

为啥会 RE。。。

n,m≤105n,m\le10^5。

在线等 qwq。

#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e5 + 5;
int n, m, x, y, ans, s, head1 = 1, tail1, head2 = 1, tail2;
struct node{int t, h;}f, a[N], b[N];
signed main ()
{
	ios::sync_with_stdio (0), cin.tie (0), cout.tie (0);
	cin >> n >> m >> x >> y;
	for (int i = 1; i <= n; ++ i)cin >> a[i].t >> a[i].h;
	for (int i = 1; i <= m; ++ i)cin >> b[i].t >> b[i].h;
	tail1 = n, tail2 = m;
	while (! (head1 == tail1 + 1) || ! (tail2 + 1 == head2))
	{
		int ti = x + s;
		if (ti >= 0)
		{
			s = 0;
			if (head1 == tail1 + 1)ans += ti;
			else while (ti > 0)
			{
				if (ti < a[head1].t && a[head1].h == 0){ans += ti;break;}
				ti -= a[head1].t;
				ans += a[head1].t;
				++ head1;
				if ((head1 == tail1 + 1) && (head2 == tail2 + 1))
				{
					cout << ans;
					return 0;
				}
				if (ti < 0)s = ti;
			}
		}
		else s = ti;
		ti = y + s;
		if (ti >= 0)
		{
			s = 0;
			if (tail2 + 1 == head2)ans += ti;
			else while (ti > 0)
			{
				if (ti < b[head2].t && b[head2].h == 0){ans += ti;break;}
				ti -= b[head2].t;
				ans += b[head2].t;
				++ head2;
				if ((tail1 + 1 == head1) && (tail2 + 1 == head2))
				{
					cout << ans;
					return 0;
				}
				if (ti < 0)s = ti;
			}
		}
		else s = ti;
	}
	cout << ans;
	return 0;
}
2024/3/7 21:39
加载中...