Skip to content

Commit 36fe2cd

Browse files
committed
new: Codeforces Round 979 (Div. 2)
1 parent 982aa7b commit 36fe2cd

File tree

4 files changed

+153
-0
lines changed

4 files changed

+153
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
void solve() {
5+
int n;
6+
cin >> n;
7+
long long maxi = 0, mini = INT_MAX;
8+
for (int i = 0; i < n; i++) {
9+
long long x;
10+
cin >> x;
11+
maxi = max(maxi, x);
12+
mini = min(mini, x);
13+
}
14+
15+
auto score = (n - 1) * (maxi - mini);
16+
cout << score << "\n";
17+
}
18+
19+
int main() {
20+
ios::sync_with_stdio(false);
21+
cin.tie(0);
22+
cout.tie(0);
23+
24+
int t = 1;
25+
cin >> t;
26+
while (t--) solve();
27+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
void solve() {
5+
int n;
6+
cin >> n;
7+
string s;
8+
for (int i = 0; i < n - 1; i++) s += '0';
9+
s += '1';
10+
cout << s << "\n";
11+
}
12+
13+
int main() {
14+
ios::sync_with_stdio(false);
15+
cin.tie(0);
16+
cout.tie(0);
17+
18+
int t = 1;
19+
cin >> t;
20+
while (t--) solve();
21+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
void solve() {
5+
int n;
6+
cin >> n;
7+
string s;
8+
cin >> s;
9+
bool yes = s[0] == '1' || s[n - 1] == '1';
10+
for (int i = 1; !yes && i < n; i++)
11+
if (s[i] == s[i - 1] && s[i] == '1') yes = true;
12+
cout << (yes ? "YES" : "NO") << "\n";
13+
}
14+
15+
int main() {
16+
ios::sync_with_stdio(false);
17+
cin.tie(0);
18+
cout.tie(0);
19+
20+
int t = 1;
21+
cin >> t;
22+
while (t--) solve();
23+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#include <bits/stdc++.h>
2+
using namespace std;
3+
4+
vector<pair<int, int>> merge(vector<pair<int, int>> must) {
5+
vector<pair<int, int>> ans;
6+
sort(must.begin(), must.end());
7+
if (must.empty()) return ans;
8+
int curl = must[0].first, curr = must[1].second;
9+
for (auto [l, r] : must) {
10+
if (l > curr + 1)
11+
ans.push_back({curl, curr}), curl = l, curr = r;
12+
else
13+
curr = max(curr, r);
14+
}
15+
ans.push_back({curl, curr});
16+
return ans;
17+
}
18+
19+
void solve() {
20+
int n, q;
21+
cin >> n >> q;
22+
vector<int> a(n);
23+
for (auto &i : a) cin >> i;
24+
string s;
25+
cin >> s;
26+
27+
vector<pair<int, int>> must;
28+
for (int i = 0; i < n; i++)
29+
if (a[i] != i + 1)
30+
must.push_back({min(a[i] - 1, i), max(a[i] - 1, i) - 1});
31+
must = merge(must);
32+
33+
auto needindex = [&](int idx) {
34+
auto it = lower_bound(must.begin(), must.end(), make_pair(idx, idx));
35+
if (it == must.end() || it->first > idx) {
36+
if (it == must.begin()) return false;
37+
it--;
38+
if (it->second < idx)
39+
return false;
40+
else
41+
return true;
42+
} else {
43+
return true;
44+
}
45+
};
46+
47+
set<int> toremove;
48+
for (int i = 0; i < n - 1; i++) {
49+
if (s[i] == 'L' && s[i + 1] == 'R' && needindex(i)) toremove.insert(i);
50+
}
51+
52+
for (int i = 0; i < q; i++) {
53+
int idx;
54+
cin >> idx;
55+
idx--;
56+
s[idx] = s[idx] == 'L' ? 'R' : 'L';
57+
58+
if (idx + 1 < n)
59+
if (s[idx] == 'L' && s[idx + 1] == 'R' && needindex(idx))
60+
toremove.insert(idx);
61+
else
62+
toremove.erase(idx);
63+
64+
if (idx - 1 >= 0)
65+
if (s[idx - 1] == 'L' && s[idx] == 'R' && needindex(idx - 1))
66+
toremove.insert(idx - 1);
67+
else
68+
toremove.erase(idx - 1);
69+
70+
cout << (toremove.empty() ? "YES" : "NO") << "\n";
71+
}
72+
}
73+
74+
int main() {
75+
ios::sync_with_stdio(false);
76+
cin.tie(0);
77+
cout.tie(0);
78+
79+
int t = 1;
80+
cin >> t;
81+
while (t--) solve();
82+
}

0 commit comments

Comments
 (0)