QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#718042#8546. Min or Max 2caibyteWA 122ms62764kbC++142.2kb2024-11-06 19:34:222024-11-06 19:34:23

Judging History

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

  • [2024-11-06 19:34:23]
  • 评测
  • 测评结果:WA
  • 用时:122ms
  • 内存:62764kb
  • [2024-11-06 19:34:22]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F(i,l,r) for(int i=l;i r;++i)
#define R(i,r,l) for(int i=r;i l;--i)
#define pb push_back
#define eval(x) cerr<<#x<<" = "<<(x)<<'\n';
const int inf=0x3f3f3f3f;
const ll lnf=0x3f3f3f3f3f3f3f3f;
template<class T=int>inline T read(){
	T x=0;bool b=0;char c=getchar();
	while(!isdigit(c)) b|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return b?-x:x;
}
inline char readc(){
	char c=getchar();
	while(isspace(c)) c=getchar();
	return c;
}
namespace{
//
const int N=5e5+3;
const int d[3][3]={{0,0,1},{0,1,1},{1,1,2}};
int n,a[N],b[N],pa[N],pb[N],ans[N<<1],l[N],r[N];
int X,Y;
inline int id(int x){
	return (a[x]>X)+(b[x]<Y);
}
struct seg{
	struct node{
		vector<int> v;
	} t[N<<2];
	inline void pend(int f,int k){
		t[f].v=vector<int>(d[id(k)],d[id(k)]+3);
	}
	inline void pushup(node&f,const node&ls,const node&rs){
		f.v.resize(3,0);
		F(i,0,<3){
			f.v[i]=rs.v[ls.v[i]];
		}
	}
	void build(int f,int l,int r){
		if(l==r) return pend(f,l);
		int mid=l+r>>1;
		build(f<<1,l,mid);build(f<<1|1,mid+1,r);
		pushup(t[f],t[f<<1],t[f<<1|1]);
	}
	void upd(int f,int l,int r,int x){
		if(l==r) return pend(f,l);
		int mid=l+r>>1;
		if(x<=mid) upd(f<<1,l,mid,x);
		else upd(f<<1|1,mid+1,r,x);
		pushup(t[f],t[f<<1],t[f<<1|1]);
	}
} T;
inline void calc(int*res){
	F(i,1,<=n) pa[a[i]]=pb[b[i]]=i;
	X=0;Y=1;
	T.build(1,2,n);
	for(X=1;X<=n;++X){
		if(pa[X]!=1) T.upd(1,2,n,pa[X]);
		while(Y<=n&&!T.t[1].v[id(1)]){
			++Y;
			if(pb[Y-1]!=1) T.upd(1,2,n,pb[Y-1]);
		}
		res[X]=Y-1;
	}
}
inline void solve(){
	n=read();
	F(i,1,<=n) a[i]=read();
	F(i,1,<=n) b[i]=read();
	calc(r);
	F(i,1,<=n) a[i]=n-a[i]+1,b[i]=n-b[i]+1;
	calc(l);
	reverse(l+1,l+n+1);
	F(i,1,<=n) l[i]=n-l[i]+1;
	F(i,1,<=n){
		++ans[l[i]-i+n];
		--ans[r[i]-i+n+1];
	}
	F(i,1,<=n*2) ans[i]+=ans[i-1];
	cout<<ans[n]<<' ';
	F(i,1,<n) cout<<ans[-i+n]+ans[i+n]<<' ';
	cout<<'\n';
	F(i,0,<=n) ans[i]=0;
}
void work(){
	int T=read();
	while(T--) solve();
}
}
#if 0
#define file(x) freopen(x".in","r",stdin),freopen(x".out","w",stdout)
#else
#define file(x)
#endif
signed main(){file("");work();return 0;}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 3ms
memory: 62764kb

input:

4
2
1 2
2 1
5
2 4 1 5 3
2 4 1 5 3
5
1 2 3 4 5
5 4 3 2 1
8
5 8 3 4 2 7 1 6
4 6 3 8 5 1 2 7

output:

2 0 
5 0 0 0 0 
2 2 2 2 0 
5 5 2 2 1 0 0 0 

result:

ok 20 numbers

Test #2:

score: -100
Wrong Answer
time: 122ms
memory: 61972kb

input:

66664
7
4 2 6 5 7 1 3
6 5 3 1 4 7 2
10
6 8 10 7 5 1 4 3 9 2
5 10 3 8 6 7 2 9 1 4
9
3 2 4 8 7 6 9 1 5
8 1 2 9 6 7 4 3 5
10
4 3 9 6 7 2 10 1 8 5
3 5 4 1 2 7 10 9 6 8
5
3 4 1 2 5
5 1 3 2 4
5
2 4 3 5 1
2 3 1 4 5
6
2 6 1 3 4 5
6 4 5 1 3 2
10
10 1 2 7 5 8 4 3 9 6
9 4 2 3 6 1 7 8 5 10
5
1 2 4 5 3
4 1 2 5 3...

output:

4 4 2 2 1 0 0 
12 19 14 10 10 9 8 8 8 8 
5 6 13 21 28 35 43 51 59 
6 17 36 62 96 138 188 247 314 322 
5 3 0 0 0 
2 4 4 4 2 
7 11 15 15 16 33 
55 124 176 224 311 448 636 883 1197 1519 
5 2 0 0 0 
6 3 0 0 0 87 
3 3 2 0 0 
5 4 2 1 87 329 545 
3 2 4 2 1 88 
4 7 5 3 91 508 1053 
3 7 9 11 101 608 1661 
16...

result:

wrong answer 8th numbers differ - expected: '5', found: '12'