-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
288 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
/** | ||
* @file 81604B.cpp | ||
* @author Macesuted ([email protected]) | ||
* @date 2024-08-13 | ||
* | ||
* @copyright Copyright (c) 2024 | ||
* | ||
*/ | ||
|
||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
#define endl '\n' | ||
#define maxn 200005 | ||
#define mod 998244353 | ||
|
||
int64_t Mod(int64_t x) { return x >= mod ? x - mod : x; } | ||
|
||
class SegmentTree { | ||
private: | ||
int laz[maxn << 2]; | ||
int64_t sum[maxn << 2]; | ||
int n; | ||
|
||
void pushUp(int p) { | ||
sum[p] = 0; | ||
if (!laz[p << 1]) sum[p] = Mod(sum[p] + sum[p << 1]); | ||
if (!laz[p << 1 | 1]) sum[p] = Mod(sum[p] + sum[p << 1 | 1]); | ||
return; | ||
} | ||
void insert(int p, int l, int r, int qp, int v) { | ||
if (l == r) return sum[p] = v, void(); | ||
int mid = (l + r) >> 1; | ||
qp <= mid ? insert(p << 1, l, mid, qp, v) : insert(p << 1 | 1, mid + 1, r, qp, v); | ||
return pushUp(p); | ||
} | ||
void update(int p, int l, int r, int ql, int qr, int v) { | ||
if (ql <= l && r <= qr) return laz[p] += v, void(); | ||
int mid = (l + r) >> 1; | ||
if (ql <= mid) update(p << 1, l, mid, ql, qr, v); | ||
if (qr > mid) update(p << 1 | 1, mid + 1, r, ql, qr, v); | ||
return pushUp(p); | ||
} | ||
|
||
public: | ||
void resize(int _n) { return n = _n, void(); } | ||
void insert(int p, int v) { return insert(1, 1, n, p, v); } | ||
void update(int l, int r, int v) { return update(1, 1, n, l, r, v); } | ||
int64_t query(void) { return sum[1]; } | ||
} ST; | ||
|
||
int a[maxn], s[15], f[maxn]; | ||
vector<int> rec[maxn]; | ||
|
||
void solve(void) { | ||
int n, m; | ||
cin >> n >> m; | ||
for (int i = 1; i <= n; i++) cin >> a[i], rec[i].push_back(0); | ||
for (int i = 1; i <= m; i++) cin >> s[i]; | ||
ST.resize(n), f[0] = 1; | ||
for (int i = 1; i <= n; i++) { | ||
for (int j = 1; j <= m; j++) { | ||
int p = (int)rec[a[i]].size() - 1 - s[j]; | ||
if (p >= 0) ST.update(rec[a[i]][p] + 1, rec[a[i]][p + 1], -1); | ||
} | ||
rec[a[i]].push_back(i); | ||
for (int j = 1; j <= m; j++) { | ||
int p = (int)rec[a[i]].size() - 1 - s[j]; | ||
if (p >= 0) ST.update(rec[a[i]][p] + 1, rec[a[i]][p + 1], +1); | ||
} | ||
ST.insert(i, f[i - 1]); | ||
f[i] = ST.query(); | ||
} | ||
cout << f[n] << endl; | ||
return; | ||
} | ||
|
||
int main() { | ||
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); | ||
|
||
int _ = 1; | ||
while (_--) solve(); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
/** | ||
* @file 81604D.cpp | ||
* @author Macesuted ([email protected]) | ||
* @date 2024-08-13 | ||
* | ||
* @copyright Copyright (c) 2024 | ||
* | ||
*/ | ||
|
||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
const int N = (1 << 22) + 10; | ||
const int mod = 1e9 + 7; | ||
|
||
class SegmentTree { | ||
private: | ||
int tree[N << 1][2]; | ||
vector<int> node[25]; | ||
|
||
void pushUp(int p) { | ||
tree[p][0] = tree[p << 1][0] + tree[p << 1 | 1][0]; | ||
tree[p][1] = tree[p << 1][1] + tree[p << 1 | 1][1]; | ||
return; | ||
} | ||
void build(int p, int l, int r, int d, int a[]) { | ||
node[d].push_back(p); | ||
if (l == r) return tree[p][a[l]] = 1, tree[p][!a[l]] = 0, void(); | ||
int mid = (l + r) >> 1; | ||
build(p << 1, l, mid, d - 1, a), build(p << 1 | 1, mid + 1, r, d - 1, a); | ||
return pushUp(p); | ||
} | ||
|
||
public: | ||
void build(int d, int a[]) { | ||
for (int i = 0; i <= d; i++) node[i].clear(); | ||
return build(1, 0, (1 << d) - 1, d, a); | ||
} | ||
void reverse(int d) { | ||
for (int i = 1; i < (int)node[d].size(); i += 2) swap(tree[node[d][i]][0], tree[node[d][i]][1]); | ||
for (int i = node[d][0] - 1; i; i--) pushUp(i); | ||
return; | ||
} | ||
int query(void) { return tree[1][1]; } | ||
} ST; | ||
|
||
int n, ans; | ||
int f[N]; | ||
|
||
int add(int x, int y) { return x + y >= mod ? x + y - mod : x + y; } | ||
|
||
int64_t anss = 0; | ||
void dfs(int d) { | ||
if (d == n) return ans = min(ans, ST.query()), anss = (anss + (int64_t)ST.query() * ST.query()) % mod, void(); | ||
dfs(d + 1); | ||
ST.reverse(d); | ||
dfs(d + 1); | ||
ST.reverse(d); | ||
return; | ||
} | ||
|
||
int main() { | ||
scanf("%d", &n); | ||
for (int i = 0; i < (1 << n); ++i) { | ||
scanf("%d", &f[i]); | ||
} | ||
int ans1 = 0; | ||
ans1 = add(ans1, 1ll * (1 << (n - 1)) * (1 << n) % mod * add(1 << n, mod - 1) % mod); | ||
ans1 = add(ans1, 1ll * (1 << n) * (1 << n) % mod); | ||
printf("%d ", ans1); | ||
|
||
ST.build(n, f); | ||
ans = (1 << n), dfs(0); | ||
for (int i = 0; i < (1 << n); i++) f[i] = !f[i]; | ||
ST.build(n, f); | ||
dfs(0); | ||
printf("%d\n", ans); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/** | ||
* @file 81604G.cpp | ||
* @author Macesuted ([email protected]) | ||
* @date 2024-08-13 | ||
* | ||
* @copyright Copyright (c) 2024 | ||
* | ||
*/ | ||
|
||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
#define endl '\n' | ||
#define maxn 1005 | ||
|
||
int a[maxn]; | ||
|
||
void solve(void) { | ||
int n, k; | ||
cin >> n >> k; | ||
cout << n + (n - 1) / k << endl; | ||
for (int i = 1; i <= n + 1; ++i) a[i] = i; | ||
for (int t = 1; t <= n + (n - 1) / k; t++) { | ||
vector<int> op; | ||
for (int l = 1, r; l <= n; l = r + 1) { | ||
r = l; | ||
while (r <= n && a[r + 1] == a[r] + 1) r++; | ||
if (l == r) continue; | ||
int p = max(l, r - k); | ||
op.push_back(p); | ||
for (int i = p + 1; i <= r; i++) a[i]++; | ||
} | ||
cout << op.size() << ' '; | ||
for (auto i : op) cout << i << ' '; | ||
cout << endl; | ||
} | ||
cout << 2 * n - 1 << endl; | ||
for (int t = 1; t <= 2 * n - 1; t++) { | ||
vector<int> op; | ||
for (int i = 1; i <= n; i++) | ||
if (i == n || (a[i] + 2 == a[i + 1] && a[i + 1] + 1 == a[i + 2])) op.push_back(i), a[++i]--; | ||
cout << op.size() << ' '; | ||
for (auto i : op) cout << i << ' '; | ||
cout << endl; | ||
} | ||
return; | ||
} | ||
|
||
int main() { | ||
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); | ||
|
||
int _ = 1; | ||
cin >> _; | ||
while (_--) solve(); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/** | ||
* @file 81604I.cpp | ||
* @author Macesuted ([email protected]) | ||
* @date 2024-08-13 | ||
* | ||
* @copyright Copyright (c) 2024 | ||
* | ||
*/ | ||
|
||
#include <bits/stdc++.h> | ||
using namespace std; | ||
|
||
__int128 sqrt128(__int128 v) { | ||
__int128 l = 0, r = pow(10, 16); | ||
while (l + 1 < r) { | ||
__int128 mid = l + (r - l) / 2; | ||
(mid * mid <= v ? l : r) = mid; | ||
} | ||
return l; | ||
} | ||
|
||
void print(__int128 ans) { | ||
if (!ans) return cout << 0, void(); | ||
stack<char> S; | ||
while (ans) S.push(ans % 10 + '0'), ans /= 10; | ||
while (!S.empty()) cout << S.top(), S.pop(); | ||
return; | ||
} | ||
|
||
void solve(void) { | ||
int n; | ||
cin >> n, n >>= 1; | ||
string L, R; | ||
cin >> L >> R; | ||
__int128 lv = 0, rv = 0; | ||
for (int i = 0; i < n; i++) lv = lv * 10 + L[i] - '0', rv = rv * 10 + R[i] - '0'; | ||
__int128 sl = sqrt128(lv), sr = sqrt128(rv); | ||
if (lv == rv) { | ||
if (sl * sl != lv) return cout << 0 << endl, void(); | ||
lv = rv = 0; | ||
for (int i = n; i < 2 * n; i++) lv = lv * 10 + L[i] - '0', rv = rv * 10 + R[i] - '0'; | ||
print(sqrt128(rv) - (lv ? sqrt128(lv - 1) : -1)), cout << endl; | ||
return; | ||
} | ||
__int128 vd = sr - sl, vl = 0, vr = 0; | ||
if (sl * sl == lv) vl = 1; | ||
if (sr * sr == rv) vd--, vr = 1; | ||
__int128 ans = 0, full = 1; | ||
lv = rv = 0; | ||
for (int i = n; i < 2 * n; i++) lv = lv * 10 + L[i] - '0', rv = rv * 10 + R[i] - '0', full *= 10; | ||
full = sqrt128(full - 1); | ||
if (vl) ans += (lv ? full - sqrt128(lv - 1) : full + 1); | ||
if (vr) ans += sqrt128(rv) + 1; | ||
ans += vd * (full + 1); | ||
print(ans), cout << endl; | ||
return; | ||
} | ||
|
||
int main() { | ||
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr); | ||
|
||
int _ = 1; | ||
while (_--) solve(); | ||
|
||
return 0; | ||
} |