func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 1e5 + 5, mod = 1000000007, INF = 1e9 + 7;   const int block = 316;   int n, k, type[N], a[N], m, cnt[N * 3], l[N][5];   long long ans, res[N], p[N][5];   set<long long> s;   map<long long, int> conv;   struct query {     int l, r, id, num;     query(){};     query(int a, int b, int c) : l(a), r(b), id(a / block), num(c){};   } q[N];   bool cmp(query q1, query q2) {     if (q1.id != q2.id) return q1.id < q2.id;     return q1.r < q2.r;   }   void add(int v, int cond) {     ans += cnt[l[v][cond]];     cnt[l[v][1]]++;   }   void remove(int v, int cond) {     cnt[l[v][1]]--;     ans -= cnt[l[v][cond]];   }   int main() {     cin >> n >> k;     for (int i = 1; i <= n; i++) {       cin >> type[i];     }     for (int i = 1; i <= n; i++) {       cin >> a[i];     }     for (int i = 0; i <= n; i++) {       if (type[i] == 2) a[i] *= -1;       p[i][1] = p[i - 1][1] + a[i];       p[i][2] = p[i][1] - k;       p[i][3] = p[i][1] + k;       s.insert(p[i][1]);       s.insert(p[i][2]);       s.insert(p[i][3]);     }     int cnt = 0;     for (long long e : s) {       conv[e] = ++cnt;     }     for (int i = 0; i <= n; i++) {       l[i][1] = conv[p[i][1]];       l[i][2] = conv[p[i][2]];       l[i][3] = conv[p[i][3]];     }     cin >> m;     for (int i = 1; i <= m; i++) {       int l, r;       cin >> l >> r;       l--;       q[i] = query(l, r, i);     }     sort(q + 1, q + m + 1, &cmp);     int l = 0, r = -1;     for (int i = 1; i <= m; i++) {       int L = q[i].l, R = q[i].r;       while (r < R) add(++r, 2);       while (l < L) remove(l++, 3);       while (R < r) remove(r--, 2);       while (L < l) add(--l, 3);       res[q[i].num] = ans;     }     for (int i = 1; i <= m; i++) {       cout << res[i] << endl;     }     cout << endl;   }   