QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#207469#7108. CouleurzhouhuanyiAC ✓1978ms28264kbC++232.8kb2023-10-08 16:04:422023-10-08 16:04:43

Judging History

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

  • [2023-10-08 16:04:43]
  • 评测
  • 测评结果:AC
  • 用时:1978ms
  • 内存:28264kb
  • [2023-10-08 16:04:42]
  • 提交

answer

#include<iostream>
#include<cstdio>
#include<set>
#define N 100000
using namespace std;
int read()
{
	char c=0;
	int sum=0;
	while (c<'0'||c>'9') c=getchar();
	while ('0'<=c&&c<='9') sum=sum*10+c-'0',c=getchar();
	return sum;
}
struct reads
{
	int l,r;
	long long res;
	bool operator < (const reads &t)const
	{
		if (res!=t.res) return res>t.res;
		else if (l!=t.l) return l<t.l;
		else return r<t.r;
	}
};
struct rds
{
	int l,r;
	long long res;
	bool operator < (const rds &t)const
	{
		return r<t.r;
	}
};
set<reads>s;
set<rds>st;
struct seg
{
	struct node
	{
		int ls,rs,data;
	};
	node tree[20*N+1];
	int length;
	void push_up(int k)
	{
		tree[k].data=tree[tree[k].ls].data+tree[tree[k].rs].data;
		return;	
	}
	int add(int k,int L,int R,int x,int d)
	{
		int nw=++length;
		tree[nw]=tree[k];
		if (L==R)
		{
			tree[nw].data+=d;
			return nw;
		}
		int mid=(L+R)>>1;
		if (x<=mid) tree[nw].ls=add(tree[nw].ls,L,mid,x,d);
		else tree[nw].rs=add(tree[nw].rs,mid+1,R,x,d);
		push_up(nw);
		return nw;
	}
	int query(int k,int L,int R,int l,int r)
	{
		if (l>r) return 0;
		if (L==l&&R==r) return tree[k].data;
		int mid=(L+R)>>1;
		if (r<=mid) return query(tree[k].ls,L,mid,l,r);
		else if (l>=mid+1) return query(tree[k].rs,mid+1,R,l,r);
		else return query(tree[k].ls,L,mid,l,mid)+query(tree[k].rs,mid+1,R,mid+1,r);
	}
};
seg T;
int ST,n,a[N+1],rt[N+1];
long long ans;
int main()
{
	int x,L,R;
	long long res,ans,rst;
	ST=read();
	while (ST--)
	{
		n=read(),s.clear(),st.clear(),T.length=ans=0;
		for (int i=1;i<=n;++i) a[i]=read(),ans+=T.query(rt[i-1],1,n,a[i]+1,n),rt[i]=T.add(rt[i-1],1,n,a[i],1);
		s.insert((reads){1,n,ans}),st.insert((rds){1,n,ans}),printf("%lld ",ans);
		for (int i=1;i<=n;++i)
		{
			x=read()^ans;
			auto it=st.lower_bound((rds){0,x,0});
			L=(*it).l,R=(*it).r,res=(*it).res,s.erase((reads){L,R,res}),st.erase(it);
			if (x-L<=R-x)
			{
				rst=0;
				for (int j=L;j<=x-1;++j) rst+=T.query(rt[j-1],1,n,a[j]+1,n)-T.query(rt[L-1],1,n,a[j]+1,n);
				if (L<=x-1) s.insert((reads){L,x-1,rst}),st.insert((rds){L,x-1,rst});
				for (int j=L;j<=x;++j) res-=T.query(rt[R],1,n,1,a[j]-1)-T.query(rt[j],1,n,1,a[j]-1);
				if (x+1<=R) s.insert((reads){x+1,R,res}),st.insert((rds){x+1,R,res});
			}
			else
			{
				for (int j=x;j<=R;++j) res-=T.query(rt[j-1],1,n,a[j]+1,n)-T.query(rt[L-1],1,n,a[j]+1,n);
				if (L<=x-1) s.insert((reads){L,x-1,res}),st.insert((rds){L,x-1,res});
				rst=0;
				for (int j=x+1;j<=R;++j) rst+=T.query(rt[j-1],1,n,a[j]+1,n)-T.query(rt[x],1,n,a[j]+1,n);
				if (x+1<=R) s.insert((reads){x+1,R,rst}),st.insert((rds){x+1,R,rst});
			}
			ans=(*s.begin()).res;
		    if (i<=n-2) printf("%lld ",ans);
			else if (i==n-1) printf("%lld\n",ans);
		}
	}
	return 0;
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 1ms
memory: 3660kb

input:

3
5
4 3 1 1 1
5 4 5 3 1
10
9 7 1 4 7 8 5 7 4 8
21 8 15 5 9 2 4 5 10 6
15
4 8 8 1 12 1 10 14 7 14 2 9 13 10 3
37 19 23 15 7 2 10 15 2 13 4 5 8 7 10

output:

7 0 0 0 0
20 11 7 2 0 0 0 0 0 0
42 31 21 14 14 4 1 1 1 0 0 0 0 0 0

result:

ok 3 lines

Test #2:

score: 0
Accepted
time: 1978ms
memory: 28264kb

input:

11116
10
10 5 10 3 6 4 8 5 9 8
31 27 24 11 12 3 0 2 3 1
10
8 2 7 2 8 10 1 10 9 10
6 5 2 13 2 1 0 1 3 1
10
7 10 7 6 1 3 10 6 7 9
21 18 10 1 6 5 4 8 9 10
10
2 10 4 8 8 5 7 2 6 7
20 10 9 1 15 0 4 2 9 7
10
1 2 3 4 5 6 7 8 9 10
1 2 3 4 5 6 7 8 9 10
10
1 2 3 4 5 6 7 8 9 10
6 3 5 2 7 10 9 1 4 8
10
1 10 1 3...

output:

21 18 16 12 10 6 4 1 1 0
12 12 10 10 4 4 4 2 1 0
20 16 9 5 3 3 3 0 0 0
22 14 8 8 5 5 2 1 1 0
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
19 12 7 4 4 2 2 1 0 0
20 18 8 3 1 1 0 0 0 0
45 21 21 10 3 3 3 0 0 0
17 11 8 2 1 1 1 0 0 0
13 4 1 0 0 0 0 0 0 0
29 27 22 15 9 7 4 3 1 0
26 16 9 2 1 1 1 1 1 0
0 0 0 0 0 ...

result:

ok 11116 lines

Extra Test:

score: 0
Extra Test Passed