跳到正文

个人记录

20251028总结

__LZH__约 5 分钟
原文
文章信息与版本

文章信息

发布
2025年10月28日
收录
2026年11月27日
更新
2026年11月27日
篇幅
约 5 分钟

版本

  1. v1当前

前言

666今天又挂大分了,C题lemon跑不了3e8,D还有小错误,火大。

分数:95+100+55+5095 + 100 + 55 + 50

题目

A - queue

666我们可以直接枚举 VV 再 O(n)O(n) 判断,因为 V≤⌊wn⌋V \leq \lfloor \frac{w}{n} \rfloor,总时间复杂度为 O(w)O(w)

C++
#include<bits/stdc++.h>

#define int long long

using namespace std;

const int N = 3e5 + 10;

int n, m, a[N], b[N];
map<int, int> mp;

signed main(){
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  for(int i = 1; i <= n; i++){
    cin >> a[i];
  }
  if(n == 1) {
    cout << 0;
    return 0;
  }
  int ans = n;
  for(int i = 0; (n - 1) * i <= m; i++){
    unordered_map<int, int> mp;
    int mx = 0;
    for(int j = 1; j <= n; j++){
      b[j] = a[j] - (j - 1) * i, mp[b[j]]++; 
      if(b[j] + (n - 1) * i > m || !b[j]){
        continue;
      }
      if(mp[b[j]] > mx){
        mx = mp[b[j]];
      }
    }
    ans = min(ans, n - mx);
  }
  cout << ans;
  return 0;
}
/*
10 2
2 2 1 2 2 1 1 2 2 2 2

6 1000
1 2 999 4 72 6
*/ 

B - compare

666乍一看有点不会,实际上直接判断每个点连到的比它大的点的数量为零的即可。

C++
#include<bits/stdc++.h>

#define int long long

using namespace std;

const int N = 2e5 + 10;

int n, m, q, d[N], ans;

signed main(){
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n >> m;
  for(int i = 1, x, y; i <= m; i++){
    cin >> x >> y;
    d[x] += (x < y), d[y] += (y < x);
  }
  for(int i = 1; i <= n; i++){
    ans += !d[i];
  }
  cin >> q;
  for(int op, x, y; q--; ){
    cin >> op;
    if(op == 1){
      cin >> x >> y;
      ans -= !d[x] + !d[y];
      d[x] += (x < y), d[y] += (y < x);
      ans += !d[x] + !d[y];
    }else if(op == 2){
      cin >> x >> y;
      ans -= !d[x] + !d[y];
      d[x] -= (x < y), d[y] -= (y < x);
      ans += !d[x] + !d[y];
    }else{
      cout << ans << '\n';
    }
  }
  return 0;
}

C - xor

666数位就这么多,但 ai≤109a_i \leq 10^9,于是我们便可以直接找相邻的长度不超过 6060 的段去判断即可。

C++
#include<bits/stdc++.h>

#define int long long

using namespace std;

const int N = 2e5 + 10;

int T, n, a[N], pre[N];

void solve(){
  cin >> n;
  for(int i = 1; i <= n; i++){
    cin >> a[i];
    pre[i] = pre[i - 1] ^ a[i];
  }
  int ans = 1e18;
  for(int i = 1; i <= n; i++){
    for(int j = i; j >= max(1ll, i - 40); j--){
      for(int k = j - 1; k >= max(1ll, i - 40); k--){
        if((pre[i] ^ pre[j - 1]) < (pre[j - 1] ^ pre[k - 1])){
          ans = min(ans, (i - j) + ((j - 1) - k));
        }
      }
    }
  }
  cout << (ans == 1e18 ? -1 : ans) << '\n';
}

signed main(){
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> T;
  while(T--){
    solve();
  }
  return 0;
}

D - yugo

666不会80分跑路

后记

今天题还挺简单的。

原文