func_code_string: #include <bits/stdc++.h>   using namespace std;   const int max_n = 5e5 + 10, max_f = 800;   struct Rad {     int l, r;     vector<pair<long long, int> > ar;     long long s;     Rad() {       l = r = -1;       s = 0;     }   };   int n, q;   long long num[max_n];   Rad sq[max_n];   bool compare(const pair<long long, int> &a, const int &b) {     return a.first < b;   }   bool compare2(const int &b, const pair<long long, int> &a) {     return b < a.first;   }   void input() {     scanf( %d%d , &n, &q);     for (int i = 0; i < n; i++) scanf( %d , &num[i]);     for (int i = 0; 1; i++) {       sq[i].l = i * max_f;       sq[i].r = min((i + 1) * max_f, n);       for (int j = sq[i].l; j < sq[i].r; j++)         sq[i].ar.push_back(make_pair(num[j], j));       sort(sq[i].ar.begin(), sq[i].ar.end());       if (sq[i].r == n) break;     }   }   void modify(int l, int r, int x) {     for (int i = 0; sq[i].l != -1; i++) {       if (l <= sq[i].l && sq[i].r <= r) sq[i].s += x;       if (sq[i].l < l && l < sq[i].r) {         for (int j = l; j < min(sq[i].r, r); j++) num[j] += x;         for (int j = sq[i].l; j < sq[i].r; j++)           sq[i].ar[j - sq[i].l] = make_pair(num[j], j);         sort(sq[i].ar.begin(), sq[i].ar.end());       } else if (sq[i].l < r && r < sq[i].r) {         for (int j = sq[i].l; j < r; j++) num[j] += x;         for (int j = sq[i].l; j < sq[i].r; j++)           sq[i].ar[j - sq[i].l] = make_pair(num[j], j);         sort(sq[i].ar.begin(), sq[i].ar.end());       }     }   }   void output() {     int type, l, r, x, y;     int first, last, tmp, tmp2;     for (int i = 0; i < q; i++) {       scanf( %d , &type);       if (type == 1) {         scanf( %d%d%d , &l, &r, &x);         modify(l - 1, r, x);       } else {         scanf( %d , &y);         first = -1;         for (int j = 0; sq[j].l != -1; j++) {           tmp = lower_bound(sq[j].ar.begin(), sq[j].ar.end(), y - sq[j].s,                             compare) -                 sq[j].ar.begin();           tmp2 = upper_bound(sq[j].ar.begin(), sq[j].ar.end(), y - sq[j].s,                              compare2) -                  sq[j].ar.begin() - 1;           if (first == -1 && tmp != (int)sq[j].ar.size() &&               sq[j].ar[tmp].first == y - sq[j].s)             first = sq[j].ar[tmp].second;           if (tmp2 != -1 && sq[j].ar[tmp2].first == y - sq[j].s)             last = sq[j].ar[tmp2].second;         }         if (first == -1)           printf( -1 n );         else           printf( %d n , last - first);       }     }   }   int main() {     input();     output();     return 0;   }   