complete 18937.cpp 24518.cpp

This commit is contained in:
2026-03-19 02:50:57 +09:00
parent 7f6e7da73f
commit 7768f8b446
2 changed files with 68 additions and 17 deletions

View File

@@ -0,0 +1,52 @@
#include <algorithm>
#include <cstdint>
#include <iostream>
#include <string>
#define let auto
#define fn auto
using namespace std;
typedef size_t usize;
typedef uint64_t u64;
const let WHITE_KING = "Whiteking";
const let BLACK_KING = "Blackking";
fn fastio() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
}
fn main() -> int {
usize n;// count of logs
cin >> n;
let arr = new u64[n];// length of each log
for (usize i = 0; i < n; i++) {
cin >> arr[i];
}
string who;
cin >> who;
let first = (who[0] == 'W') ? false : true;
let g = 0;
for (usize i = 0; i < n; i++) {
let e = arr[i] - 2;
g ^= e;
}
//
// W0B WOOOB
if (g == 0) {
cout << (first ? WHITE_KING : BLACK_KING);
} else {
cout << (!first ? WHITE_KING : BLACK_KING);
}
// free
delete[] arr;
return 0;
}

View File

@@ -8,7 +8,7 @@
using namespace std;
const usize MOD = 1'000'000'007;
const usize MOD = 1000000007;
fn fastio() {
ios::sync_with_stdio(false);
@@ -32,19 +32,19 @@ fn well_known_subarr_sum(usize d, usize lo, usize hi /* exclusive */, usize m) -
if (lo / m == hi / m) {
res += ((hi_margin * (hi_margin - 1) / 2) - (lo_margin * (lo_margin - 1) / 2)) * d;
res %= MOD;
return res;
} else {
res += (hi_margin * (hi_margin - 1) / 2) * d;
res %= MOD;
res += (m * (m - 1) / 2 - lo_margin * (lo_margin - 1) / 2) * d;
res %= MOD;
let d_cycle = (d * (m * (m - 1) / 2) % MOD) % MOD;
let cycle_cnt = (hi - lo - (hi_margin + m - lo_margin)) / m;
res += cycle_cnt * d_cycle;
res %= MOD;
}
res += (hi_margin * (hi_margin - 1) / 2) * d;
res %= MOD;
res += (m * (m - 1) / 2 - lo_margin * (lo_margin - 1) / 2) * d;
res %= MOD;
let d_cycle = (d * (m * (m - 1) / 2) % MOD) % MOD;
let cycle_cnt = (hi - lo - (hi_margin + m - lo_margin)) / m;
res += cycle_cnt * d_cycle;
res %= MOD;
return res;
}
@@ -52,16 +52,16 @@ fn well_known_sum(usize n, usize m) -> usize {
let res = (usize) 0;
let steps = vector<usize>();
steps.push_back(n + 1);
for (usize i = 2; i <= (usize) pow(n, 0.5) + 1; i++) {
let k = (usize) pow(n, 0.5);
for (usize i = 2; i <= k + 1; i++) {
steps.push_back(n / i + 1);
}
for (usize i = 1; i < (usize) pow(n, 0.5); i++) {
let step_size = steps.size();
for (usize i = 1; i < steps[step_size - 1]; i++) {
res += (n / i) * (i % m);
res %= MOD;
}
let step_size = steps.size();
for (usize i = 0; i < step_size - 1; i++) {
let temp = well_known_subarr_sum(i + 1, steps[i + 1], steps[i], m);
res += temp;
@@ -84,7 +84,6 @@ fn main() -> int {
} else if (m == 1) {
cout << 0 << endl;
} else {
cout << well_known_sum_draft(n, m) << endl;
cout << well_known_sum(n, m) << endl;
}
return 0;