NOI OL T1求助
  • 板块灌水区
  • 楼主MrSWdAxiv
  • 当前回复5
  • 已保存回复5
  • 发布时间2022/3/26 12:21
  • 上次更新2023/10/28 05:37:01
查看原帖
NOI OL T1求助
387037
MrSWdAxiv楼主2022/3/26 12:21

会打暴力

各位大佬,T1怎么做啊??(发狂)

#include<iostream>
using namespace std;
const int N=500001;
int n,q,a[N],b[N],l[N],r[N],stack[N],stack2[N],top,cnt;
bool bol;
void push(int x,int y){
	if(top<500001){
		top++;
		stack[top]=x;
		stack2[top]=y;
		return;
	}
}
void pop(){
	if(top>0){
		top--;
		return;
	}
}
void empty(){
	for(int i=1;i<=n;i++){
		stack[i]=0,stack2[i]=0;
	}
	cnt=0,top=0,bol=0;
}
int main(){
	freopen("stack.in","r",stdin);
	freopen("stack.out","w",stdout);
	cin>>n>>q;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	for(int i=1;i<=n;i++){
		cin>>b[i];
	}
	for(int i=1;i<=q;i++){
		empty();
		cin>>l[i]>>r[i];
		for(int j=l[i];j<=r[i];j++){
			if(top==0){
				push(a[j],b[j]);
				cnt++;
			}else if(top!=0){
				while(top!=0){
					if(stack[top]!=a[j]&&stack2[top]>b[j]){
						push(a[j],b[j]);
						bol=1;
						break;
					}else{
						pop();
					}
				}
				if(!bol||top==0){
					push(a[j],b[j]);
					cnt++;
				}
			}
		}
		cout<<cnt<<'\n';
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}
2022/3/26 12:21
加载中...