UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#215014#2037. aCharloCompile Error//C++1.2kb2024-11-25 19:56:452024-11-25 23:06:38

answer

#include<bits/stdc++.h>

const int N=1e6+5;
int n,q;
std::string s;
struct node{
	int ans,lr,rl;
};
node merge(node a,node b){
    node c;
	int res=std::min(a.rl,b.lr);
	c.ans=a.ans+b.ans+res;
	c.lr=a.lr+b.lr-res;
	c.rl=b.rl+a.rl-res;
	return c;
}
struct segtree{
	int l,r;
	node ans1,ans2;
}tree[N<<2];
void pushup(int u){
	tree[u].ans1=merge(tree[u<<1].ans1,tree[u<<1|1].ans1);
	tree[u].ans2=merge(tree[u<<1].ans2,tree[u<<1|1].ans2);
}
void build(int u,int l,int r){
	tree[u].l=l,tree[u].r=r;
	if(l==r){
		tree[u].ans1.lr=tree[u].ans2.rl=(s[l]==')');
		tree[u].ans1.rl=tree[u].ans2.lr=(s[l]=='(');
		return;
	}
	int mid=(l+r)>>1;
	build(u<<1,l,mid);
	build(u<<1|1,mid+1,r);
	pushup(u);
}
node query(int u,int l,int r){
	if(l<=tree[u].l&&tree[u].r<=r)return tree[u].ans1;
	int mid=(tree[u].l+tree[u].r)>>1;
	if(r<=mid)return query(u<<1,l,r);
	else if(l>mid)return query(u<<1|1,l,r);
	else return merge(query(u<<1,l,r),query(u<<1|1,l,r));
}
int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
	std::cin>>s>>q;s=" "+s;n=s.size()-1;
	build(1,1,n);
	while(q--){
        int l,r;
		std::cin>>l>>r;
		std::cout<<query(1,l,r).ans*2<<'\n';
	}
	return 0;
}

详细

answer.code: In function 'int main()':
answer.code:46:18: error: 'nullptr' was not declared in this scope
     std::cin.tie(nullptr);\x0d
                  ^