20251028总结
前言
666今天又挂大分了,C题lemon跑不了3e8,D还有小错误,火大。
分数:
题目
A - queue
666我们可以直接枚举
#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乍一看有点不会,实际上直接判断每个点连到的比它大的点的数量为零的即可。
#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数位就这么多,但
#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分跑路
后记
今天题还挺简单的。