QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#457369#8837. Increasing Incomeucup-team3510#WA 1ms5580kbC++141.4kb2024-06-29 11:03:512024-06-29 11:03:52

Judging History

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

  • [2024-06-29 11:03:52]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5580kb
  • [2024-06-29 11:03:51]
  • 提交

answer

#include<iostream>
using namespace std;
struct tree
{
	int add,maxx;
};
tree a[800010];
int v[200010];
inline void update(int p)
{
	a[p].maxx=max(a[p<<1].maxx,a[(p<<1)+1].maxx);
}
void build(int l,int r,int p)
{
	a[p].add=0;
	if(l==r)
	{
		a[p].maxx=v[l];
		return;
	}
	int mid=l+r>>1;
	build(l,mid,p<<1);
	build(mid+1,r,(p<<1)+1);
	update(p);
}
inline void pushdown(int p)
{
	int add=a[p].add;
	a[p].add=0;
	a[p<<1].add+=add,a[p<<1].maxx+=add;
	a[(p<<1)+1].add+=add,a[(p<<1)+1].maxx+=add;
}
void change(int l,int r,int ll,int rr,int v,int p)
{
	if(r<ll||l>rr)
	{
		return;
	}
	if(ll<=l&&r<=rr)
	{
		a[p].add+=v,a[p].maxx+=v;
		return;
	}
	pushdown(p);
	int mid=l+r>>1;
	change(l,mid,ll,rr,v,p<<1);
	change(mid+1,r,ll,rr,v,(p<<1)+1);
	update(p);
}
int query(int l,int r,int ll,int rr,int p)
{
	if(r<ll||l>rr)
	{
		return -1e9;
	}
	if(ll<=l&&r<=rr)
	{
		return a[p].maxx;
	}
	pushdown(p);
	int mid=l+r>>1;
	return max(query(l,mid,ll,rr,p<<1),
	query(mid+1,r,ll,rr,(p<<1)+1));
}
int T,n,p[200010];
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>T;
	while(T--)
	{
		cin>>n;
		for(int i=1;i<=n;i++)
		{
			cin>>p[i];
		}
		for(int i=0;i<=n;v[i++]=0);
		build(0,n,1);
		for(int i=1;i<=n;i++)
		{
			a[1].add++;
			change(0,n,p[i],p[i],-query(0,n,p[i],p[i],1)
			+query(0,n,0,p[i]-1,1)+1,1);
		}
		cout<<a[1].maxx<<endl;
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 1ms
memory: 5580kb

input:

3
3
1 2 3
4
2 4 3 1
5
1 5 2 4 3

output:

6
6
8

result:

wrong answer Integer element q[1] equals to 6, violates the range [1, 3] (test case 1)