题目:
3.字符迁移【算法赛】 - 蓝桥云课 (lanqiao.cn)
思路:
此题通过把小写字母映射成数字,进行差分即可。
AC代码:
#include<iostream>
#include<cstring>
#include<algorithm>using namespace std;typedef long long LL;
const int N = 2e5 + 10;
LL c[N],b[N];
// 差分
void insert(LL l,LL r,LL k) {b[l] += k;b[r+1] -= k;return;
}int main() {cin.tie(0)->ios::sync_with_stdio(false);LL n,q;cin >> n >> q;string str;cin >> str;for(int i=0; i<str.size(); i++){c[i+1]=str[i]-'a';insert(i+1,i+1,c[i+1]);}while(q--) {int l,r,k;cin >> l >> r >> k;//k%=26; 可写可不写insert(l,r,k);}for(int i=1; i<=n; i++) {b[i] += b[i-1]; //前缀和cout << (char)('a'+b[i]%26);}return 0;
}