QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#178296#7248. Ivan DornPhantomThreshold#WA 5ms17408kbC++201.6kb2023-09-13 20:48:102023-09-13 20:48:11

Judging History

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

  • [2023-09-13 20:48:11]
  • 评测
  • 测评结果:WA
  • 用时:5ms
  • 内存:17408kb
  • [2023-09-13 20:48:10]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
#define int long long
using namespace std;

const int maxn = 510000;
const int inf  = 1e9+5;
inline void up(int &a,const int &b){ if(a<b) a=b; }

int n,m;
int a[maxn];

vector< pair<int,int> >V[maxn];

struct segment
{
	int seg[maxn<<2];
	int loc,c;
	void upd(const int x,const int l,const int r)
	{
		if(l==r)
		{
			up(seg[x],c);
			return;
		}
		int mid=(l+r)>>1,lc=x<<1,rc=lc|1;
		if(loc<=mid) upd(lc,l,mid);
		else upd(rc,mid+1,r);
		seg[x]=max(seg[lc],seg[rc]);
	}
	int lx,rx;
	int query(const int x,const int l,const int r)
	{
		if(rx<l||r<lx) return 0;
		if(lx<=l&&r<=rx) return seg[x];
		int mid=(l+r)>>1,lc=x<<1,rc=lc|1;
		return max(query(lc,l,mid),query(rc,mid+1,r));
	}
}seg;

int ans[maxn];
int t[maxn],tp;

signed main()
{
	ios_base::sync_with_stdio(false); ////////////////////////////////////////
	cin.tie(0);
	
	cin>>n>>m;
	for(int i=1;i<=n;i++) cin>>a[i];
	for(int i=1;i<=m;i++)
	{
		int l,r; cin>>l>>r;
		V[r].emplace_back(l,i);
	}
	
	t[tp=1]=0; a[0]=inf;
	for(int r=1;r<=n;r++)
	{
		while(a[t[tp]]<a[r])
		{
			int j=tp-1;
			while(j>=1 && a[t[tp]]==a[t[j]])
			{
				seg.loc=t[j];
				seg.c=t[tp]-t[j];
				seg.upd(1,1,n);
				j--;
			}
			tp=j;
		}
		for(auto [ql,i]:V[r])
		{
			if(a[t[tp]]==a[r] && ql<=t[tp])
			{
				int x=1,y=tp;
				while(x<=y)
				{
					int mid=(x+y)>>1;
					if(t[mid]<ql || a[t[mid]]>a[r]) x=mid+1;
					else y=mid-1;
				} y++;
				up(ans[i],r-t[y]);
			}
			seg.lx=ql,seg.rx=r;
			up(ans[i],seg.query(1,1,n));
		}
		t[++tp]=r;
	}
	
	for(int i=1;i<=m;i++) cout<<ans[i]<<'\n';
	
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 16680kb

input:

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

output:

4
0
0
1
4

result:

ok 5 number(s): "4 0 0 1 4"

Test #2:

score: 0
Accepted
time: 5ms
memory: 17052kb

input:

1 1
1
1 1

output:

0

result:

ok 1 number(s): "0"

Test #3:

score: 0
Accepted
time: 0ms
memory: 16628kb

input:

2 1
1 2
1 2

output:

0

result:

ok 1 number(s): "0"

Test #4:

score: 0
Accepted
time: 0ms
memory: 17408kb

input:

2 1
1 1
1 2

output:

1

result:

ok 1 number(s): "1"

Test #5:

score: -100
Wrong Answer
time: 0ms
memory: 17308kb

input:

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

output:

0
0
2
0
0
0
0
0
0
0

result:

wrong answer 1st numbers differ - expected: '1', found: '0'