QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#201891#5150. Alternating Algorithmnameless_story#WA 2ms11796kbC++202.3kb2023-10-05 17:26:462023-10-05 17:26:46

Judging History

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

  • [2023-10-05 17:26:46]
  • 评测
  • 测评结果:WA
  • 用时:2ms
  • 内存:11796kb
  • [2023-10-05 17:26:46]
  • 提交

answer

#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
template<class T1,class T2> bool cmin(T1 &x,const T2 &y) { if (y<x) { x=y; return 1; }return 0; }
template<class T1,class T2> bool cmax(T1 &x,const T2 &y) { if (x<y) { x=y; return 1; }return 0; }
#define all(x) (x).begin(),(x).end()
int n,m;
const int N=400005;
int a[N],p[N],b[N],vis[N];
pair<int,int> pa[N];
int len[N];
int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	cout<<fixed<<setprecision(15);
	cin>>n;
	for (int i=0; i<=n; i++)
		cin>>a[i],pa[i]={a[i],i};
	sort(pa,pa+n+1);
	vector vp(n+1,0);
	iota(all(vp),0);
	function<int(int)> getf=[&](int x)->int
		{
			return x==vp[x]?x:(vp[x]=getf(vp[x]));
		};
	for (int i=0; i<=n; i++)
	{
		// p[i]=getf(lower_bound(b,b+n+1,a[i])-b);
		// vp[p[i]]=p[i]+1;
		p[i]=pa[i].second;
		// cerr<<p[i]<<" \n"[i==n];
	}
	fill(b,b+n+1,0);
	set<int> S;
	int ans=0;
	for (int i=n; ~i; i--)
	{
		b[p[i]]=1;
		auto nxt=S.upper_bound(p[i]);
		if (nxt!=S.end())
		{
			if (*nxt-p[i]<=len[*nxt]+1)
				len[*nxt]++;
			else
			{
				S.insert(p[i]);
				len[p[i]]=1;
				nxt=S.find(p[i]);
			}
		}
		else
		{
			S.insert(p[i]);
			len[p[i]]=1;
			nxt=S.find(p[i]);
		}
		if (nxt==S.begin())
		{
			// cerr<<S.size()<<'\n';
			// cerr<<p[i]<<' '<<*S.begin()<<' '<<len[*S.begin()]<<'\n';
			int tp=len[*S.begin()]-1+(*S.begin()&1),tm=i-(*S.begin()-len[*S.begin()]+1);
			// cerr<<len[*S.begin()]-1+(*S.begin()&1)<<' '<<i-(*S.begin()-len[*S.begin()]+1)<<'\n';
			// int tmp=len[*S.begin()]-1+(*S.begin()&1)+i-(*S.begin()-len[*S.begin()]+1);
			// cerr<<tmp<<"\n\n";
			cmax(ans,tm==0?tm:tm+tp);
			continue;
		}
		auto pre=nxt;
		nxt--;
		swap(nxt,pre);
		while (len[*nxt]>=(*nxt-len[*nxt]-*pre))
		{
			len[*nxt]+=len[*pre];
			S.erase(pre);
			if (nxt==S.begin())
				break;
			pre=nxt;
			nxt--;
			swap(pre,nxt);
		}
		// cerr<<S.size()<<'\n';
		// cerr<<p[i]<<' '<<*S.begin()<<' '<<len[*S.begin()]<<'\n';
		int tp=len[*S.begin()]-1+(*S.begin()&1),tm=i-(*S.begin()-len[*S.begin()]+1);
		// cerr<<len[*S.begin()]-1+(*S.begin()&1)<<' '<<i-(*S.begin()-len[*S.begin()]+1)<<'\n';
		// int tmp=len[*S.begin()]-1+(*S.begin()&1)+i-(*S.begin()-len[*S.begin()]+1);
		// cerr<<tmp<<"\n\n";
		cmax(ans,tm==0?tm:tm+tp);
	}
	cout<<ans<<'\n';
}

详细

Test #1:

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

input:

3
8 13 4 10

output:

3

result:

ok single line: '3'

Test #2:

score: 0
Accepted
time: 1ms
memory: 9904kb

input:

5
13 12 14 10 14 12

output:

3

result:

ok single line: '3'

Test #3:

score: 0
Accepted
time: 2ms
memory: 11796kb

input:

2
2 2 1

output:

3

result:

ok single line: '3'

Test #4:

score: 0
Accepted
time: 1ms
memory: 7864kb

input:

1
300172042 474444146

output:

0

result:

ok single line: '0'

Test #5:

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

input:

1
636357447 557539481

output:

1

result:

ok single line: '1'

Test #6:

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

input:

2
139715426 368724097 417561009

output:

0

result:

ok single line: '0'

Test #7:

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

input:

2
77784868 542697475 509604021

output:

2

result:

ok single line: '2'

Test #8:

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

input:

2
698395658 71848686 699775597

output:

0

result:

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