Codeforces Round #645 (Div. 2)

题目地址:https://codeforces.com/contest/1358

A.

#include <bits/stdc++.h>
using namespace std;
int main () {
	int t;
	cin >> t;
	while(t--) {
		int n, m;
		cin >> n >> m;
		if((n * m) & 1) {
			cout << n * m / 2 + 1 << endl;
		}
		else {
			cout << n * m / 2 << endl;
		}
	}
}

 B.

#include <bits/stdc++.h>
using namespace std;
int main () {
	ios::sync_with_stdio(false);
	int t;
	cin >> t;
	while(t--) {
		int n;
		cin >> n;
		map<int, int> mp;
		for(int i = 0; i < n; ++i) {
			int temp;
			cin >> temp;
			mp[temp]++;
		}
		int ans = 0;
		int num = 0;
		for(auto &sb : mp) {
			num += sb.second;
			if(num >= sb.first) {
				ans = num;
			}
		}
		ans++;
		cout << ans << endl;
	}
}

 C.

#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int mod = 1000000001;
int main () {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int t;
	cin >> t;
	while(t--) {
		LL x1, y1, x2, y2;
		cin >> x1 >> y1 >> x2 >> y2;
		LL m = x2 - x1;
		LL n = y2 - y1;
		cout << m * n + 1 << endl;
	}
}

 D.

#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const LL N=2e5+10;
LL a[2 * N];
LL b[2 * N];
LL c[N];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	LL n, x;
	cin >> n >> x ;
	for(int i = 0; i < n; ++i) cin >> c[i];
	a[0] = c[0];
	b[0] = ((c[0] + 1) * c[0]) >> 1;
	for(int i = 1; i < 2 * n; ++i){
		b[i] = (((c[i % n] + 1) * c[i % n]) >> 1) + b[i - 1];
		a[i] = c[i % n] + a[i - 1]; //计算天数
	}
	//如果我在某个月到,那么应该选择哪个月呢
	LL ans = 0;
	for(int i = 0; i < n; ++i){  //在这个月的终点结束
		LL l = i;
		LL r = i + n;
		LL temp = r;
		while(r >= l){
			LL mid = (l + r) >> 1;
			if(a[i + n] - a[mid] >= x){
				l = mid + 1;
			}else{
				temp = mid;
				r = mid - 1;
			}
		}
		LL cnm = x - (a[i + n] - a[temp]);	//起始月份中最多有的天数
		LL rem = ((c[temp % n] + 1) * c[temp % n]) >> 1;	//起始月份中的天数之和
		rem -= ((c[temp % n] - cnm + 1) * (c[temp % n] - cnm)) >> 1;	//取后面的连续部分
		ans = max(ans, b[i + n] - b[temp] + rem);
	}
	cout<<ans<<endl;
	return 0;
}
作者:LightAc
出处:https://www.cnblogs.com/lightac/
联系:
Email: dzz@stu.ouc.edu.cn
QQ: 1171613053
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文链接,否则保留追究法律责任的权利。
原文地址:https://www.cnblogs.com/lightac/p/12970346.html