Niuke practice match 115

(0 unread notifications) Niuke Practice Competition 115_ACM/NOI/CSP/CCPC/ICPC Algorithm Programming High Difficulty Practice Competition_Niuke Competition OJ (nowcoder.com)

A-Mountain sequence

Except for the largest element which does not contribute to the answer, all other elements can contribute to the answer. An element can be placed on the left or right compared to the largest element. If the number of elements is x, then if compared to There is a way to put [0, x] on the left, so the contribution is x + 1, and each number is multiplied each time (all contributions except the maximum value are multiplied)

#include<bits/stdc++.h>
using namespace std;
long long n, t, x;
int main()
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> t;
	while(t --)
	{
		map<int, int> mp;
		long long maxx = 0;
		cin >> n;
		for(int i = 1; i <= n; i ++)
		{
			cin >> x;
			maxx = max(maxx, x);
			mp[x] ++;
		}
		long long ans = 1;
		for(auto i: mp)
		{
			if(i.first != maxx)
			{
				ans = (ans * (i.second + 1)) % 998244353;
			}
		}
		cout << ans << '\n';
	}
	return 0;
}

B-Antiamuny wants to leaern binary search again

Just simulate two points

#include<bits/stdc++.h>
using namespace std;
int t, l, r, cnt;
int main()
{
	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> t;
	while(t --)
	{
		int mid;
		cin >> l >> r >> cnt;
		while(l <= r && cnt > 0)
		{
			cnt --;
			mid = (l + r) >> 1;
			l = mid + 1;
		}
		if(cnt > 0)cout << -1 << '\n';
		else cout << mid << '\n';
	}
	return 0;
}

Guess you like

Origin blog.csdn.net/m0_75087931/article/details/132787807