func_code_string: #include <bits/stdc++.h>   using namespace ::std;   const long long maxn = 1e5 + 500;   const long long mod = 1e9 + 7;   const long long inf = 1e9 + 500;   const long long rad = 330;   long long a[maxn];   long long t[maxn];   bool cmp(pair<long long, long long> a, pair<long long, long long> b) {     if (a.first / rad == b.first / rad) {       return (a.second < b.second);     }     return (a.first < b.first);   }   long long ml[maxn];   pair<long long, long long> sque[maxn];   map<pair<long long, long long>, long long> anss;   long long lastid[maxn];   long long nextid[maxn];   long long id[maxn];   int main() {     ios_base::sync_with_stdio(0);     cin.tie(0);     cout.tie(0);     long long n, k;     cin >> n >> k;     for (long long i = 1; i <= n; i++) {       cin >> t[i];     }     for (long long i = 1; i <= n; i++) {       cin >> a[i];       if (t[i] == 2) {         a[i] *= -1;       }     }     for (long long i = 1; i <= n; i++) {       a[i] += a[i - 1];     }     vector<long long> vec;     for (long long i = 0; i <= n; i++) {       vec.push_back(a[i]);     }     {       sort(vec.begin(), vec.end());       auto it = unique(vec.begin(), vec.end());       vec.resize(distance(vec.begin(), it));     }     vector<long long>::iterator it;     for (long long i = 0; i <= n; i++) {       id[i] = lower_bound(vec.begin(), vec.end(), a[i]) - vec.begin();       it = lower_bound(vec.begin(), vec.end(), a[i] + k);       if (it != vec.end() && (*it) == a[i] + k) {         nextid[i] = it - vec.begin();       } else {         nextid[i] = maxn - 1;       }       it = lower_bound(vec.begin(), vec.end(), a[i] - k);       if (it != vec.end() && (*it) == a[i] - k) {         lastid[i] = it - vec.begin();       } else {         lastid[i] = maxn - 1;       }     }     long long q;     cin >> q;     vector<pair<long long, long long> > que;     for (long long i = 0; i < q; i++) {       long long l, r;       cin >> l >> r;       l--;       sque[i] = make_pair(l, r);       que.push_back(make_pair(l, r));     }     sort(que.begin(), que.end(), cmp);     long long res = 0;     long long l = 0;     long long r = 0;     for (auto b : que) {       long long L = b.first;       long long R = b.second;       while (r <= R) {         res += ml[lastid[r]];         ml[id[r]]++;         r++;       }       while (L < l) {         l--;         res += ml[nextid[l]];         ml[id[l]]++;       }       while (R + 1 < r) {         r--;         ml[id[r]]--;         res -= ml[lastid[r]];       }       while (l < L) {         ml[id[l]]--;         res -= ml[nextid[l]];         l++;       }       anss[make_pair(L, R)] = res;     }     for (long long i = 0; i < q; i++) {       cout << anss[sque[i]] << endl;     }   }   