QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#286667#7969. 套娃linweitongWA 2ms11268kbC++142.2kb2023-12-18 11:25:142023-12-18 11:25:15

Judging History

你现在查看的是最新测评结果

  • [2023-12-18 11:25:15]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:11268kb
  • [2023-12-18 11:25:14]
  • 提交

answer

#include<cstdio>
#include<set>
#include<algorithm>
#include<vector>
#include<cstring>
#define mp(x,y) make_pair(x,y)
using namespace std;
const int N=100005; 
struct node{
	int x,id;
	friend bool operator <(node x,node y){
		if (x.x==y.x)return x.id>y.id;
		return x.x<y.x;
	}
};
struct pr{
	int x,y,z;
}; 
multiset<node>s;
int n,a[N],t[N],las[N];
vector<pr>v[N];
vector<pair<int,int>>vv[N];
int mn[N],mx[N],tr[N],id[N<<2];
void pushup(int x){
	id[x]=-1;
	int U=id[x<<1],V=id[x<<1|1];
	if (V!=-1)id[x]=V;
	if (U!=-1)id[x]=U;
}
void build(int x,int l,int r){
	id[x]=l;
	if (l==r)return;
	int mid=(l+r)>>1;
	build(x<<1,l,mid),build(x<<1|1,mid+1,r); 
}
void add(int x,int l,int r,int k,int val){
	if (l==r){
		tr[l]+=val;
		if (tr[l])id[x]=-1;
		else id[x]=l;
		return;
	}
	int mid=(l+r)>>1;
	if (k<=mid)add(x<<1,l,mid,k,val);else add(x<<1|1,mid+1,r,k,val);
	pushup(x);
}
int main(){
//	freopen("j.in","r",stdin);
//	freopen("j.out","w",stdout);
	scanf("%d",&n);
	for (int i=1;i<=n;++i)scanf("%d",&a[i]);
	for (int i=1;i<=n;++i)las[i]=t[a[i]],t[a[i]]=i;
	memset(t,0,sizeof(t));
	int now=0,lass=-1;
	build(1,0,n);
	for (int i=n;i>=1;--i){
		t[a[i]]=1;
		while (t[now])++now;
		if (lass!=now)s.insert((node){now,i});
		lass=now;
	}
	for (int i=0;i<=n;++i)mn[i]=n+1,mx[i]=-1;
	for (int i=n;i>=1;--i){
		node x=(*s.begin());s.erase(s.begin());
		int y=(*s.begin()).id;
		v[x.x].push_back((pr){y+1,i,i});
		if (y!=i-1)s.insert((node){x.x,i-1});	
		auto o=s.lower_bound((node){a[i],n+1});
		if (o==s.end()||(*o).id<=las[i])continue;
		int u=(*o).id,xx=-1;
		while ((*o).id>las[i]){
			auto oo=o;++oo;
			xx=(*o).x;
			v[xx].push_back((pr){(*oo).id+1,(*o).id,i});
			s.erase(o);
			o=oo;
		}
		s.insert((node){a[i],u});
		if (xx!=-1)s.insert((node){xx,las[i]});
	}
	for (int i=0;i<=n;++i){
		for (pr x:v[i]){
			int len=x.z-x.x+1,lenn=x.z-x.y+1;
//			printf("%d %d %d\n",lenn,len,i);
			vv[lenn].push_back(mp(i,1));
			vv[len+1].push_back(mp(i,-1));
		}//puts("");
	}
	for (int i=1;i<=n;++i){
		for (pair<int,int> j:vv[i]){
//			printf("%d %d\n",j.first,j.second);
			add(1,0,n,j.first,j.second);
		}
//		puts("");
		printf("%d ",id[1]);
	}
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 2ms
memory: 10284kb

input:

6
0 0 0 1 2 3

output:

2 3 4 0 0 0 

result:

ok single line: '2 3 4 0 0 0 '

Test #2:

score: -100
Wrong Answer
time: 2ms
memory: 11268kb

input:

100
0 10 21 9 4 1 14 0 8 1 4 6 10 0 0 4 18 0 12 5 2 5 15 1 6 2 0 4 14 5 1 2 23 1 8 1 24 8 8 9 5 2 12 2 3 7 6 11 12 12 6 12 4 4 5 0 7 4 9 12 1 7 4 7 12 2 10 2 4 8 7 1 4 0 13 9 13 2 2 3 9 14 7 9 15 10 10 6 2 12 3 11 6 3 4 7 9 6 11 1

output:

2 2 3 4 4 4 4 4 4 4 4 4 4 4 4 4 4 2 2 2 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 

result:

wrong answer 1st lines differ - expected: '2 2 3 4 4 4 4 4 4 4 4 4 4 4 4 ...0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0', found: '2 2 3 4 4 4 4 4 4 4 4 4 4 4 4 ... 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 '