QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#645947#7627. Phonyzero_orezWA 1ms7932kbC++142.6kb2024-10-16 20:33:052024-10-16 20:33:06

Judging History

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

  • [2024-10-16 20:33:06]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:7932kb
  • [2024-10-16 20:33:05]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
using namespace std;
inline int read()
{
	int x=0;char c=getchar();bool f=0;
	for(;c<'0'||c>'9';c=getchar()) f|=(c=='-');
	for(;c>='0'&&c<='9';c=getchar()) x=(x<<1)+(x<<3)+(c^48);
	return (f)?(-x):x;
}
const int N=5e5+86;
struct node{
	int ls,rs,sm;
	#define ls(o) tr[o].ls
	#define rs(o) tr[o].rs
	#define sm(o) tr[o].sm
}tr[N*16];
int n,m,rt[N*16],cnt=0,tot=1,kk,b[N];
void del(int x)
{
	sm(x)=ls(x)=rs(x)=0;
}
int ask(int p,int l,int r,int ql,int qr)
{
	if(qr<l||ql>r) return 0;
	if(ql<=l&&qr>=r) return sm(p);
	int mid=(l+r)/2;
	return ask(ls(p),l,mid,ql,qr)+ask(rs(p),mid+1,r,ql,qr);
}
int merge(int x,int y)
{
	if(!x||!y) return x+y;
	sm(x)+=sm(y);
	ls(x)=merge(ls(x),ls(y)); 
	rs(x)=merge(rs(x),rs(y));
	del(y);
	return x; 
}
void spilt(int x,int &y,int k)
{
	if(x==0) return ;
	y=++cnt;
	int v=sm(ls(x));
	if(v<k) spilt(rs(x),rs(y),k-v);
	else swap(rs(x),rs(y));
	if(v>k) spilt(ls(x),ls(y),k);
	sm(y)=sm(x)-k;
	sm(x)=k;
	return ;
}
void add(int &p,int l,int r,int pos,int v)
{
	if(!p) p=++cnt;
	if(l==r)
	{
		sm(p)+=v;
		return ;
	}
	int mid=(l+r)/2;
	if(pos<=mid) add(ls(p),l,mid,pos,v);
	else add(rs(p),mid+1,r,pos,v);
	sm(p)=sm(ls(p))+sm(rs(p));
	return ;
}
int kth(int p,int l,int r,int k)
{
	if(l==r) return l;
	int mid=(l+r)/2;
	if(sm(ls(p))<k) return kth(rs(p),mid+1,r,k-sm(ls(p))); 
	else return kth(ls(p),l,mid,k);
}
signed main()
{
	n=read();m=read();kk=read();
	int mx=-1;
	for(int i=1;i<=n;i++)
	{
		int x=read();
		add(rt[x/kk],1,kk,x%kk+1,1);
		mx=max(mx,(x/kk));
	}
	while(m--)
	{
		char op;int x;
		cin>>op;x=read();
		if(op=='A')
		{
			x--;
			int tem=mx;
//			cout<<mx<<" "<<sm(rt[mx])<<" "<<x<<endl;
			while(x>=sm(rt[tem])&&tem>=0)
			{
				x-=sm(rt[tem]);
				tem--;
			}
//			cout<<tem<<endl;
			if(tem<0) printf("-1\n");
			else printf("%lld\n",tem*kk+kth(rt[tem],1,kk,sm(rt[tem])-x)-1);
		}
		else
		{
			tot=0;
//			cout<<mx<<" "<<sm(rt[mx])<<endl;
			while(x&&mx>=0)
			{
				if(x>=sm(rt[mx]))
				{
//					cout<<x<<" "<<sm(rt[mx])<<endl;
//					cout<<"wsssb"<<endl;
					x-=sm(rt[mx]);
					b[++tot]=mx;
					mx--;
				}
				else 
				{
					int tem=0;
//					cout<<x<<endl;
					spilt(rt[mx],tem,x);
					rt[mx-1]=merge(rt[mx-1],tem);
					break;
				}
			}
			for(int i=tot;i>=1;i--)
			{
				merge(rt[b[i]-1],rt[b[i]]);
				del(rt[b[i]]);
			}
		} 
		
//		for(int i=0;i<=mx;i++)
//		{
//			for(int j=1;j<=kk;j++)
//			{
//				cout<<ask(rt[i],1,kk,j,j)<<" ";
//			}
//			cout<<endl;
//		}
		
	}
 	return 0;
} 

Details

Tip: Click on the bar to expand more detailed information

Test #1:

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

input:

3 5 5
7 3 9
A 3
C 1
A 2
C 2
A 3

output:

3
4
-1

result:

ok 3 lines

Test #2:

score: -100
Wrong Answer
time: 1ms
memory: 7884kb

input:

5 8 8
294 928 293 392 719
A 4
C 200
A 5
C 10
A 2
C 120
A 1
A 3

output:

294
-1
-1
-1
-1

result:

wrong answer 2nd lines differ - expected: '200', found: '-1'