- CWNU算协挑战赛 Round 3
CWNU算协挑战赛 Round 3 题解(代码版)
- @ 2026-10-26 14:26:44
A
for i in range(int(input()): print(eval(input()))
B
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
ll k;
cin >> n >> k;
vector<ll> a(n + 1), pre(n + 1, 0);
map<ll, int> cnt;
ll ans = 0;
cnt[k] = 1;
for (int i = 1; i <= n; i++) {
cin >> a[i];
pre[i] = pre[i - 1] + a[i];
ans += cnt[pre[i]];
cnt[pre[i] + k]++;
}
cout << ans << "\n";
return 0;
}
C
#include<bits/stdc++.h>
#define ll long long
using namespace std;
void Solve() {
int n, m;
cin >> n >> m;
vector<string> a(n);
int total = 0, sx = -1, sy = -1;
for (int i = 0; i < n; i++) {
cin >> a[i];
for (int j = 0; j < m; j++) {
if (a[i][j] == '1') {
total++;
if (sx == -1) {
sx = i;
sy = j;
}
}
}
}
if (total == 0) {
cout << "No" << endl;
return;
}
vector<vector<int>> vis(n, vector<int>(m, 0));
queue<pair<int,int>> q;
q.push({sx, sy});
vis[sx][sy] = true;
int cnt = 0;
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
while (!q.empty()) {
auto [x, y] = q.front(); q.pop();
cnt++;
for (int d = 0; d < 4; d++) {
int nx = x + dx[d], ny = y + dy[d];
if (nx >= 0 && nx < n && ny >= 0 && ny < m
&& !vis[nx][ny] && a[nx][ny] == '1') {
vis[nx][ny] = true;
q.push({nx, ny});
}
}
}
cout << (cnt == total ? "Yes" : "No") << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T = 1;
cin >> T;
while (T--) {
Solve();
}
return 0;
}
D
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<int> a(n);
int mx = 0;
for (int i = 0; i < n; i++) {
cin >> a[i];
mx = max(mx, a[i]);
}
ll ans = 0;
for (int g = 1; g <= mx; g++) {
ll s = 0;
for (int x : a) {
if (x % g == 0) s += x;
}
ans = max(ans, s * g);
}
cout << ans << "\n";
return 0;
}
E
#include<bits/stdc++.h>
#define endl '\n'
#define ll long long
using namespace std;
const int MAXP = 10000;
vector<int> primes;
void init() {
vector<bool> is_p(MAXP + 1, true);
is_p[0] = is_p[1] = false;
for (int i = 2; i <= MAXP; i++) {
if (is_p[i]) {
primes.push_back(i);
for (ll j = (ll)i * i; j <= MAXP; j += i) is_p[j] = false;
}
}
}
void Solve() {
int n;
cin >> n;
int s = 0;
for (int p : primes) {
if ((ll)p * p > n) break;
while (n % p == 0) {
n /= p;
s++;
}
}
if (n > 1) s++;
cout << (s & 1 ? "Alice" : "Bob") << endl;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
init();
int T = 1;
cin >> T;
while (T--) Solve();
return 0;
}
F
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll MOD = 998244353;
ll norm(ll x) {
x %= MOD;
if (x < 0) x += MOD;
return x;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
vector<ll> a(n + 1), b(n + 1);
for (int i = 1; i <= n; i++) {
cin >> a[i];
a[i] = norm(a[i]);
}
for (int i = 1; i <= n; i++) {
cin >> b[i];
b[i] = norm(b[i]);
}
// E = sum_{i=1}^{n-1} b_i * a_i - (sum_{i=1}^{n-1} b_i) * a_n
ll P = 0, T = 0;
for (int i = 1; i < n; i++) {
P = (P + b[i] * a[i]) % MOD;
T = (T + b[i]) % MOD;
}
int q;
cin >> q;
while (q--) {
int type;
cin >> type;
if (type == 1) {
int x;
ll v;
cin >> x >> v;
v = norm(v);
if (x < n) {
P = (P + b[x] * v) % MOD;
}
a[x] = norm(a[x] + v);
} else if (type == 2) {
int x;
ll v;
cin >> x >> v;
v = norm(v);
if (x < n) {
P = (P + a[x] * v) % MOD;
T = (T + v) % MOD;
}
b[x] = norm(b[x] + v);
} else {
ll v;
cin >> v;
v = norm(v);
ll E = norm(P - T * a[n] % MOD);
cout << norm(E + v) << "\n";
}
}
return 0;
}
0 条评论
目前还没有评论...