概述
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;
}
}
}
最后
以上就是清秀唇膏为你收集整理的2022CCPC桂林的全部内容,希望文章能够帮你解决2022CCPC桂林所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复