Add some more problems and update TODO list
This commit is contained in:
@@ -1,16 +1,22 @@
|
||||
/* Problem URL: https://codeforces.com/contest/2050/problem/F */
|
||||
/* Problem URL: https://codeforces.com/problemset/problem/2050/F */
|
||||
|
||||
#include <bits/stdc++.h>
|
||||
#include <ext/pb_ds/assoc_container.hpp>
|
||||
#include <ext/pb_ds/tree_policy.hpp>
|
||||
|
||||
using namespace std;
|
||||
using namespace __gnu_pbds;
|
||||
|
||||
template <class T, class comp = less<>>
|
||||
using ordered_set = tree<T, null_type , comp , rb_tree_tag , tree_order_statistics_node_update>;
|
||||
|
||||
#define V vector
|
||||
|
||||
#define rmin(a, b) a = min(a, b)
|
||||
#define rmax(a, b) a = max(a, b)
|
||||
|
||||
#define rep(i, lim) for (size_t i = 0; i < (lim); i++)
|
||||
#define nrep(i, s, lim) for (size_t i = s; i < (lim); i++)
|
||||
#define rep(i, lim) for (int i = 0; i < (lim); i++)
|
||||
#define nrep(i, s, lim) for (int i = s; i < (lim); i++)
|
||||
|
||||
#define repv(i, v) for (auto &i : (v))
|
||||
#define fillv(v) for (auto &itr_ : (v)) { cin >> itr_; }
|
||||
@@ -69,25 +75,70 @@ auto operator>>(istream &is, vector<vector<v>> &vec)->istream& {
|
||||
return is;
|
||||
}
|
||||
|
||||
int dp(int i, int j, int k, string &a, string &b, string &c)
|
||||
const int oo = INT32_MAX >> 1;
|
||||
const ll OO = INT64_MAX >> 1;
|
||||
|
||||
|
||||
void pre()
|
||||
{
|
||||
if (i >= a.size() || j >= b.size() || k >= c.size()) {
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
#define TEST 1
|
||||
|
||||
void solve()
|
||||
{
|
||||
int n, q;
|
||||
cin >> n >> q;
|
||||
|
||||
vl a(n);
|
||||
cin >> a;
|
||||
|
||||
if (n == 1) {
|
||||
while (q--) {
|
||||
int l, r;
|
||||
cin >> l >> r;
|
||||
cout << "0" << " \n"[q == 0];
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (a[i] != c[k] && b[j] != c[k]) {
|
||||
return min(dp(i + 1, j, k + 1, a, b, c), dp(i, j + 1, k, a, b, c)) + 1;
|
||||
vl diffs(n - 1);
|
||||
rep(i, n - 1) {
|
||||
diffs[i] = abs(a[i] - a[i + 1]);
|
||||
}
|
||||
|
||||
if (a[i] == b[j]) {
|
||||
return min(dp(i + 1, j, k + 1, a, b, c), dp(i, j + 1, k, a, b, c));
|
||||
int size = n - 1;
|
||||
|
||||
vvl sparse(20, vl(size));
|
||||
|
||||
rep(i, size) {
|
||||
sparse[0][i] = diffs[i];
|
||||
}
|
||||
|
||||
if (a[i] == c[k]) {
|
||||
return dp(i + 1, j, k + 1, a, b, c);
|
||||
nrep(j, 1, 20) {
|
||||
for (int i = 0; i + (1 << (j - 1)) < size; i++) {
|
||||
sparse[j][i] = __gcd(sparse[j - 1][i], sparse[j - 1][i + (1 << (j - 1))]);
|
||||
}
|
||||
}
|
||||
|
||||
return dp(i, j + 1, k + 1, a, b, c);
|
||||
auto squery = [&](int l, int r) {
|
||||
int log = 31 - __builtin_clz(r - l + 1);
|
||||
return __gcd(sparse[log][l], sparse[log][r - (1 << log) + 1]);
|
||||
};
|
||||
|
||||
while (q--) {
|
||||
int l, r;
|
||||
cin >> l >> r;
|
||||
l--, r--;
|
||||
|
||||
if (l == r) {
|
||||
cout << "0" << " \n"[q == 0];
|
||||
continue;
|
||||
}
|
||||
|
||||
cout << squery(l, r - 1) << " \n"[q == 0];
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
@@ -95,12 +146,11 @@ int main()
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
int t;
|
||||
cin >> t;
|
||||
while (t--) {
|
||||
string a, b, c;
|
||||
cin >> a >> b >> c;
|
||||
pre();
|
||||
|
||||
cout << dp(0, 0, 0, a, b, c) << '\n';
|
||||
int t;
|
||||
(TEST && cin >> t) || (t = 1);
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user