守规矩 题解

上课闲的没事想到的题,挺水的。。。

只需要计算出每个数被除了多少次,就是优先级的最长下降子序列

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cmath>
#define N 5000005
using namespace std;
int n,a[N],q[N],top,ans[N],t;
int read(){
	int a=0;char ch=getchar();
	while(ch<'0'||ch>'9')ch=getchar();
	while(ch>='0'&&ch<='9'){a=a*10+ch-'0';ch=getchar();}
	return a;
}
int main(){
	freopen("divid.in","r",stdin);
	freopen("divid.out","w",stdout);
	n=read();t=read();
	for(int i=1;i<=n-1;i++)a[i]=read();
	for(int i=1;i<n;i++){
		while(top&&a[i]>q[top])top--;
		q[++top]=a[i];
		ans[i+1]=top;
	}
	for(int i=t;i<=n;i+=t)
		printf("%d",ans[i]%2);
	return 0;
}


原文地址:https://www.cnblogs.com/Ren-Ivan/p/7746669.html