Skip to content

Commit

Permalink
new: Codeforces Round 979 (Div. 2)
Browse files Browse the repository at this point in the history
  • Loading branch information
omar-besbes committed Oct 19, 2024
1 parent 982aa7b commit 36fe2cd
Show file tree
Hide file tree
Showing 4 changed files with 153 additions and 0 deletions.
27 changes: 27 additions & 0 deletions solutions/Codeforces/Codeforces Round 979 (Div. 2)/A.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#include <bits/stdc++.h>
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();
}
21 changes: 21 additions & 0 deletions solutions/Codeforces/Codeforces Round 979 (Div. 2)/B.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#include <bits/stdc++.h>
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();
}
23 changes: 23 additions & 0 deletions solutions/Codeforces/Codeforces Round 979 (Div. 2)/C.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <bits/stdc++.h>
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();
}
82 changes: 82 additions & 0 deletions solutions/Codeforces/Codeforces Round 979 (Div. 2)/D.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#include <bits/stdc++.h>
using namespace std;

vector<pair<int, int>> merge(vector<pair<int, int>> must) {
vector<pair<int, int>> 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<int> a(n);
for (auto &i : a) cin >> i;
string s;
cin >> s;

vector<pair<int, int>> 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<int> 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();
}

0 comments on commit 36fe2cd

Please sign in to comment.