跳到正文

个人记录

日可艮土莫以贝(白哥很黑模拟赛)

King_tissue约 6 分钟
原文
文章信息与版本

文章信息

收录
2025年12月12日
更新
2025年12月12日
篇幅
约 6 分钟

版本

  1. v1当前

标题何以为。

T1

祝睿融题目。

逆序对,用归并排序,居然还可以树状数组,居然还有平衡树。

C++
#include <bits/stdc++.h>
#define vi vector<int>
#define mid (l + r) / 2
using namespace std;
const int N = 1e6 + 5;
int n;
vi a(N), b(N), c(N), s(N); // b 是读入数组 c 是空 vector s 是归并读取的数组
int Gui_sort(vi& a, int l, int r, vi& s) { // 逆序对数量(1 奇数 0 偶数)
// 归并排序确定逆序对数量
  if (l >= r) return 0;
  int ans = (Gui_sort(a, l, mid, s) + Gui_sort(a, mid + 1, r, s)) % 2;
  int L = l, R = mid + 1, k = l;
  while (L <= mid && R <= r) {
    if (a[L] <= a[R]) {
      s[k++] = a[L++];
    } else {
      ans += (mid - L + 1); ans %= 2;
      s[k++] = a[R++];
    }
  }
  while (L <= mid) s[k++] = a[L++];
  while (R <= r) s[k++] = a[R++];
  for (int i = l; i <= r; i++) a[i] = s[i];
  return ans;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  int t; cin >> t; while (t--) {
    a = c;
    cin >> n;
    for (int i = 0; i < n; i++) cin >> a[i];
    if (n == 1) { // 0对逆序对
      cout << "Yes\n";
      continue;
    }
    if (n == 2) {
      if (a[0] == 1 && a[1] == 2) {
        cout << "Yes\n"; // 实际相当于 0 对逆序对
      } else {
        cout << "No\n"; // 一对逆序对
      }
      continue;
    }
    b = a, s = c;
    if (Gui_sort(b, 0, n - 1, s) == 0) {
      cout << "Yes\n"; // 偶数对
    } else {
      cout << "No\n"; // 奇数对
    }
  }
  return 0;
}

T2

我是美丽祝睿融。

起点为什么是 1。

起点为什么是 1。

沟槽的起点,

沟槽的T2,

沟槽的出题人!

(我原本的做法起点必须是 0)

何以为。

C++
#include <bits/stdc++.h>
#define int long long
using namespace std;
int n, x1, x2, c1, c2;
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  int ceshidianbiaohaohemeilizhuruirong, T;
  cin >> ceshidianbiaohaohemeilizhuruirong >> T;
  while (T--) {
    cin >> n >> x1 >> c1 >> x2 >> c2;
    if (x2 == 1) {
      cout << ((n - 1) % x1 ? -1 : ((n - 1) / x1 * c1)) << "\n";
      continue;
    }
    int s = 1, D = LONG_LONG_MAX, u, ans;
    for (int i = 0;; i++, s *= x2) {
      if ((n - s) % x1) goto dick;
      u = (n - s) / x1, ans = i * c2;
      for (int j = 1; j <= i; j++) {
        ans += (u % x2) * c1; u /= x2;
      }
      ans += u * c1, D = min(D, ans);
      dick: if (s > n / x2) break;
    }
    cout << (D == LONG_LONG_MAX ? -1 : D) << "\n";
  }
  return 0;
}

T3

人类智慧。

李超线段树是什么。

我们充分发扬人类智慧。

嗯。

C++
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int N = 1e6 + 5;
int n, a[N], dp[N], maxn, minn;
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
  cin >> n;
  bool flag = 1;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
    flag &= (a[i] >= a[i - 1]);
  }
  if (flag) {
    cout << (a[n] - a[1]) * (a[n] - a[1]) << "\n";
    return 0;
  }
  for (int i = 1; i <= n; i++) {
    maxn = -1e18, minn = 1e18;
    for (int j = i; j >= 1 && abs(i - j) <= 25; j--) {
      maxn = max(maxn, a[j]);
      minn = min(minn, a[j]);
      dp[i] = max(dp[i], dp[j - 1] + (maxn - minn) * (maxn - minn));
    }
  }
  cout << dp[n] << "\n";
  return 0;
}

T4

何以为。

看不懂。

总结

何意味。

原文