Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define int long long int
- signed main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- int t;
- cin >> t;
- while (t--) {
- int n, q;
- cin >> n >> q;
- string a, b;
- cin >> a >> b;
- vector<vector<int>> freqa(n, vector<int>(26, 0)), freqb(n, vector<int>(26, 0));
- freqa[0][a[0] - 'a'] = 1;
- freqb[0][b[0] - 'a'] = 1;
- for (int i = 1; i < n; i++) {
- freqa[i] = freqa[i - 1];
- freqa[i][a[i] - 'a']++;
- }
- for (int i = 1; i < n; i++) {
- freqb[i] = freqb[i - 1];
- freqb[i][b[i] - 'a']++;
- }
- while (q--) {
- int l, r;
- cin >> l >> r;
- l--;
- r--;
- int sum = 0;
- for (int i = 0; i < 26; i++) {
- int v1 = (l == 0) ? freqa[r][i] : freqa[r][i] - freqa[l - 1][i];
- int v2 = (l == 0) ? freqb[r][i] : freqb[r][i] - freqb[l - 1][i];
- sum += abs(v1 - v2);
- }
- cout << sum / 2 << endl;
- }
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement