Add a bunch of other problems.
Some are not finished...
This commit is contained in:
103
Codeforces Round 1020 (Div. 3)/A. Dr. TC.cpp
Normal file
103
Codeforces Round 1020 (Div. 3)/A. Dr. TC.cpp
Normal file
@@ -0,0 +1,103 @@
|
||||
/* Problem URL: https://codeforces.com/contest/2106/problem/A */
|
||||
|
||||
#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 fds;
|
||||
string a;
|
||||
cin >> fds >> a;
|
||||
|
||||
int n = 0;
|
||||
|
||||
int count = 0;
|
||||
repv(i, a) {
|
||||
if (i == '1') {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
rep(i, a.size()) {
|
||||
if (a[i] == '1') {
|
||||
n += count - 1;
|
||||
} else {
|
||||
n += count + 1;
|
||||
}
|
||||
}
|
||||
|
||||
cout << n << '\n';
|
||||
}
|
||||
}
|
||||
92
Codeforces Round 1020 (Div. 3)/B. St. Chroma.cpp
Normal file
92
Codeforces Round 1020 (Div. 3)/B. St. Chroma.cpp
Normal file
@@ -0,0 +1,92 @@
|
||||
/* Problem URL: https://codeforces.com/contest/2106/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--) {
|
||||
int n, x;
|
||||
cin >> n >> x;
|
||||
|
||||
for (int i = 0; i < x; i++) {
|
||||
cout << i << ' ';
|
||||
}
|
||||
|
||||
for (int i = n - 1; i >= x; i--) {
|
||||
cout << i << ' ';
|
||||
}
|
||||
cout << '\n';
|
||||
}
|
||||
}
|
||||
134
Codeforces Round 1020 (Div. 3)/C. Cherry Bomb.cpp
Normal file
134
Codeforces Round 1020 (Div. 3)/C. Cherry Bomb.cpp
Normal file
@@ -0,0 +1,134 @@
|
||||
/* Problem URL: https://codeforces.com/contest/2106/problem/C */
|
||||
|
||||
#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--) {
|
||||
ll n, k;
|
||||
cin >> n >> k;
|
||||
|
||||
vl a(n);
|
||||
cin >> a;
|
||||
vl b(n);
|
||||
cin >> b;
|
||||
|
||||
ll tmp = -1;
|
||||
bool pos = true;
|
||||
rep(i, n) {
|
||||
if (b[i] != -1) {
|
||||
if (tmp != -1 && a[i] + b[i] != tmp) {
|
||||
pos = false;
|
||||
break;
|
||||
}
|
||||
tmp = a[i] + b[i];
|
||||
continue;
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < n && tmp != -1 && pos; i++) {
|
||||
if (a[i] > tmp) {
|
||||
pos = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!pos) {
|
||||
cout << "0\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
if (tmp != -1) {
|
||||
repv(i, a) {
|
||||
if (tmp - i > k) {
|
||||
pos = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
cout << (pos ? "1\n" : "0\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
ll minimal = INT32_MAX;
|
||||
ll maximal = 0;
|
||||
|
||||
repv(i, a) {
|
||||
rmin(minimal, i);
|
||||
rmax(maximal, i);
|
||||
}
|
||||
|
||||
cout << k - (maximal - minimal) + 1 << '\n';
|
||||
}
|
||||
}
|
||||
136
Codeforces Round 1020 (Div. 3)/D. Flower Boy.cpp
Normal file
136
Codeforces Round 1020 (Div. 3)/D. Flower Boy.cpp
Normal file
@@ -0,0 +1,136 @@
|
||||
/* Problem URL: https://codeforces.com/contest/2106/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;
|
||||
|
||||
vl a(n);
|
||||
cin >> a;
|
||||
vl b(m);
|
||||
cin >> b;
|
||||
b.push_back(0);
|
||||
|
||||
vi pref(m, -1);
|
||||
vi suf(m, -1);
|
||||
|
||||
int now = 0;
|
||||
for (int i = 0; i < n && now < m; i++) {
|
||||
if (a[i] >= b[now]) {
|
||||
pref[now] = i;
|
||||
now++;
|
||||
}
|
||||
}
|
||||
|
||||
now = m - 1;
|
||||
for (int i = n - 1; i >= 0 && now >= 0; i--) {
|
||||
if (a[i] >= b[now]) {
|
||||
suf[now] = i;
|
||||
now--;
|
||||
}
|
||||
}
|
||||
|
||||
ll ans = INT64_MAX >> 1;
|
||||
|
||||
if (pref.back() != -1) {
|
||||
cout << "0\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
if (m == 1) {
|
||||
cout << b[0] << '\n';
|
||||
continue;
|
||||
}
|
||||
|
||||
if (pref[m - 1] == -1 && pref[m - 2] != -1) {
|
||||
rmin(ans, b[m - 1]);
|
||||
}
|
||||
|
||||
if (suf[1] != -1 && suf[0] == -1) {
|
||||
rmin(ans, b[0]);
|
||||
}
|
||||
|
||||
for (int i = 1; i < m - 1; i++) {
|
||||
if (pref[i - 1] != -1 && suf[i + 1] != -1 && pref[i - 1] < suf[i + 1]) {
|
||||
rmin(ans, b[i]);
|
||||
}
|
||||
}
|
||||
|
||||
cout << (ans == INT64_MAX >> 1 ? -1 : ans) << '\n';
|
||||
}
|
||||
}
|
||||
181
Codeforces Round 1020 (Div. 3)/E. Wolf.cpp
Normal file
181
Codeforces Round 1020 (Div. 3)/E. Wolf.cpp
Normal file
@@ -0,0 +1,181 @@
|
||||
/* Problem URL: https://codeforces.com/contest/2106/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 n, q;
|
||||
cin >> n >> q;
|
||||
|
||||
vi elem(n);
|
||||
cin >> elem;
|
||||
|
||||
vi pos(n + 1);
|
||||
rep(i, n) {
|
||||
pos[elem[i]] = i;
|
||||
}
|
||||
|
||||
while (q--) {
|
||||
int l, r, x;
|
||||
cin >> l >> r >> x;
|
||||
l--, r--;
|
||||
|
||||
if (pos[x] > r || pos[x] < l) {
|
||||
cout << "-1 ";
|
||||
continue;
|
||||
}
|
||||
|
||||
int greater = n - x;
|
||||
int lesser = x - 1;
|
||||
int cgreater = 0;
|
||||
int clesser = 0;
|
||||
int ans = 0;
|
||||
|
||||
int low = l;
|
||||
int high = r;
|
||||
|
||||
bool valid = true;
|
||||
|
||||
while (elem[(low + high) / 2] != x) {
|
||||
int mid = (low + high) / 2;
|
||||
|
||||
if (elem[mid] > x) {
|
||||
if (pos[x] > mid) {
|
||||
if (clesser) {
|
||||
clesser--;
|
||||
low = mid + 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (greater == 0 || lesser == 0) {
|
||||
valid = false;
|
||||
break;
|
||||
}
|
||||
|
||||
lesser--;
|
||||
greater--;
|
||||
cgreater++;
|
||||
ans += 2;
|
||||
|
||||
low = mid + 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (greater == 0) {
|
||||
valid = false;
|
||||
break;
|
||||
}
|
||||
|
||||
greater--;
|
||||
high = mid - 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (pos[x] < mid) {
|
||||
if (cgreater) {
|
||||
cgreater--;
|
||||
high = mid - 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (greater == 0 || lesser == 0) {
|
||||
valid = false;
|
||||
break;
|
||||
}
|
||||
|
||||
greater--;
|
||||
lesser--;
|
||||
clesser++;
|
||||
ans += 2;
|
||||
|
||||
high = mid - 1;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (lesser == 0) {
|
||||
valid = false;
|
||||
break;
|
||||
}
|
||||
|
||||
lesser--;
|
||||
low = mid + 1;
|
||||
}
|
||||
|
||||
cout << (valid ? ans : -1) << ' ';
|
||||
}
|
||||
cout << '\n';
|
||||
}
|
||||
}
|
||||
104
Codeforces Round 1020 (Div. 3)/F. Goblin.cpp
Normal file
104
Codeforces Round 1020 (Div. 3)/F. Goblin.cpp
Normal file
@@ -0,0 +1,104 @@
|
||||
/* Problem URL: https://codeforces.com/contest/2106/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;
|
||||
string a;
|
||||
cin >> n >> a;
|
||||
|
||||
ll part1 = 0;
|
||||
ll part2 = 0;
|
||||
ll ans = 0;
|
||||
|
||||
rep(i, a.size()) {
|
||||
if (a[i] == '0') {
|
||||
part1 += i;
|
||||
part2 += n - i - 1;
|
||||
} else {
|
||||
swap(part1, part2);
|
||||
part2 = 0;
|
||||
part1++;
|
||||
}
|
||||
|
||||
rmax(ans, part1);
|
||||
rmax(ans, part2);
|
||||
}
|
||||
|
||||
cout << ans << '\n';
|
||||
}
|
||||
}
|
||||
135
Codeforces Round 1020 (Div. 3)/G1. Baudelaire (easy version).cpp
Normal file
135
Codeforces Round 1020 (Div. 3)/G1. Baudelaire (easy version).cpp
Normal file
@@ -0,0 +1,135 @@
|
||||
/* Problem URL: https://codeforces.com/contest/2106/problem/G1 */
|
||||
|
||||
#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 (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;
|
||||
|
||||
vvi graph(n);
|
||||
rep(i, n - 1) {
|
||||
int a, b;
|
||||
cin >> a >> b;
|
||||
a--, b--;
|
||||
|
||||
graph[a].push_back(b);
|
||||
graph[b].push_back(a);
|
||||
}
|
||||
|
||||
cout << "? 1 1 1" << endl;
|
||||
int ans;
|
||||
cin >> ans;
|
||||
|
||||
if (ans > 1 || ans < -1) {
|
||||
cout << "? 2 1" << endl;
|
||||
ans = 0;
|
||||
}
|
||||
|
||||
vi tmp(n);
|
||||
nrep(i, 1, n) {
|
||||
cout << "? 1 1 " << i + 1 << endl;
|
||||
int now;
|
||||
cin >> now;
|
||||
|
||||
tmp[i] = now - ans;
|
||||
}
|
||||
|
||||
int one = 0;
|
||||
if (ans == 0) {
|
||||
cout << "? 2 1" << endl;
|
||||
int fds;
|
||||
cout << "? 1 1 1" << endl;
|
||||
cin >> fds;
|
||||
|
||||
if (fds == -2) {
|
||||
one = -1;
|
||||
} else {
|
||||
one = 1;
|
||||
}
|
||||
} else {
|
||||
one = ans;
|
||||
}
|
||||
|
||||
tmp[0] = one;
|
||||
|
||||
cout << "! ";
|
||||
repv(i, tmp) {
|
||||
cout << ' ' << i;
|
||||
}
|
||||
cout << endl;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user