全站最先发讨论
2025-07-14 21:32:08
发布于:四川
19阅读
0回复
0点赞
#include <iostream>
#include <string>
#include <vector>
using namespace std;
struct Op {
int l, r, x;
int timestamp;
};
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int n;
cin >> n;
string s;
cin >> s;
int q;
cin >> q;
vector<Op> type1_ops;
int total_shift = 0;
for (int i = 0; i < q; ++i) {
int op;
cin >> op;
if (op == 1) {
int l, r, x;
cin >> l >> r >> x;
x %= 26;
type1_ops.push_back({l, r, x, total_shift});
} else {
int x;
cin >> x;
total_shift = (total_shift + x) % n;
}
}
vector<int> add(n, 0);
for (const auto& op : type1_ops) {
int current_l = (op.l - 1 - op.timestamp + n) % n;
int current_r = (op.r - 1 - op.timestamp + n) % n;
if (current_l <= current_r) {
add[current_l] = (add[current_l] + op.x) % 26;
if (current_r + 1 < n) {
add[current_r + 1] = (add[current_r + 1] - op.x + 26) % 26;
}
} else {
add[current_l] = (add[current_l] + op.x) % 26;
add[0] = (add[0] + op.x) % 26;
if (current_r + 1 < n) {
add[current_r + 1] = (add[current_r + 1] - op.x + 26) % 26;
}
}
}
for (int i = 1; i < n; ++i) {
add[i] = (add[i] + add[i - 1]) % 26;
}
string result(n, ' ');
for (int i = 0; i < n; ++i) {
int original_pos = (i - total_shift + n) % n;
char c = s[original_pos];
c = 'a' + (c - 'a' + add[original_pos]) % 26;
result[i] = c;
}
cout << result << endl;
return 0;
}
全部评论 2
shabi
2025-07-14 来自 湖南
0不错吧???
2025-07-14 来自 四川
0
有帮助,赞一个