func_code_string: #include <bits/stdc++.h>   using namespace std;   const int N = 600010, inf = N;   int n, m;   int head[N], cnt = 1;   struct edge {     int to, next;   } e[N << 1];   void adde(int a, int b) {     e[++cnt].to = b;     e[cnt].next = head[a];     head[a] = cnt;   }   int nxt[N], st[N], vis[N], top, mn, mx, in[N];   void dfs(int k, int fa) {     vis[k] = 1;     st[++top] = k;     for (int i = head[k]; i; i = e[i].next) {       int v = e[i].to;       if (v == fa) continue;       if (!vis[v])         dfs(v, k);       else if (!in[v]) {         mx = 0;         mn = inf;         while (top) {           mx = max(st[top], mx);           mn = min(mn, st[top]);           in[st[top]] = 1;           top--;           if (st[top + 1] == v) break;         }         nxt[mn] = min(nxt[mn], mx);       }     }     if (!in[k]) top--;   }   long long sum[N];   int main() {     scanf( %d%d , &n, &m);     int u, v, q;     for (int i = 1; i <= m; i++) {       scanf( %d%d , &u, &v);       adde(u, v);       adde(v, u);     }     for (int i = 1; i <= n + 1; i++) nxt[i] = n + 1;     for (int i = 1; i <= n; i++)       if (!vis[i]) dfs(i, 0);     for (int i = n; i; i--) nxt[i] = min(nxt[i + 1], nxt[i]);     for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + nxt[i];     scanf( %d , &q);     int L, R;     while (q--) {       scanf( %d%d , &L, &R);       int l = L, r = R, res = L - 1;       while (l <= r) {         int mid = l + r >> 1;         if (nxt[mid] > R)           r = mid - 1;         else           l = mid + 1, res = mid;       }       printf( %lld n , 1ll * (R - res) * (R - res + 1) / 2 + sum[res] -                            sum[L - 1] - 1ll * (res + L) * (res - L + 1) / 2);     }     return 0;   }   