#include using namespace std; #define MAX (int)1e6+2 struct Node{ int op; int open; int close; }; Node st[MAX*4]; string s; Node operator + (Node l, Node r){ Node res; int tmp = min(l.open,r.close); res.op = l.op + r.op + tmp; res.open = l.open + r.open - tmp; res.close = l.close + r.close - tmp; return res; } void build(int id, int l,int r){ if(l==r){ if(s[l]=='(') st[id]={0,1,0}; else st[id]={0,0,1}; return; } int m=(l+r)/2; build(id*2,l,m); build(id*2+1,m+1,r); st[id]=st[id*2]+st[id*2+1] ; } Node query(int id,int l,int r,int u,int v){ if(vu){ Node x={0,0,0}; return x; } if(u<=l && r<=v) return st[id]; int mid = (l+r)/2; Node x = query(id*2,l,mid,u,v)+query(id*2+1,mid+1,r,u,v); return x; } int main(){ ios::sync_with_stdio(0); cin.tie(0); string s1; cin>>s1; s="0"+s1; int t; cin>>t; int n = s1.size(); build(1,1,n); for(int i=1;i<=29;i++){ cout<>l>>r; Node x = query(1,1,n,l,r); cout<