From 36fe2cdda2c864cf21b90e72a4aa1d7f074912d1 Mon Sep 17 00:00:00 2001 From: Omar Besbes <86571415+omar-besbes@users.noreply.github.com> Date: Sat, 19 Oct 2024 17:28:27 +0100 Subject: [PATCH] new: Codeforces Round 979 (Div. 2) --- .../Codeforces Round 979 (Div. 2)/A.cpp | 27 ++++++ .../Codeforces Round 979 (Div. 2)/B.cpp | 21 +++++ .../Codeforces Round 979 (Div. 2)/C.cpp | 23 ++++++ .../Codeforces Round 979 (Div. 2)/D.cpp | 82 +++++++++++++++++++ 4 files changed, 153 insertions(+) create mode 100644 solutions/Codeforces/Codeforces Round 979 (Div. 2)/A.cpp create mode 100644 solutions/Codeforces/Codeforces Round 979 (Div. 2)/B.cpp create mode 100644 solutions/Codeforces/Codeforces Round 979 (Div. 2)/C.cpp create mode 100644 solutions/Codeforces/Codeforces Round 979 (Div. 2)/D.cpp diff --git a/solutions/Codeforces/Codeforces Round 979 (Div. 2)/A.cpp b/solutions/Codeforces/Codeforces Round 979 (Div. 2)/A.cpp new file mode 100644 index 0000000..61553ed --- /dev/null +++ b/solutions/Codeforces/Codeforces Round 979 (Div. 2)/A.cpp @@ -0,0 +1,27 @@ +#include +using namespace std; + +void solve() { + int n; + cin >> n; + long long maxi = 0, mini = INT_MAX; + for (int i = 0; i < n; i++) { + long long x; + cin >> x; + maxi = max(maxi, x); + mini = min(mini, x); + } + + auto score = (n - 1) * (maxi - mini); + cout << score << "\n"; +} + +int main() { + ios::sync_with_stdio(false); + cin.tie(0); + cout.tie(0); + + int t = 1; + cin >> t; + while (t--) solve(); +} \ No newline at end of file diff --git a/solutions/Codeforces/Codeforces Round 979 (Div. 2)/B.cpp b/solutions/Codeforces/Codeforces Round 979 (Div. 2)/B.cpp new file mode 100644 index 0000000..1fddd8f --- /dev/null +++ b/solutions/Codeforces/Codeforces Round 979 (Div. 2)/B.cpp @@ -0,0 +1,21 @@ +#include +using namespace std; + +void solve() { + int n; + cin >> n; + string s; + for (int i = 0; i < n - 1; i++) s += '0'; + s += '1'; + cout << s << "\n"; +} + +int main() { + ios::sync_with_stdio(false); + cin.tie(0); + cout.tie(0); + + int t = 1; + cin >> t; + while (t--) solve(); +} \ No newline at end of file diff --git a/solutions/Codeforces/Codeforces Round 979 (Div. 2)/C.cpp b/solutions/Codeforces/Codeforces Round 979 (Div. 2)/C.cpp new file mode 100644 index 0000000..edb0b3d --- /dev/null +++ b/solutions/Codeforces/Codeforces Round 979 (Div. 2)/C.cpp @@ -0,0 +1,23 @@ +#include +using namespace std; + +void solve() { + int n; + cin >> n; + string s; + cin >> s; + bool yes = s[0] == '1' || s[n - 1] == '1'; + for (int i = 1; !yes && i < n; i++) + if (s[i] == s[i - 1] && s[i] == '1') yes = true; + cout << (yes ? "YES" : "NO") << "\n"; +} + +int main() { + ios::sync_with_stdio(false); + cin.tie(0); + cout.tie(0); + + int t = 1; + cin >> t; + while (t--) solve(); +} \ No newline at end of file diff --git a/solutions/Codeforces/Codeforces Round 979 (Div. 2)/D.cpp b/solutions/Codeforces/Codeforces Round 979 (Div. 2)/D.cpp new file mode 100644 index 0000000..bdd2166 --- /dev/null +++ b/solutions/Codeforces/Codeforces Round 979 (Div. 2)/D.cpp @@ -0,0 +1,82 @@ +#include +using namespace std; + +vector> merge(vector> must) { + vector> ans; + sort(must.begin(), must.end()); + if (must.empty()) return ans; + int curl = must[0].first, curr = must[1].second; + for (auto [l, r] : must) { + if (l > curr + 1) + ans.push_back({curl, curr}), curl = l, curr = r; + else + curr = max(curr, r); + } + ans.push_back({curl, curr}); + return ans; +} + +void solve() { + int n, q; + cin >> n >> q; + vector a(n); + for (auto &i : a) cin >> i; + string s; + cin >> s; + + vector> must; + for (int i = 0; i < n; i++) + if (a[i] != i + 1) + must.push_back({min(a[i] - 1, i), max(a[i] - 1, i) - 1}); + must = merge(must); + + auto needindex = [&](int idx) { + auto it = lower_bound(must.begin(), must.end(), make_pair(idx, idx)); + if (it == must.end() || it->first > idx) { + if (it == must.begin()) return false; + it--; + if (it->second < idx) + return false; + else + return true; + } else { + return true; + } + }; + + set toremove; + for (int i = 0; i < n - 1; i++) { + if (s[i] == 'L' && s[i + 1] == 'R' && needindex(i)) toremove.insert(i); + } + + for (int i = 0; i < q; i++) { + int idx; + cin >> idx; + idx--; + s[idx] = s[idx] == 'L' ? 'R' : 'L'; + + if (idx + 1 < n) + if (s[idx] == 'L' && s[idx + 1] == 'R' && needindex(idx)) + toremove.insert(idx); + else + toremove.erase(idx); + + if (idx - 1 >= 0) + if (s[idx - 1] == 'L' && s[idx] == 'R' && needindex(idx - 1)) + toremove.insert(idx - 1); + else + toremove.erase(idx - 1); + + cout << (toremove.empty() ? "YES" : "NO") << "\n"; + } +} + +int main() { + ios::sync_with_stdio(false); + cin.tie(0); + cout.tie(0); + + int t = 1; + cin >> t; + while (t--) solve(); +} \ No newline at end of file