记录11
作者:
Soel
,
2023-08-28 20:44:24
,
所有人可见
,
阅读 126
#ifdef LOCAL
#pragma GCC optimize ("Ofast")
#pragma GCC optimize ("unroll-loops")
#endif
using i64 = long long;
#ifdef ovec
std::ostream& operator<<(std::ostream& o, const std::vector<int>& a) {
for (auto& x : a) o << x+1 << ' ';
return o;
}
#endif
class Solution {
std::string to_string(std::vector<int>& a,std::string s) {
i64 cnt = 0;
std::string b; i64 d = ('z' - 'a' + 1) * 1e4;
int mod = ('z' - 'a' + 1);
for (int i = 0; i < s.size(); ++i) {
cnt += a[i];
cnt = (cnt + d) % mod;
b.push_back(cnt + 'a');
}
return b;
}
public:
std::string shiftingLetters(std::string s, std::vector<std::vector<int>>& shifts) {
std::vector<int> a(s.size() + 1);
a.front() = s.front()-'a';
for (int i = 1; i < s.size(); ++i) {
a[i] = s[i] - s[i - 1];
}
for (auto& x : shifts) {
int t1 = x[0], t2 = x[1], t3 = x[2];
if (t3 == 1) {
a[t1] += 1;
a[t2 + 1] -= 1;
}else {
a[t1] -= 1;
a[t2 + 1] += 1;
}
}
return to_string(a,s);
}
};