玄学的括号匹配问题

链接 : 

AC代码 :

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

int pos[2000009];
stack<pair<int,int> >st;

int main() {
	int n,m,q;
	cin>>n>>m>>q;

	st.push(make_pair(0,-1));

	int t;
	for(int i=1; i<=n; i++) {
		cin>>t;
		if(st.top().second + 1 == t && (t&1)) {
			st.pop();//一定要先弹出,再对pos[i]赋值
		} else 
			st.push(make_pair(i,t));
		pos[i]=st.top().first;//不能进行预处理,应该是也会超时,但是oj还是显示WA
	}
	
	int l,r;
	while(q--) {
		scanf("%d%d",&l,&r);//cin好像会超时,但是oj显示是WA
		if(pos[l-1] == pos[r]) cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/StarrYooSkY/article/details/86550127
今日推荐