Skip to content

Commit 5b5ffc1

Browse files
committed
update Hello2023.md
1 parent d06adfe commit 5b5ffc1

File tree

1 file changed

+102
-0
lines changed

1 file changed

+102
-0
lines changed

codeforces/contest/Hello2023.md

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
## A
2+
3+
容易发现只要存在`RL`字符串即可满足要求,于是只需要判断是否存在,如果不存在的话将`LR`进行反转
4+
5+
```cpp
6+
void solve() {
7+
int n;
8+
string s;
9+
cin >> n >> s;
10+
// 每盏灯左边或者右边有灯
11+
//LLLRLRR
12+
if (n == 1 || count(all(s), 'L') == 0 || count(all(s), 'R') == 0) {
13+
cout << -1 << "\n";
14+
return;
15+
}
16+
int idx = 0;
17+
for (int i = 0; i < n-1; i++) {
18+
if (s[i] == 'L' && s[i+1] == 'R') {
19+
idx = i+1;
20+
break;
21+
}
22+
}
23+
cout << idx << "\n";
24+
}
25+
26+
```
27+
28+
## B
29+
30+
{**a1,a2**,a3...ak}这样的一个序列,容易发现必须满足减去a[i] + a[i+1]之后的和为0,当n=3的时候显然不满足;
31+
32+
当n>3的时候,通过消元发现,a[i] = a[i+2*k],进而,对剩余的元素,进行正负的划分即可,然后可以给他们安一个值,`lcm(a,b)/a``lcm(a,b)/b`.
33+
34+
```cpp
35+
void solve() {
36+
int n;
37+
cin >> n;
38+
if (n == 3) {
39+
cout << "NO\n";
40+
}
41+
else if (~n&1){
42+
cout << "YES\n";
43+
for (int i = 1; i <= n; i+=2) {
44+
cout << 1 << " " << -1 << " ";
45+
}
46+
cout << "\n";
47+
}
48+
else {
49+
cout << "YES\n";
50+
ll a = (n-1)/2, b = (n-2)/2;
51+
cout << lcm(a,b)/a << " ";
52+
for (int i = 1; i <= n-1; i+=2) {
53+
cout << -lcm(a,b)/b << " " << lcm(a,b)/a << " ";
54+
}
55+
cout << "\n";
56+
}
57+
}
58+
```
59+
60+
## C
61+
62+
对于m之前的所有前缀应该满足>=0,对于m之后的所有前缀也是如此。
63+
64+
于是可以采取从m位置向前保证前缀和< 0的操作,如果不满足的话将原先存在的堆里头最大值变成负数;
65+
66+
往后的操作同理。 实际上就是**反悔堆**的操作
67+
68+
```cpp
69+
void solve() {
70+
int n, m;
71+
cin >> n >> m;
72+
vector <ll> a(n+1);
73+
for (int i = 0; i < n; i++) {
74+
cin >> a[i+1];
75+
}
76+
ll cur = 0;
77+
int ans = 0;
78+
priority_queue<int> q;
79+
for (int i = m; i >= 2; i--) {
80+
cur += a[i];
81+
q.push(a[i]);
82+
if (cur > 0) {
83+
auto u = q.top(); q.pop();
84+
cur -= 2 * u;
85+
ans++;
86+
}
87+
}
88+
priority_queue <int,vector<int>,greater<>> q1;
89+
cur = 0;
90+
for (int i = m+1; i <= n; i++) {
91+
cur += a[i];
92+
q1.push(a[i]);
93+
if (cur < 0) {
94+
auto u = q1.top(); q1.pop();
95+
cur -= 2 * u;
96+
ans++;
97+
}
98+
}
99+
cout << ans << "\n";
100+
}
101+
```
102+

0 commit comments

Comments
 (0)