func_code_string: #include <bits/stdc++.h>   using namespace std;   int n, m;   int c[1010100], cc[1010100];   int lowbit(int x) { return x & (-x); }   void upd(int v, int idx, int a[]) {     while (idx <= n) {       a[idx] += v;       idx += lowbit(idx);     }   }   int qu(int idx, int a[]) {     int sum = 0;     if (idx == 0) return 0;     while (idx > 0) {       sum += a[idx];       idx -= lowbit(idx);     }     return sum;   }   struct Node {     int v, id;   } arr[1010100];   int cmp(Node a, Node b) { return a.v < b.v; }   int find() {     int ll = 1, rr = n + 1, mid, ans = n;     while (ll < rr) {       mid = (ll + rr) / 2;       if (qu(mid, cc) < mid)         ans = rr = mid;       else         ll = mid + 1;     }     return ans;   }   int vis[1010100];   int main() {     int i, j;     while (scanf( %d %d , &n, &m) != EOF) {       memset(vis, 0, sizeof(vis));       for (i = 1; i <= n; i++) scanf( %d , &arr[i].v), arr[i].id = i;       for (i = 1; i <= m; i++) scanf( %d , &j), vis[j] = 1;       sort(arr + 1, arr + 1 + n, cmp);       memset(c, 0, sizeof(c));       memset(cc, 0, sizeof(cc));       long long sum = 0;       for (i = 1; i <= n; i++) {         if (vis[arr[i].v]) {           upd(1, arr[i].id, c);         } else {           int ll = 0, rr = arr[i].id, mid;           int v = qu(rr, c), x = rr;           while (ll < rr) {             mid = (ll + rr) / 2;             if (qu(mid, c) == v)               x = rr = mid;             else               ll = mid + 1;           }           if (qu(n, c) == 0) x = 0;           ll = arr[i].id, rr = n + 1;           v = qu(ll, c);           int y = ll;           while (ll < rr) {             mid = (ll + rr) / 2;             if (qu(mid, c) == v)               y = mid, ll = mid + 1;             else               rr = mid;           }           y = y - qu(y, cc);           x = max(find() - 1, x);           x = x - qu(x, cc);           sum = sum + (y - x);           upd(1, arr[i].id, cc);         }       }       printf( %I64d n , sum);     }     return 0;   }   