首页 > 其他分享 >2022CCPC桂林 (2022 China Collegiate Programming Contest (CCPC) Guilin Site)

2022CCPC桂林 (2022 China Collegiate Programming Contest (CCPC) Guilin Site)

时间:2022-11-17 12:55:53浏览次数:78  
标签:Contest int res 2022CCPC Guilin pos i64 i128 using

链接:https://codeforces.com/gym/104008

A. Lily

C++ Code
#include "bits/stdc++.h"
 
using namespace std;
using i64 = long long;
 
void solve() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    if (s[i] == 'L') {
      a[min(n - 1, i + 1)] = 1;
      a[max(0, i - 1)] = 1;
    }
  }
  for (int i = 0; i < n; i++) {
    if (a[i] == 1 || s[i] == 'L') {
      cout << s[i];
    } else {
      cout << 'C';
    }
  }
}
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int tt = 1;
  //cin >> tt;
  for (int _ = 1; _ <= tt; _++) {
    solve();
  }
  return 0;
}

C. Array Concatenation

C++ Code
#include <bits/stdc++.h>
 
using namespace std;
using i64 = long long;

constexpr int M = 1000000007;
 
i64 POW(i64 a, int b) {
  i64 res = 1;
  while (b) {
    if (b & 1) {
      res = res * a % M;
    }
    a = a * a % M;
    b >>= 1;
  }
  return res;
}
 
void solve() {
  auto get = [&](i64 sum, i64 presum, int k, int len) {
    i64 POW_2 = POW(2, k);
    i64 inv_2 = POW(2, M - 2);
    return (presum * POW_2 % M + len * sum % M * POW_2 % M * (POW_2 - 1 + M) % M * inv_2 % M) % M;
  };
  int n, m;
  cin >> n >> m;
  vector<i64> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  i64 presum = 0, sum = 0;
  for (int i = 0; i < n; i++) {
    sum = (sum + a[i]) % M;
    presum = (presum + sum) % M;
  }
  i64 ans1 = get(sum, presum, m, n);
  vector<i64> b(n << 1);
  for (int i = 0; i < n; i++) {
    b[i] = a[n - 1 - i];
  }
  for (int i = n; i < (n << 1); i++) {
    b[i] = a[i - n];
  }
  presum = 0, sum = 0;
  for (int i = 0; i < (n << 1); i++) {
    sum = (sum + b[i]) % M;
    presum = (presum + sum) % M;    
  }
  i64 ans2 = get(sum, presum, m - 1, n << 1);
  cout << max(ans1, ans2);
}
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int tt = 1;
  //cin >> tt;
  for (int _ = 1; _ <= tt; _++) {
    solve();
  }
  return 0;
}

E. Draw a triangle

C++ Code
#include "bits/stdc++.h"
 
using namespace std;
using i64 = long long;
using i128 = __int128;
 
i128 exgcd(i128 a, i128 b, i128 &x, i128 &y) {
  if (!b) {
    x = 1;
    y = 0;
    return a;
  }
  i128 d = exgcd(b, a % b, x, y);
  i128 t = x;
  x = y;
  y = t - (a / b) * y;
  return d;
}
 
constexpr i64 N = 1E18;
 
i128 abs(i128 x) {
  if (x < 0) {
    return -x;
  }
  return x;
}
 
void print(i128 x) {
  bool ok = 0;
  if (x < 0) {
    ok = 1;
    x = -x;
  }
  i64 num1 = x / N;
  i64 num2 = x % N;
  if (ok) {
    cout << '-';
  }
  if (x < N) {
    cout << num2;
  } else {
    cout << num1 << setw(18) << setfill('0') << num2;
  }
}
 
void solve() {
  i64 x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  i128 d1 = x2 - x1;
  i128 d2 = y2 - y1;
  i128 ansx, ansy;
  if (d1 == 0) {
    cout << x1 + 1 << ' ' << y1 << '\n';
  } else if (d2 == 0) {
    cout << x1 << ' ' << y1 + 1 << '\n';
  } else {
    i128 g = exgcd(abs(d1), abs(d2), ansy, ansx);
    if (d1 < 0) {
      ansy = -ansy;
    }
    if (d2 > 0) {
      ansx = -ansx;
    }
    print(x1 + ansx);
    cout << ' ';
    print(y1 + ansy);
    cout << '\n';
  }
}
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int tt = 1;
  cin >> tt;
  for (int _ = 1; _ <= tt; _++) {
    solve();
  }
  return 0;
}

M. Youth Finale

原:http://acm.hdu.edu.cn/showproblem.php?pid=1394

C++ Code
#include "bits/stdc++.h"
 
using namespace std;
using i64 = long long;
 
template <typename T>
class Fenwick {
 public:
  int n;
  vector<T> tree;
  Fenwick(const int &n) : n(n), tree(n) {}
  inline void modify(int pos, T x) {
    for ( ; pos <= n; pos += pos & -pos) {
      tree[pos - 1] += x;
    }
  }
  inline T get(int pos) {
    T res = 0;
    for ( ; pos > 0; pos -= pos & -pos) {
      res += tree[pos - 1];
    }
    return res;
  }
  inline T sum(int l, int r) { // (l, r]
    return get(r) - get(l);
  }
};
 
void solve() {
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  Fenwick<i64> f(n);
  i64 ans = 0;
  for (int i = n - 1; i >= 0; i--) {
    ans += f.get(a[i]);
    f.modify(a[i] + 1, 1);
  }
  cout << ans << '\n';
  string s;
  cin >> s;
  i64 res = ans;
  int pos = 0; 
  int now = 0;
  for (int i = 0; i < m; i++) {
    if (s[i] == 'S') {
      res = res + n - 2 * a[pos] + 1;
    } else {
      now ^= 1;
      res = 1LL * (n - 1) * n / 2 - res;
    }
    if (now == 0) {
      pos++;
    } else {
      pos--;
    }
    pos = (pos + n) % n;
    cout << res % 10;
  }
}
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int tt = 1;
  //cin >> tt;
  for (int _ = 1; _ <= tt; _++) {
    solve();
  }
  return 0;
}

标签:Contest,int,res,2022CCPC,Guilin,pos,i64,i128,using
From: https://www.cnblogs.com/kiddingma/p/16899119.html

相关文章

  • 2022ccpc广州
    算是第一场xcpc(?)现场出了的题:E.Elevator 冷静分析以下就会发现其实贡献是前面的比当前数小的数和当前数的差值+1,后面的贡献是比当前小的数和当前数的差于是预处理......
  • 大和証券プログラミングコンテスト2022 Autumn (AtCoder Beginner Contest 277)
    A.^{-1}果然是你ABC的A。//Problem:A-^{-1}//Contest:AtCoder-DaiwaSecuritiesCo.Ltd.ProgrammingContest2022Autumn(AtCoderBeginnerContest27......
  • 大和証券プログラミングコンテスト2022 Autumn (AtCoder Beginner Contest 277)
    A.^{-1}果然是你ABC的A。//Problem:A-^{-1}//Contest:AtCoder-DaiwaSecuritiesCo.Ltd.ProgrammingContest2022Autumn(AtCoderBeginnerContest27......
  • 2022 China Collegiate Programming Contest (CCPC) Guangzhou Onsite I
    I.Infectionn=2000,我们考虑dp我们转化题意发现就是找一个连通子块然后连通块的权重就是其中任何一个点的a[i]其他都是p[i]但是对于连通块相接的点我们都要让他是(1-......
  • Biweekly Contest 91
    BiweeklyContest91ProblemANumberofDistinctAverages思路按照题意模拟即可,最后set的大小就是所求结果代码classSolution:defdistinctAverages(self,nu......
  • 2022CCPC威海站 D - Sternhalma // 状压dp + 记忆化搜索
    题目来源:2022ChinaCollegiateProgrammingContestWeihaiSiteD-Sternhalma题目链接:https://codeforces.com/gym/104023/problem/D题意在一个\(19\)个格子的六边......
  • Weekly Contest 318
    WeeklyContest318ProblemAApplyOperationstoanArray思路按照题意模拟即可代码classSolution:defapplyOperations(self,nums:List[int])->List[int......
  • 广州2022CCPC补题
    IInfection知识点:树上背包第一次写树上背包的题目,没想到就是在区域赛中神奇的是树上背包的复杂度,看起来是\(O(n^3)\),但是实际计算只有\(O(n^2)\)学会树上背包后可......
  • [Leetcode Weekly Contest]319
    链接:LeetCode[Leetcode]2469.温度转换给你一个四舍五入到两位小数的非负浮点数celsius来表示温度,以摄氏度(Celsius)为单位。你需要将摄氏度转换为开氏度(Kelvin)和华......
  • AtCoder Beginner Contest 277 (F,G,Ex)
    之前没细想过OSU那个题,被G薄纱,F也没写完,输麻了懒得放链接,代码可以直接去AtCoder上搜。ID:YunQianQwQF首先求出每列的最大最小值,然后依此排序,如果出现insertion......