QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#283590#7108. Couleuryixiuge777AC ✓2951ms47752kbC++142.9kb2023-12-14 20:57:402023-12-14 20:57:40

Judging History

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

  • [2023-12-14 20:57:40]
  • 评测
  • 测评结果:AC
  • 用时:2951ms
  • 内存:47752kb
  • [2023-12-14 20:57:40]
  • 提交

answer

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <set>
#define ll long long
#define N 100010
using namespace std;
ll read(){
	char cc;
	while(1){cc=getchar();if((cc>='0'&&cc<='9')||cc=='-')break;}
	ll sum=0,flag=1;
	cc=='-'?flag=-1:sum=(cc^48);
	while(1){cc=getchar();if(!(cc>='0'&&cc<='9'))break;sum=(sum<<1)+(sum<<3)+(cc^48);}
	return sum*flag;
}
void write(ll x){
	if(!x)putchar('0');
	if(x<0){x=-x;putchar('-');}
	ll cc[25],cntt=0;
	while(x){cc[++cntt]=x%10;x/=10;}
	for(ll i=cntt;i>=1;i--)putchar(cc[i]+'0');
	putchar(' ');
}
multiset <ll> sans;
struct node{
	ll l,r,root,ans;
	inline friend bool operator<(node a,node b){return a.r<b.r;}
};set <node> s;
struct node1{
	ll ls,rs,s;
}t[N<<5];
ll T,n,a[N],cnt=0,aa[N],m,q[N<<5],hh;
ll newid(){if(!hh)return ++cnt;return q[hh--];}
void insert(ll &x,ll l,ll r,ll L){
	if(!x)x=newid();
	t[x].s++;
	if(l==r)return ;
	ll mid=(l+r)>>1;
	if(mid>=L)insert(t[x].ls,l,mid,L);
	else insert(t[x].rs,mid+1,r,L); 
}
ll ask(ll x,ll l,ll r,ll L,ll R){
	if(L>R)return 0;
	if(!x)return 0;
	if(L<=l&&r<=R)return t[x].s;
	ll mid=(l+r)>>1;
	if(mid>=L&&mid<R)return ask(t[x].ls,l,mid,L,R)+ask(t[x].rs,mid+1,r,L,R);
	if(mid>=L)return ask(t[x].ls,l,mid,L,R);
	return ask(t[x].rs,mid+1,r,L,R);
}
void del(ll &x,ll l,ll r,ll L){
	t[x].s--;
	if(l!=r){
		ll mid=(l+r)>>1;
		if(mid>=L)del(t[x].ls,l,mid,L);
		else del(t[x].rs,mid+1,r,L);
	}
	if(!t[x].s){q[++hh]=x;x=0;}
}
void add_node(ll l,ll r){
	node s1;s1.l=l;s1.r=r;s1.root=0;s1.ans=0;
	for(ll i=l;i<=r;i++){insert(s1.root,1,m,a[i]);s1.ans+=ask(s1.root,1,m,a[i]+1,m);}
	s.insert(s1);sans.insert(-s1.ans);
}
void out(){
	printf("\n**************\n");
	for(node s1:s)printf("%lld %lld %lld %lld\n",s1.l,s1.r,s1.root,s1.ans);
	printf("**************\n");
}
int main(){
//	freopen("data.in","r",stdin);
//	freopen("data.out","w",stdout);
	T=read();while(T--){
		n=read();for(ll i=1;i<=n;i++)a[i]=aa[i]=read();
		sort(aa+1,aa+n+1);m=unique(aa+1,aa+n+1)-(aa+1);
		for(ll i=1;i<=n;i++)a[i]=lower_bound(aa+1,aa+m+1,a[i])-aa;
		for(ll i=1;i<=cnt;i++)t[i]=(node1){0,0,0};
		cnt=hh=0;
		s.clear();sans.clear();
		add_node(1,n);
		for(ll ope=1;ope<n;ope++){
			write((-*sans.begin()));
			ll k=read()^(-(*sans.begin()));
			node s1=*s.lower_bound((node){k,k,0,0});
			s.erase(s1);sans.erase(sans.find(-s1.ans));
			if(s1.l==k&&s1.r==k)del(s1.root,1,m,a[k]);
			else if(s1.l==k){
				s1.l++;del(s1.root,1,m,a[k]);s1.ans-=ask(s1.root,1,m,1,a[k]-1);
				s.insert(s1);sans.insert(-s1.ans);
			}
			else if(s1.r==k){
				s1.r--;del(s1.root,1,m,a[k]);s1.ans-=ask(s1.root,1,m,a[k]+1,m);
				s.insert(s1);sans.insert(-s1.ans);
			}
			else {
				for(ll i=s1.l;i<=k;i++){del(s1.root,1,m,a[i]);s1.ans-=ask(s1.root,1,m,1,a[i]-1);}
				add_node(s1.l,k-1);s1.l=k+1;
				s.insert(s1);sans.insert(-s1.ans);
			}
//			out();
		}
		read();putchar('0');putchar('\n');
	}
	return 0;
} 

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

详细

Test #1:

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

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: 2951ms
memory: 47752kb

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