Add a bunch of other problems.
Some are not finished...
This commit is contained in:
@@ -0,0 +1,112 @@
|
||||
/* Problem URL: https://codeforces.com/contest/920/problem/A */
|
||||
|
||||
#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 (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_; }
|
||||
#define sortv(v) sort(v.begin(), v.end())
|
||||
#define all(v) (v).begin(), (v).end()
|
||||
|
||||
using vi = vector<int>;
|
||||
using vvi = vector<vi>;
|
||||
using vvvi = vector<vvi>;
|
||||
using vvvvi = vector<vvvi>;
|
||||
|
||||
using ll = long long;
|
||||
|
||||
using vl = vector<ll>;
|
||||
using vvl = vector<vl>;
|
||||
using vvvl = vector<vvl>;
|
||||
using vvvvl = vector<vvvl>;
|
||||
|
||||
template<class v>
|
||||
auto operator<<(ostream &os, const vector<v> &vec)->ostream& {
|
||||
os << vec[0];
|
||||
for (size_t i = 1; i < vec.size(); i++) {
|
||||
os << ' ' << vec[i];
|
||||
}
|
||||
os << '\n';
|
||||
return os;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator>>(istream &is, vector<v> &vec)->istream& {
|
||||
for (auto &i : vec) {
|
||||
is >> i;
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator<<(ostream &os, const vector<vector<v>> &vec)->ostream& {
|
||||
for (auto &i : vec) {
|
||||
os << i[0];
|
||||
for (size_t j = 1; j < i.size(); j++) {
|
||||
os << ' ' << i[j];
|
||||
}
|
||||
os << '\n';
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator>>(istream &is, vector<vector<v>> &vec)->istream& {
|
||||
for (auto &i : vec) {
|
||||
for (auto &j : i) {
|
||||
is >> j;
|
||||
}
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
int t;
|
||||
cin >> t;
|
||||
while (t--) {
|
||||
int n, k;
|
||||
cin >> n >> k;
|
||||
|
||||
int oo = INT32_MAX >> 1;
|
||||
vi fds(n, oo);
|
||||
|
||||
while (k--) {
|
||||
int now;
|
||||
cin >> now;
|
||||
now--;
|
||||
|
||||
fds[now] = 1;
|
||||
|
||||
nrep(i, 1, n) {
|
||||
if (now - i >= 0) {
|
||||
rmin(fds[now - i], i + 1);
|
||||
}
|
||||
|
||||
if (now + i < n) {
|
||||
rmin(fds[now + i], i + 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cout << *max_element(all(fds)) << '\n';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
/* Problem URL: https://codeforces.com/contest/920/problem/B */
|
||||
|
||||
#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 (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_; }
|
||||
#define sortv(v) sort(v.begin(), v.end())
|
||||
#define all(v) (v).begin(), (v).end()
|
||||
|
||||
using vi = vector<int>;
|
||||
using vvi = vector<vi>;
|
||||
using vvvi = vector<vvi>;
|
||||
using vvvvi = vector<vvvi>;
|
||||
|
||||
using ll = long long;
|
||||
|
||||
using vl = vector<ll>;
|
||||
using vvl = vector<vl>;
|
||||
using vvvl = vector<vvl>;
|
||||
using vvvvl = vector<vvvl>;
|
||||
|
||||
template<class v>
|
||||
auto operator<<(ostream &os, const vector<v> &vec)->ostream& {
|
||||
os << vec[0];
|
||||
for (size_t i = 1; i < vec.size(); i++) {
|
||||
os << ' ' << vec[i];
|
||||
}
|
||||
os << '\n';
|
||||
return os;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator>>(istream &is, vector<v> &vec)->istream& {
|
||||
for (auto &i : vec) {
|
||||
is >> i;
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator<<(ostream &os, const vector<vector<v>> &vec)->ostream& {
|
||||
for (auto &i : vec) {
|
||||
os << i[0];
|
||||
for (size_t j = 1; j < i.size(); j++) {
|
||||
os << ' ' << i[j];
|
||||
}
|
||||
os << '\n';
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator>>(istream &is, vector<vector<v>> &vec)->istream& {
|
||||
for (auto &i : vec) {
|
||||
for (auto &j : i) {
|
||||
is >> j;
|
||||
}
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
int t;
|
||||
cin >> t;
|
||||
while (t--) {
|
||||
int n;
|
||||
cin >> n;
|
||||
|
||||
int now = 1;
|
||||
|
||||
vi ans(n);
|
||||
|
||||
rep(i, n) {
|
||||
int l, r;
|
||||
cin >> l >> r;
|
||||
|
||||
if (now > r) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (now <= l) {
|
||||
ans[i] = l;
|
||||
now = l + 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (now <= r) {
|
||||
ans[i] = now;
|
||||
now++;
|
||||
}
|
||||
}
|
||||
|
||||
cout << ans;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,124 @@
|
||||
/* Problem URL: https://codeforces.com/contest/920/problem/C */
|
||||
|
||||
#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 (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_; }
|
||||
#define sortv(v) sort(v.begin(), v.end())
|
||||
#define all(v) (v).begin(), (v).end()
|
||||
|
||||
using vi = vector<int>;
|
||||
using vvi = vector<vi>;
|
||||
using vvvi = vector<vvi>;
|
||||
using vvvvi = vector<vvvi>;
|
||||
|
||||
using ll = long long;
|
||||
|
||||
using vl = vector<ll>;
|
||||
using vvl = vector<vl>;
|
||||
using vvvl = vector<vvl>;
|
||||
using vvvvl = vector<vvvl>;
|
||||
|
||||
template<class v>
|
||||
auto operator<<(ostream &os, const vector<v> &vec)->ostream& {
|
||||
os << vec[0];
|
||||
for (size_t i = 1; i < vec.size(); i++) {
|
||||
os << ' ' << vec[i];
|
||||
}
|
||||
os << '\n';
|
||||
return os;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator>>(istream &is, vector<v> &vec)->istream& {
|
||||
for (auto &i : vec) {
|
||||
is >> i;
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator<<(ostream &os, const vector<vector<v>> &vec)->ostream& {
|
||||
for (auto &i : vec) {
|
||||
os << i[0];
|
||||
for (size_t j = 1; j < i.size(); j++) {
|
||||
os << ' ' << i[j];
|
||||
}
|
||||
os << '\n';
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator>>(istream &is, vector<vector<v>> &vec)->istream& {
|
||||
for (auto &i : vec) {
|
||||
for (auto &j : i) {
|
||||
is >> j;
|
||||
}
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
int n;
|
||||
cin >> n;
|
||||
|
||||
vl fds(n);
|
||||
string a;
|
||||
cin >> fds >> a;
|
||||
|
||||
vvi count(1);
|
||||
|
||||
count[0].push_back(fds[0]);
|
||||
|
||||
nrep(i, 1, n) {
|
||||
if (a[i - 1] == '0') {
|
||||
count.emplace_back();
|
||||
}
|
||||
|
||||
count.back().push_back(fds[i]);
|
||||
}
|
||||
|
||||
vi ans(n);
|
||||
int now = 0;
|
||||
|
||||
repv(j, count) {
|
||||
sortv(j);
|
||||
|
||||
repv(k, j) {
|
||||
ans[now] = k;
|
||||
now++;
|
||||
}
|
||||
}
|
||||
|
||||
bool valid = true;
|
||||
|
||||
nrep(i, 1, n) {
|
||||
if (ans[i] < ans[i - 1]) {
|
||||
valid = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
cout << (valid ? "YES\n" : "NO\n");
|
||||
}
|
||||
244
Educational Codeforces Round 37 (Rated for Div. 2)/D. Tanks.cpp
Normal file
244
Educational Codeforces Round 37 (Rated for Div. 2)/D. Tanks.cpp
Normal file
@@ -0,0 +1,244 @@
|
||||
/* Problem URL: https://codeforces.com/contest/920/problem/D */
|
||||
|
||||
#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 (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_; }
|
||||
#define sortv(v) sort(v.begin(), v.end())
|
||||
#define all(v) (v).begin(), (v).end()
|
||||
|
||||
using vi = vector<int>;
|
||||
using vvi = vector<vi>;
|
||||
using vvvi = vector<vvi>;
|
||||
using vvvvi = vector<vvvi>;
|
||||
|
||||
using ll = long long;
|
||||
|
||||
using vl = vector<ll>;
|
||||
using vvl = vector<vl>;
|
||||
using vvvl = vector<vvl>;
|
||||
using vvvvl = vector<vvvl>;
|
||||
|
||||
template<class v>
|
||||
auto operator<<(ostream &os, const vector<v> &vec)->ostream& {
|
||||
os << vec[0];
|
||||
for (size_t i = 1; i < vec.size(); i++) {
|
||||
os << ' ' << vec[i];
|
||||
}
|
||||
os << '\n';
|
||||
return os;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator>>(istream &is, vector<v> &vec)->istream& {
|
||||
for (auto &i : vec) {
|
||||
is >> i;
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator<<(ostream &os, const vector<vector<v>> &vec)->ostream& {
|
||||
for (auto &i : vec) {
|
||||
os << i[0];
|
||||
for (size_t j = 1; j < i.size(); j++) {
|
||||
os << ' ' << i[j];
|
||||
}
|
||||
os << '\n';
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator>>(istream &is, vector<vector<v>> &vec)->istream& {
|
||||
for (auto &i : vec) {
|
||||
for (auto &j : i) {
|
||||
is >> j;
|
||||
}
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
int n, k;
|
||||
ll v;
|
||||
cin >> n >> k >> v;
|
||||
|
||||
vl a(n);
|
||||
cin >> a;
|
||||
|
||||
if (v == 0) {
|
||||
cout << "YES\n";
|
||||
cout << (ll)1e9 << ' ' << 1 << ' ' << 2 << '\n';
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (accumulate(all(a), 0LL) < v) {
|
||||
cout << "NO\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
auto printans = [&](V<tuple<ll, int, int>> &ans) {
|
||||
for (auto [c, i, j] : ans) {
|
||||
if (c == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
cout << c << ' ' << i << ' ' << j << '\n';
|
||||
}
|
||||
};
|
||||
|
||||
ll mod = v % k;
|
||||
vi ans;
|
||||
|
||||
if (mod == 0) {
|
||||
cout << "YES\n";
|
||||
V<tuple<ll, int, int>> lol;
|
||||
|
||||
int choice = 0;
|
||||
int other = 1;
|
||||
|
||||
nrep(i, 1, n) {
|
||||
lol.emplace_back(1e9, i + 1, choice + 1);
|
||||
}
|
||||
|
||||
lol.emplace_back(v / k, choice + 1, other + 1);
|
||||
|
||||
printans(lol);
|
||||
return 0;
|
||||
}
|
||||
|
||||
ll oo = INT64_MAX >> 1;
|
||||
|
||||
V<V<bool>> dp(n + 1, V<bool>(k));
|
||||
|
||||
nrep(i, 1, n + 1) {
|
||||
dp[i][a[i - 1] % k] = true;
|
||||
rep(j, k) {
|
||||
dp[i][j] = dp[i][j] || dp[i - 1][j] || dp[i - 1][((j - a[i - 1]) % k + k) % k];
|
||||
}
|
||||
}
|
||||
|
||||
auto getans1 = [&](ll mod) {
|
||||
if (!dp[n][mod]) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int ind = n - 1;
|
||||
int act = mod;
|
||||
while (ind >= 0) {
|
||||
while (dp[ind][act]) {
|
||||
ind--;
|
||||
}
|
||||
|
||||
if (!dp[ind + 1][act]) {
|
||||
break;
|
||||
}
|
||||
|
||||
ans.push_back(ind);
|
||||
act = ((act - a[ind]) % k + k) % k;
|
||||
ind--;
|
||||
}
|
||||
|
||||
return !ans.empty();
|
||||
};
|
||||
|
||||
if (!getans1(mod)) {
|
||||
cout << "NO\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (ans.empty()) {
|
||||
cout << "NO\n";
|
||||
return 0;
|
||||
}
|
||||
//
|
||||
// if (ans.size() == 1) {
|
||||
// ll total = a[ans[0]];
|
||||
// V<tuple<ll, int, int>> lol;
|
||||
//
|
||||
// ll other = ans[0] == 0 ? 1 : 0;
|
||||
//
|
||||
// rep(i, n) {
|
||||
// if (i == ans[0]) {
|
||||
// continue;
|
||||
// }
|
||||
//
|
||||
// lol.emplace_back(a[i] / k, i + 1, ans[0] + 1);
|
||||
// total += (a[i] / k) * k;
|
||||
// }
|
||||
//
|
||||
// if (total < v) {
|
||||
// cout << "NO\n";
|
||||
// return 0;
|
||||
// }
|
||||
//
|
||||
// cout << "YES\n";
|
||||
// ll diff = total - v;
|
||||
// lol.emplace_back(diff / k, ans[0] == 0 ? 2 : 1, ans[0] + 1);
|
||||
// printans(lol);
|
||||
//
|
||||
// return 0;
|
||||
// }
|
||||
//
|
||||
V<tuple<ll, int, int>> lol;
|
||||
|
||||
set<int> ignore;
|
||||
ignore.insert(ans[0]);
|
||||
|
||||
nrep(i, 1, ans.size()) {
|
||||
a[ans[0]] += a[ans[i]];
|
||||
a[ans[i]] = 0;
|
||||
lol.emplace_back(1e9, ans[i] + 1, ans[0] + 1);
|
||||
ignore.insert(ans[i]);
|
||||
}
|
||||
|
||||
int other = ans[0] == 0 ? 1 : 0;
|
||||
ignore.insert(other);
|
||||
|
||||
rep(i, n) {
|
||||
if (ignore.count(i)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
lol.emplace_back(1e9, i + 1, other + 1);
|
||||
a[other] += a[i];
|
||||
a[i] = 0;
|
||||
}
|
||||
|
||||
lol.emplace_back(a[other] / k, other + 1, ans[0] + 1);
|
||||
|
||||
a[ans[0]] += a[other] / k * k;
|
||||
|
||||
if (a[ans[0]] < v) {
|
||||
cout << "NO\n";
|
||||
return 0;
|
||||
}
|
||||
|
||||
ll diff = a[ans[0]] - v;
|
||||
|
||||
cout << "YES\n";
|
||||
lol.emplace_back(diff / k, ans[0] + 1, ans[0] == 0 ? 2 : 1);
|
||||
|
||||
printans(lol);
|
||||
}
|
||||
@@ -0,0 +1,134 @@
|
||||
/* Problem URL: https://codeforces.com/contest/920/problem/E */
|
||||
|
||||
#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 (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_; }
|
||||
#define sortv(v) sort(v.begin(), v.end())
|
||||
#define all(v) (v).begin(), (v).end()
|
||||
|
||||
using vi = vector<int>;
|
||||
using vvi = vector<vi>;
|
||||
using vvvi = vector<vvi>;
|
||||
using vvvvi = vector<vvvi>;
|
||||
|
||||
using ll = long long;
|
||||
|
||||
using vl = vector<ll>;
|
||||
using vvl = vector<vl>;
|
||||
using vvvl = vector<vvl>;
|
||||
using vvvvl = vector<vvvl>;
|
||||
|
||||
template<class v>
|
||||
auto operator<<(ostream &os, const vector<v> &vec)->ostream& {
|
||||
os << vec[0];
|
||||
for (size_t i = 1; i < vec.size(); i++) {
|
||||
os << ' ' << vec[i];
|
||||
}
|
||||
os << '\n';
|
||||
return os;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator>>(istream &is, vector<v> &vec)->istream& {
|
||||
for (auto &i : vec) {
|
||||
is >> i;
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator<<(ostream &os, const vector<vector<v>> &vec)->ostream& {
|
||||
for (auto &i : vec) {
|
||||
os << i[0];
|
||||
for (size_t j = 1; j < i.size(); j++) {
|
||||
os << ' ' << i[j];
|
||||
}
|
||||
os << '\n';
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator>>(istream &is, vector<vector<v>> &vec)->istream& {
|
||||
for (auto &i : vec) {
|
||||
for (auto &j : i) {
|
||||
is >> j;
|
||||
}
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
ll n, m;
|
||||
cin >> n >> m;
|
||||
|
||||
V<set<int>> notgraph(n);
|
||||
|
||||
while (m--) {
|
||||
int a, b;
|
||||
cin >> a >> b;
|
||||
|
||||
a--, b--;
|
||||
|
||||
notgraph[a].insert(b);
|
||||
notgraph[b].insert(a);
|
||||
}
|
||||
|
||||
set<int> v;
|
||||
|
||||
rep(i, n) {
|
||||
v.insert(i);
|
||||
}
|
||||
|
||||
vi ans;
|
||||
|
||||
function<int(int)> dfs = [&](int i) {
|
||||
int ans = 1;
|
||||
|
||||
v.erase(i);
|
||||
|
||||
auto itr = v.begin();
|
||||
|
||||
while (itr != v.end()) {
|
||||
if (notgraph[i].count(*itr)) {
|
||||
itr = v.upper_bound(*itr);
|
||||
continue;
|
||||
}
|
||||
|
||||
int now = *itr;
|
||||
ans += dfs(*itr);
|
||||
itr = v.upper_bound(now);
|
||||
}
|
||||
|
||||
return ans;
|
||||
};
|
||||
|
||||
while (!v.empty()) {
|
||||
ans.push_back(dfs(*v.begin()));
|
||||
}
|
||||
|
||||
sortv(ans);
|
||||
cout << ans.size() << '\n';
|
||||
cout << ans;
|
||||
}
|
||||
@@ -0,0 +1,183 @@
|
||||
/* Problem URL: https://codeforces.com/contest/920/problem/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 (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_; }
|
||||
#define sortv(v) sort(v.begin(), v.end())
|
||||
#define all(v) (v).begin(), (v).end()
|
||||
|
||||
using vi = vector<int>;
|
||||
using vvi = vector<vi>;
|
||||
using vvvi = vector<vvi>;
|
||||
using vvvvi = vector<vvvi>;
|
||||
|
||||
using ll = long long;
|
||||
|
||||
using vl = vector<ll>;
|
||||
using vvl = vector<vl>;
|
||||
using vvvl = vector<vvl>;
|
||||
using vvvvl = vector<vvvl>;
|
||||
|
||||
template<class v>
|
||||
auto operator<<(ostream &os, const vector<v> &vec)->ostream& {
|
||||
os << vec[0];
|
||||
for (size_t i = 1; i < vec.size(); i++) {
|
||||
os << ' ' << vec[i];
|
||||
}
|
||||
os << '\n';
|
||||
return os;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator>>(istream &is, vector<v> &vec)->istream& {
|
||||
for (auto &i : vec) {
|
||||
is >> i;
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator<<(ostream &os, const vector<vector<v>> &vec)->ostream& {
|
||||
for (auto &i : vec) {
|
||||
os << i[0];
|
||||
for (size_t j = 1; j < i.size(); j++) {
|
||||
os << ' ' << i[j];
|
||||
}
|
||||
os << '\n';
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator>>(istream &is, vector<vector<v>> &vec)->istream& {
|
||||
for (auto &i : vec) {
|
||||
for (auto &j : i) {
|
||||
is >> j;
|
||||
}
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
vi div(1e6 + 1, 1);
|
||||
|
||||
nrep(i, 2, 1e6 + 1) {
|
||||
if (div[i] > 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int j = i; j <= 1e6; j += i) {
|
||||
div[j] = i;
|
||||
}
|
||||
}
|
||||
|
||||
vi f(1e6 + 1);
|
||||
f[1] = 1;
|
||||
f[2] = 2;
|
||||
|
||||
nrep(i, 3, 1e6 + 1) {
|
||||
int now = 1;
|
||||
int tmp = i;
|
||||
|
||||
while (tmp > 1) {
|
||||
int count = 1;
|
||||
int prime = div[tmp];
|
||||
|
||||
while (tmp % prime == 0) {
|
||||
tmp /= prime;
|
||||
count++;
|
||||
}
|
||||
|
||||
now *= count;
|
||||
}
|
||||
|
||||
f[i] = now;
|
||||
}
|
||||
|
||||
int n, m;
|
||||
cin >> n >> m;
|
||||
|
||||
vi fds(n);
|
||||
cin >> fds;
|
||||
|
||||
while (__builtin_popcount(n) != 1) {
|
||||
n++;
|
||||
fds.push_back(1);
|
||||
}
|
||||
|
||||
V<pair<int, ll>> seg(n * 2);
|
||||
|
||||
nrep(i, n, n * 2) {
|
||||
seg[i] = {fds[i - n], fds[i - n]};
|
||||
}
|
||||
|
||||
for (int i = n - 1; i > 0; i--) {
|
||||
seg[i] = {max(seg[i * 2].first, seg[i * 2 + 1].first), seg[i * 2].second + seg[i * 2 + 1].second};
|
||||
}
|
||||
|
||||
function<void(int, int, int ,int, int)> update = [&](int i, int l, int r, int tl, int tr) {
|
||||
if (l > tr || r < tl || seg[i].first <= 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (l == r) {
|
||||
seg[i] = {f[seg[i].first], f[seg[i].first]};
|
||||
return;
|
||||
}
|
||||
|
||||
int mid = (l + r) >> 1;
|
||||
|
||||
update(i * 2, l, mid, tl, tr);
|
||||
update(i * 2 + 1, mid + 1, r, tl, tr);
|
||||
|
||||
seg[i] = {max(seg[i * 2].first, seg[i * 2 + 1].first), seg[i * 2].second + seg[i * 2 + 1].second};
|
||||
};
|
||||
|
||||
function<ll(int, int, int, int, int)> query = [&](int i, int l, int r, int tl, int tr) {
|
||||
if (l > tr || r < tl) {
|
||||
return 0LL;
|
||||
}
|
||||
|
||||
if (l >= tl && r <= tr) {
|
||||
return seg[i].second;
|
||||
}
|
||||
|
||||
int mid = (l + r) >> 1;
|
||||
|
||||
return query(i * 2, l, mid, tl, tr) + query(i * 2 + 1, mid + 1, r, tl, tr);
|
||||
};
|
||||
|
||||
while (m--) {
|
||||
int t, l, r;
|
||||
cin >> t >> l >> r;
|
||||
l--, r--;
|
||||
|
||||
if (t == 1) {
|
||||
update(1, 0, n - 1, l, r);
|
||||
continue;
|
||||
}
|
||||
|
||||
cout << query(1, 0, n - 1, l, r) << '\n';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,162 @@
|
||||
/* Problem URL: https://codeforces.com/contest/920/problem/G */
|
||||
|
||||
#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 (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_; }
|
||||
#define sortv(v) sort(v.begin(), v.end())
|
||||
#define all(v) (v).begin(), (v).end()
|
||||
|
||||
using vi = vector<int>;
|
||||
using vvi = vector<vi>;
|
||||
using vvvi = vector<vvi>;
|
||||
using vvvvi = vector<vvvi>;
|
||||
|
||||
using ll = long long;
|
||||
|
||||
using vl = vector<ll>;
|
||||
using vvl = vector<vl>;
|
||||
using vvvl = vector<vvl>;
|
||||
using vvvvl = vector<vvvl>;
|
||||
|
||||
template<class v>
|
||||
auto operator<<(ostream &os, const vector<v> &vec)->ostream& {
|
||||
os << vec[0];
|
||||
for (size_t i = 1; i < vec.size(); i++) {
|
||||
os << ' ' << vec[i];
|
||||
}
|
||||
os << '\n';
|
||||
return os;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator>>(istream &is, vector<v> &vec)->istream& {
|
||||
for (auto &i : vec) {
|
||||
is >> i;
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator<<(ostream &os, const vector<vector<v>> &vec)->ostream& {
|
||||
for (auto &i : vec) {
|
||||
os << i[0];
|
||||
for (size_t j = 1; j < i.size(); j++) {
|
||||
os << ' ' << i[j];
|
||||
}
|
||||
os << '\n';
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
template<class v>
|
||||
auto operator>>(istream &is, vector<vector<v>> &vec)->istream& {
|
||||
for (auto &i : vec) {
|
||||
for (auto &j : i) {
|
||||
is >> j;
|
||||
}
|
||||
}
|
||||
return is;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
vi div(1e6 + 1, 1);
|
||||
nrep(i, 2, 1e6 + 1) {
|
||||
if (div[i] > 1) {
|
||||
continue;
|
||||
}
|
||||
|
||||
for (int j = i; j <= 1e6; j += i) {
|
||||
div[j] = i;
|
||||
}
|
||||
}
|
||||
|
||||
int t;
|
||||
cin >> t;
|
||||
while (t--) {
|
||||
int x, p, k;
|
||||
cin >> x >> p >> k;
|
||||
|
||||
vi primes;
|
||||
|
||||
auto getprimes = [&]() {
|
||||
int tmp = p;
|
||||
while (tmp > 1) {
|
||||
primes.push_back(div[tmp]);
|
||||
int prime = div[tmp];
|
||||
|
||||
while (tmp % prime == 0) {
|
||||
tmp /= prime;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
getprimes();
|
||||
|
||||
auto getmuls = [&](ll now) {
|
||||
ll ans = 0;
|
||||
|
||||
nrep(i, 1, 1 << primes.size()) {
|
||||
ll tmp = 1;
|
||||
|
||||
rep(j, primes.size()) {
|
||||
if ((i >> j) & 1) {
|
||||
tmp *= primes[j];
|
||||
}
|
||||
}
|
||||
|
||||
if (__builtin_popcount(i) & 1) {
|
||||
ans += now / tmp;
|
||||
} else {
|
||||
ans -= now / tmp;
|
||||
}
|
||||
}
|
||||
|
||||
return ans;
|
||||
};
|
||||
|
||||
ll inv = getmuls(x);
|
||||
|
||||
ll low = x + 1;
|
||||
ll high = 1e18;
|
||||
ll ans = 0;
|
||||
while (low <= high) {
|
||||
ll mid = ((high - low) >> 1) + low;
|
||||
|
||||
ll act = getmuls(mid) - inv;
|
||||
if (mid - x - act >= k) {
|
||||
ans = mid;
|
||||
high = mid - 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
low = mid + 1;
|
||||
}
|
||||
|
||||
while (__gcd(ans, (ll)p) != 1) {
|
||||
ans++;
|
||||
}
|
||||
|
||||
cout << ans << '\n';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user