CF1971E WA20求调 悬1关
查看原帖
CF1971E WA20求调 悬1关
737296
wangjingtian1234楼主2024/6/8 22:24
#include<bits/stdc++.h>
#define int long long
using namespace std;
int n, k, q, a[100010], b[100010], que;
signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0); cout.tie(0);
	int T;
	cin >> T;
	while (T--)
	{
		cin >> n >> k >> q;
		for (int i = 1; i <= k; i++) cin >> a[i];
		for (int i = 1; i <= k; i++) cin >> b[i];
		for (int i = 1; i <= q; i++)
		{
			cin >> que;
			int l = 0, r = k, mid, pos = 0;
			while (l <= r)
			{
				mid = (l + r) / 2;
				if (a[mid] <= que) 
				{
					pos = mid;
					l = mid + 1;	
				} 
				else
					r = mid - 1;
			}
			if (a[pos] == que) 
			{
				cout << b[pos] << ' ';
				continue;
			}
			double time = b[pos] + (b[pos + 1] - b[pos]) * 1.0 * (que - a[pos]) / (a[pos + 1] - a[pos]);
			cout << (int)(time) << ' '; 
		}
		cout << endl;
	}
	return 0;
}

悬赏1关

2024/6/8 22:24
加载中...