# Harbour.Space Scholarship Contest 2021-2022 (Div. 1 + Div. 2) 题解 (ABCDEF)

## A. Digits Sum

#include <bits/stdc++.h>
#define repeat(i, a, b) for (int i = (a), ib = (b); i < ib; i++)
#define repeat_back(i, a, b) for (int i = (b) - 1, ib = (a);i >= ib; i--)
using namespace std;
namespace start {
typedef long long ll; const int inf = INT_MAX >> 1; const ll INF = INT64_MAX >> 1;
ll read() { ll x; if (scanf("%lld", &x) != 1) exit(0); return x; } // will detect EOF
void print(ll x, bool e = 0) { printf("%lld%c", x, " \n"[e]); }
const int N = 500010;
} using namespace start;
#define OK { puts("Yes"); return; }
#define GG { puts("No"); return; }
void Solve() {
int n = read();
print((n + 1) / 10, 1);
}
signed main() {
// freopen("data.txt", "r", stdin);
int T = 1; T = read();
repeat (ca, 1, T + 1) {
Solve();
}
return 0;
}


## B. Reverse String

#include <bits/stdc++.h>
#define repeat(i, a, b) for (int i = (a), ib = (b); i < ib; i++)
#define repeat_back(i, a, b) for (int i = (b) - 1, ib = (a);i >= ib; i--)
using namespace std;
namespace start {
typedef long long ll; const int inf = INT_MAX >> 1; const ll INF = INT64_MAX >> 1;
ll read() { ll x; if (scanf("%lld", &x) != 1) exit(0); return x; } // will detect EOF
void print(ll x, bool e = 0) { printf("%lld%c", x, " \n"[e]); }
const int N = 500010;
} using namespace start;
#define OK { puts("Yes"); return; }
#define GG { puts("No"); return; }
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
int x = rnd() % 100;
template<typename string>
struct Hash{
template<int b,int mod>
struct hs{
vector<int> a,p;
hs(const string &s=""){
a={0},p={1};
for(auto c:s){
a.push_back((1ll*a.back()*b+(c^x))%mod);
p.push_back(1ll*p.back()*b%mod);
}
}
ll q(int l,int r){
return (a[r+1]-1ll*a[l]*p[r-l+1]%mod+mod)%mod;
}
};
hs<257,1000000007> h1;
hs<257,2147483647> h2;
Hash(const string &s):h1(s),h2(s){}
pair<ll, ll> query(int l,int r){
return {h1.q(l,r),h2.q(l,r)};
}
};
char s[N], t[N];
void Solve() {
scanf("%s%s", s, t);
int n = strlen(s), m = strlen(t);
Hash<string> ss(s), tt(t);
repeat (i, 0, m)
repeat (j, 0, n - i)
if (ss.query(j, j + i) == tt.query(0, i)) {
int f = true;
repeat (p, i + 1, m)
if (t[p] != s[i + j - p + i]) {
f = false;
break;
}
if (f) { OK; }
}
GG;
}
signed main() {
// freopen("data.txt", "r", stdin);
int T = 1; T = read();
repeat (ca, 1, T + 1) {
Solve();
}
return 0;
}


## C. Penalty

#include <bits/stdc++.h>
#define repeat(i, a, b) for (int i = (a), ib = (b); i < ib; i++)
#define repeat_back(i, a, b) for (int i = (b) - 1, ib = (a);i >= ib; i--)
using namespace std;
namespace start {
typedef long long ll; const int inf = INT_MAX >> 1; const ll INF = INT64_MAX >> 1;
ll read() { ll x; if (scanf("%lld", &x) != 1) exit(0); return x; } // will detect EOF
void print(ll x, bool e = 0) { printf("%lld%c", x, " \n"[e]); }
const int N = 500010;
} using namespace start;
#define OK { puts("Yes"); return; }
#define GG { puts("No"); return; }
char s[N];
void Solve() {
scanf("%s", s);
auto cnt = array<int, 2>{0};
int ans = 10;
repeat (i, 0, 10) {
if (s[i] == '1') cnt[i % 2]++;
else if (s[i] == '?' && i % 2 == 1) cnt[1]++;
if ((9 - i) / 2 < cnt[1] - cnt[0])
ans = min(ans, i + 1);
}
cnt = array<int, 2>{0};
repeat (i, 0, 10) {
if (s[i] == '1') cnt[i % 2]++;
else if (s[i] == '?' && i % 2 == 0) cnt[0]++;
if ((9 - i + 1) / 2 < cnt[0] - cnt[1])
ans = min(ans, i + 1);
}
print(ans, 1);
}
signed main() {
// freopen("data.txt", "r", stdin);
int T = 1; T = read();
repeat (ca, 1, T + 1) {
Solve();
}
return 0;
}


## D. Backspace

#include <bits/stdc++.h>
#define repeat(i, a, b) for (int i = (a), ib = (b); i < ib; i++)
#define repeat_back(i, a, b) for (int i = (b) - 1, ib = (a);i >= ib; i--)
using namespace std;
namespace start {
typedef long long ll; const int inf = INT_MAX >> 1; const ll INF = INT64_MAX >> 1;
ll read() { ll x; if (scanf("%lld", &x) != 1) exit(0); return x; } // will detect EOF
void print(ll x, bool e = 0) { printf("%lld%c", x, " \n"[e]); }
const int N = 500010;
} using namespace start;
#define OK { puts("Yes"); return; }
#define GG { puts("No"); return; }
#define int ll
char s[N], t[N];
void Solve() {
scanf("%s%s", s, t);
int n = strlen(s), m = strlen(t);
int p = m - 1;
repeat_back (i, 0, n) {
if (p >= 0 && s[i] == t[p]) {
p--;
} else {
i--;
}
}
if (p == -1) OK;
GG;
}
signed main() {
// freopen("data.txt", "r", stdin);
int T = 1; T = read();
repeat (ca, 1, T + 1) {
Solve();
}
return 0;
}


## E. Permutation Shift

#include <bits/stdc++.h>
#define repeat(i, a, b) for (int i = (a), ib = (b); i < ib; i++)
#define repeat_back(i, a, b) for (int i = (b) - 1, ib = (a);i >= ib; i--)
using namespace std;
namespace start {
typedef long long ll; const int inf = INT_MAX >> 1; const ll INF = INT64_MAX >> 1;
ll read() { ll x; if (scanf("%lld", &x) != 1) exit(0); return x; } // will detect EOF
void print(ll x, bool e = 0) { printf("%lld%c", x, " \n"[e]); }
const int N = 500010;
} using namespace start;
#define OK { puts("Yes"); return; }
#define GG { puts("No"); return; }
int Count(int a[],int n){
static bool vis[N];
int cnt=0;
fill(vis,vis+n,0);
repeat(i,0,n)if(!vis[i]){
for(int p=a[i];p!=i;p=a[p])
vis[p]=1;
cnt++;
}
return cnt;
}
vector<int> ans;
int a[N], cnt[N];
int b[N];
void Solve() {
ans.clear();
int n = read(), k = read();
fill(cnt, cnt + n, 0);
repeat (i, 0, n) {
a[i] = read() - 1;
cnt[(i + n - a[i]) % n]++;
}
repeat (i, 0, n) {
if (cnt[i] >= n / 3) {
repeat (j, 0, n) b[j] = a[(j + i) % n];
if (n - Count(b, n) <= k)
ans.push_back(i);
}
}
sort(ans.begin(), ans.end());
print(ans.size());
repeat (i, 0, ans.size())
print(ans[i], i == ib - 1);
}
signed main() {
// freopen("data.txt", "r", stdin);
int T = 1; T = read();
repeat (ca, 1, T + 1) {
Solve();
}
return 0;
}


## F. Pairwise Modulo

1. 维护一个集合，支持插入 x，查询 $\displaystyle\sum_{i\in \text Set}i \bmod x$
2. 维护一个集合，支持插入 x，查询 $\displaystyle\sum_{i\in \text Set}x \bmod i$

#include <bits/stdc++.h>
#define repeat(i, a, b) for (int i = (a), ib = (b); i < ib; i++)
#define repeat_back(i, a, b) for (int i = (b) - 1, ib = (a);i >= ib; i--)
using namespace std;
namespace start {
typedef long long ll; const int inf = INT_MAX >> 1; const ll INF = INT64_MAX >> 1;
ll read() { ll x; if (scanf("%lld", &x) != 1) exit(0); return x; } // will detect EOF
void print(ll x, bool e = 0) { printf("%lld%c", x, " \n"[e]); }
const int N = 500010;
} using namespace start;
#define OK { puts("Yes"); return; }
#define GG { puts("No"); return; }
#define int ll
struct zkw {
const ll a0 = 0;
int n; ll a[N * 4];
void init(int inn, ll in[] = nullptr) { // A[x] = a0 or in[x]
n = 1; while (n < inn) n <<= 1;
fill(a + n, a + n * 2, a0);
if (in) repeat (i, 0, inn) a[n + i] = in[i];
repeat_back (i, 1, n) up(i);
}
void up(int x) { // private
a[x] = a[x * 2] + a[x * 2 + 1];
}
void add(int x, ll k) { // A[x] += k
x += n;
a[x] += 1;
while (x >>= 1) up(x);
}
ll sum(int l, int r) { // U(A[l, r])
ll ans = a0; l += n - 1, r += n + 1;
while (l + 1 < r){
if (~l & 1) ans = (ans + a[l + 1]);
if ( r & 1) ans = (ans + a[r - 1]);
l >>= 1, r >>= 1;
}
return ans;
}
} zkw, tr;
int ans[N];
void Solve() {
int n = read();
zkw.init(300000); tr.init(300000);
ll sum = 0;
repeat (i, 0, n) {
int x = read(); sum += x;
if (i) ans[i] = ans[i - 1];
ans[i] += sum;
ans[i] += x * i - tr.sum(0, x);
for (int j = x; j <= 300000; j += x) {
// orz(j, j + x - 1);
// cout << tr.qb(j, j + x - 1) << endl; pause;
ans[i] -= zkw.sum(j, min(300000ll, j + x - 1)) * j;
tr.add(j, j / x * x);
tr.add(min(300000ll, j + x - 1) + 1, -j / x * x);
}
print(ans[i], i == n - 1);
}
}
signed main() {
// freopen("data.txt", "r", stdin);
int T = 1; // T = read();
repeat (ca, 1, T + 1) {
Solve();
}
return 0;
}

posted @ 2021-07-23 01:27  axiomofchoice  阅读(144)  评论(0编辑  收藏  举报