2022CCPC桂林

A

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e6 + 6;
ll ans, c[N], a[N], n, m;
char p[N];
list<ll>d;
int lowbit(int i) {
	return i & (-i);
}
void insert(int i, int x) {
	for (; i <= n; i += lowbit(i)) {
		c[i] += x;
	}
}
ll getsum(int i) {
	ll sum = 0;
	for (; i; i -= lowbit(i)) {
		sum += c[i];
	}
	return sum;
}
int main()
{
	cin >> n >> m ;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		d.push_front(a[i]);
		insert(a[i], 1);
		ans += i - getsum(a[i]);//统计当前序列中大于a的元素的个数
	}
	cin>>p+1;
	ll sum = n * (n - 1) / 2;
	cout << ans << endl;
	int f = 1;
	for (int i = 1; i <= m; i++) {
		
		if (p[i] == 'R') {
			ans = sum - ans;
			cout << ans%10;
			d.reverse();
		}
		else {
			
			ll x = d.back();
			d.pop_back();
			d.push_front(x);
			ans = ans + (n - x) - (x - 1);
			cout << ans%10;
		}
		
	}
}

C

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e6 + 6;
const ll mod = 1e9 + 7;
ll a[N], n, m, ans1, ans2, b[N], sum;
int main()
{

	cin >> n >> m;
	for (int i = 1, x; i <= n; i++) {
		cin >> x;
		a[i] = a[i + n] = x;
		b[i + n] = b[n - i + 1] = x;
	}
	sum *= 2;
	n *= 2;
	m--;
	for (int i = 1; i <= n; i++) {
		ans1 += a[i] * (n + 1 - i);
		ans2 += b[i] * (n + 1 - i);
		sum += a[i];
		ans1 %= mod;
		ans2 %= mod;
		sum %= mod;
	}
	ll d = 1;
	for (int i = 1; i <= m; i++) {
		ans1 = (2 * ans1 % mod + ((n * sum % mod) * d % mod)) % mod;
		ans2 = (2 * ans2 % mod + ((n * sum % mod) * d % mod)) % mod;

		d = (d * 4) % mod;

	}
	cout << max(ans1, ans2);
}

E

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define ll long long
using namespace std;

//在gcd的过程上增加了拓展
ll extend_gcd(ll a, ll b, ll& x, ll& y)
{
	if (b == 0) { x = 1; y = 0; return a; }
	ll d = extend_gcd(b, a % b, x, y);
	ll temp = x;
	x = y;
	y = temp - a / b * y;
	return d;

}

int main()
{
	ll T, x1, x2, y1, y2, a, b, c, b1;
	cin >> T;
	int z = 0;
	while (T--) {
		if (z)cout << endl;
		z = 1;
		cin >> x1 >> y1 >> x2 >> y2;
		ll xx = x1, yy = y1;
		x2 -= x1;
		y2 -= y1;
		x1 = y1 = 0;
		if (x1 == x2) {
			cout << x1 + 1 + xx << " " << y1 + yy;
			continue;
		}
		else if (y1 == y2) {
			cout << x1 + xx << " " << y1 + 1 + yy;
			continue;
		}
		a = y2 - y1;
		b = x1 - x2;
		c = x1 * y2 - x2 * y1;

		ll gcd = __gcd(abs(a), abs(b));
		a = a / gcd;
		b = b / gcd;
		c = c / gcd;
		gcd = 1;
		c -= gcd;

		ll x = 0, y = 0;
		ll d = extend_gcd(a, b, x, y);
		x = x * c / d;
		y = y * c / d;
		ll px = x / b;
		ll py = y / a;
		ll p = max(abs(px), abs(py));
		x -= p * b;
		y += p * a;
		cout << x + xx << " " << y + yy;
	}
}

M

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 2e6 + 6;
ll ans, c[N], a[N], n, m;
char p[N];
list<ll>d;
int lowbit(int i) {
	return i & (-i);
}
void insert(int i, int x) {
	for (; i <= n; i += lowbit(i)) {
		c[i] += x;
	}
}
ll getsum(int i) {
	ll sum = 0;
	for (; i; i -= lowbit(i)) {
		sum += c[i];
	}
	return sum;
}
int main()
{
	cin >> n >> m ;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		d.push_front(a[i]);
		insert(a[i], 1);
		ans += i - getsum(a[i]);//统计当前序列中大于a的元素的个数
	}
	cin>>p+1;
	ll sum = n * (n - 1) / 2;
	cout << ans << endl;
	int f = 1;
	for (int i = 1; i <= m; i++) {
		
		if (p[i] == 'R') {
			ans = sum - ans;
			cout << ans%10;
			d.reverse();
		}
		else {
			
			ll x = d.back();
			d.pop_back();
			d.push_front(x);
			ans = ans + (n - x) - (x - 1);
			cout << ans%10;
		}
		
	}
}
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值