Add a bunch of other problems.
Some are not finished...
This commit is contained in:
93
Codeforces Round 1003 (Div. 4)/A. Skibidus and Amog'u.cpp
Normal file
93
Codeforces Round 1003 (Div. 4)/A. Skibidus and Amog'u.cpp
Normal file
@@ -0,0 +1,93 @@
|
||||
/* Problem URL: https://codeforces.com/contest/2065/problem/0 */
|
||||
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#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 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;
|
||||
scanf("%d", &t);
|
||||
while (t--) {
|
||||
char fds[11];
|
||||
scanf("%s", fds);
|
||||
|
||||
char *ptr = fds;
|
||||
while (*ptr != 0) {
|
||||
ptr++;
|
||||
}
|
||||
|
||||
ptr[-1] = 0;
|
||||
ptr[-2] = 'i';
|
||||
|
||||
puts(fds);
|
||||
}
|
||||
}
|
||||
93
Codeforces Round 1003 (Div. 4)/B. Skibidus and Ohio.cpp
Normal file
93
Codeforces Round 1003 (Div. 4)/B. Skibidus and Ohio.cpp
Normal file
@@ -0,0 +1,93 @@
|
||||
/* Problem URL: https://codeforces.com/contest/2065/problem/B */
|
||||
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#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 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--) {
|
||||
string a;
|
||||
cin >> a;
|
||||
|
||||
size_t size = a.size();
|
||||
nrep(i, 1, a.size()) {
|
||||
if (a[i] == a[i - 1]) {
|
||||
size = 1;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
cout << size << '\n';
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,118 @@
|
||||
/* Problem URL: https://codeforces.com/contest/2065/problem/C1 */
|
||||
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#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 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, m;
|
||||
cin >> n >> m;
|
||||
|
||||
vi a(n);
|
||||
cin >> a;
|
||||
int num;
|
||||
cin >> num;
|
||||
|
||||
if (num - a[0] < a[0]) {
|
||||
a[0] = num - a[0];
|
||||
}
|
||||
|
||||
bool pos = true;
|
||||
nrep(i, 1, n) {
|
||||
if (num - a[i] < a[i] && num - a[i] >= a[i - 1]) {
|
||||
a[i] = num - a[i];
|
||||
continue;
|
||||
}
|
||||
|
||||
if (a[i] < a[i - 1] && num - a[i] >= a[i - 1]) {
|
||||
a[i] = num - a[i];
|
||||
continue;
|
||||
}
|
||||
|
||||
if (a[i] >= a[i - 1]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
pos = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if (pos) {
|
||||
cout << "YES\n";
|
||||
} else {
|
||||
cout << "NO\n";
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
/* Problem URL: https://codeforces.com/contest/2065/problem/C2 */
|
||||
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#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 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, m;
|
||||
cin >> n >> m;
|
||||
|
||||
vl a(n);
|
||||
cin >> a;
|
||||
vl b(m);
|
||||
cin >> b;
|
||||
|
||||
sortv(b);
|
||||
|
||||
if (b[0] - a[0] < a[0]) {
|
||||
a[0] = b[0] - a[0];
|
||||
}
|
||||
|
||||
bool pos = true;
|
||||
nrep(i, 1, a.size()) {
|
||||
int low = 0;
|
||||
int high = b.size() - 1;
|
||||
int ans = b.size();
|
||||
while (low <= high) {
|
||||
int mid = (low + high) / 2;
|
||||
|
||||
if (b[mid] - a[i] >= a[i - 1]) {
|
||||
ans = mid;
|
||||
high = mid - 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
low = mid + 1;
|
||||
}
|
||||
|
||||
if (ans != b.size() && b[ans] - a[i] > a[i] && a[i] >= a[i - 1]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ans != b.size() && b[ans] - a[i] >= a[i - 1]) {
|
||||
a[i] = b[ans] - a[i];
|
||||
continue;
|
||||
}
|
||||
|
||||
if (a[i] >= a[i - 1]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
pos = false;
|
||||
break;
|
||||
}
|
||||
|
||||
cout << (pos ? "YES\n" : "NO\n");
|
||||
}
|
||||
}
|
||||
105
Codeforces Round 1003 (Div. 4)/D. Skibidus and Sigma.cpp
Normal file
105
Codeforces Round 1003 (Div. 4)/D. Skibidus and Sigma.cpp
Normal file
@@ -0,0 +1,105 @@
|
||||
/* Problem URL: https://codeforces.com/contest/2065/problem/D */
|
||||
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#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 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, m;
|
||||
cin >> n >> m;
|
||||
|
||||
V<pair<ll, V<ll>>> arrays(n, pair<ll, V<ll>>(0, V<ll>(m)));
|
||||
|
||||
for (auto &[num, arr] : arrays) {
|
||||
for (auto &i : arr) {
|
||||
cin >> i;
|
||||
num += i;
|
||||
}
|
||||
}
|
||||
|
||||
sort(arrays.begin(), arrays.end(), greater<>());
|
||||
|
||||
ll total = 0;
|
||||
ll pref = 0;
|
||||
for (auto &[num, arr] : arrays) {
|
||||
for (auto i : arr) {
|
||||
pref += i;
|
||||
total += pref;
|
||||
}
|
||||
}
|
||||
|
||||
cout << total << '\n';
|
||||
}
|
||||
}
|
||||
127
Codeforces Round 1003 (Div. 4)/E. Skibidus and Rizz.cpp
Normal file
127
Codeforces Round 1003 (Div. 4)/E. Skibidus and Rizz.cpp
Normal file
@@ -0,0 +1,127 @@
|
||||
/* Problem URL: https://codeforces.com/contest/2065/problem/E */
|
||||
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
#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 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 x, y, z;
|
||||
cin >> x >> y >> z;
|
||||
|
||||
if (z < abs(x - y) || z > max(x, y)) {
|
||||
cout << "-1\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
string ans;
|
||||
int zeroes = x > y ? 1 : 0;
|
||||
|
||||
if (zeroes) {
|
||||
rep(i, z) {
|
||||
ans.push_back('0');
|
||||
x--;
|
||||
}
|
||||
} else {
|
||||
rep(i, z) {
|
||||
ans.push_back('1');
|
||||
y--;
|
||||
}
|
||||
}
|
||||
|
||||
int lim = x + y - z;
|
||||
zeroes ^= 1;
|
||||
|
||||
while (x > 0 && y > 0) {
|
||||
if (zeroes) {
|
||||
ans.push_back('0');
|
||||
x--;
|
||||
} else {
|
||||
ans.push_back('1');
|
||||
y--;
|
||||
}
|
||||
zeroes ^= 1;
|
||||
}
|
||||
|
||||
while (x > 0) {
|
||||
ans.push_back('0');
|
||||
x--;
|
||||
}
|
||||
while (y > 0) {
|
||||
ans.push_back('1');
|
||||
y--;
|
||||
}
|
||||
|
||||
cout << ans << '\n';
|
||||
}
|
||||
}
|
||||
132
Codeforces Round 1003 (Div. 4)/F. Skibidus and Slay.cpp
Normal file
132
Codeforces Round 1003 (Div. 4)/F. Skibidus and Slay.cpp
Normal file
@@ -0,0 +1,132 @@
|
||||
/* Problem URL: https://codeforces.com/contest/2065/problem/F */
|
||||
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#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 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;
|
||||
|
||||
vi color(n + 1);
|
||||
rep(i, n) {
|
||||
cin >> color[i + 1];
|
||||
}
|
||||
|
||||
vvi graph(n + 1);
|
||||
rep(i, n - 1) {
|
||||
int a, b;
|
||||
cin >> a >> b;
|
||||
|
||||
graph[a].push_back(b);
|
||||
graph[b].push_back(a);
|
||||
}
|
||||
|
||||
vi parent(n + 1);
|
||||
|
||||
string ans(n, '0');
|
||||
function<void(int, int)> dfs = [&](int i, int p){
|
||||
if (color[i] == color[p]) {
|
||||
ans[color[i] - 1] = '1';
|
||||
}
|
||||
|
||||
if (color[i] == color[parent[p]]) {
|
||||
ans[color[i] - 1] = '1';
|
||||
}
|
||||
|
||||
parent[i] = p;
|
||||
|
||||
map<int, int> count;
|
||||
for (auto j : graph[i]) {
|
||||
if (j == p) {
|
||||
continue;
|
||||
}
|
||||
|
||||
count[color[j]]++;
|
||||
dfs(j, i);
|
||||
}
|
||||
|
||||
for (auto &i : count) {
|
||||
if (i.second >= 2) {
|
||||
ans[i.first - 1] = '1';
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
dfs(1, 0);
|
||||
|
||||
cout << ans << '\n';
|
||||
}
|
||||
}
|
||||
139
Codeforces Round 1003 (Div. 4)/G. Skibidus and Capping.cpp
Normal file
139
Codeforces Round 1003 (Div. 4)/G. Skibidus and Capping.cpp
Normal file
@@ -0,0 +1,139 @@
|
||||
/* Problem URL: https://codeforces.com/contest/2065/problem/G */
|
||||
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
#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 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);
|
||||
|
||||
V<bool> isprime(2e5 + 1, true);
|
||||
isprime[1] = false;
|
||||
vi divs(2e5 + 1);
|
||||
divs[1] = 1;
|
||||
|
||||
for (int i = 2; i <= (int)2e5; i++) {
|
||||
if (!isprime[i]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
divs[i] = i;
|
||||
|
||||
for (int j = i * 2; j <= (int)2e5; j += i) {
|
||||
isprime[j] = false;
|
||||
divs[j] = i;
|
||||
}
|
||||
}
|
||||
|
||||
int t;
|
||||
cin >> t;
|
||||
while (t--) {
|
||||
int n;
|
||||
cin >> n;
|
||||
|
||||
vi nums;
|
||||
ll primes = 0;
|
||||
ll ans = 0;
|
||||
vl count(n + 1);
|
||||
rep(i, n) {
|
||||
int num;
|
||||
cin >> num;
|
||||
if (isprime[num]) {
|
||||
ans += primes;
|
||||
primes++;
|
||||
ans -= count[num];
|
||||
count[num]++;
|
||||
continue;
|
||||
}
|
||||
|
||||
int a = divs[num];
|
||||
int b = num / a;
|
||||
|
||||
if (!isprime[b]) {
|
||||
continue;
|
||||
}
|
||||
|
||||
nums.push_back(num);
|
||||
}
|
||||
|
||||
for (auto i : nums) {
|
||||
int a = divs[i];
|
||||
int b = i / a;
|
||||
|
||||
count[i]++;
|
||||
ans += count[a] + count[b] + count[i];
|
||||
if (a == b) {
|
||||
ans -= count[a];
|
||||
}
|
||||
}
|
||||
|
||||
cout << ans << '\n';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user