QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#864937#894. Longest Loose SegmentHMZHMZHMZWA 614ms46956kbC++141.4kb2025-01-21 11:27:072025-01-21 11:27:08

Judging History

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

  • [2025-01-21 11:27:08]
  • 评测
  • 测评结果:WA
  • 用时:614ms
  • 内存:46956kb
  • [2025-01-21 11:27:07]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define vi vector<int>
#define pb push_back
#define lowbit(x) (x)&-(x)
using namespace std;
const int N=1e6+10;
int ans;
int n,m,T,a[N],ls[N],rs[N],f[N],stk[N],top,mx[N],len[N];
inline int read(){
	int s=0,f=0;
	char ch=getchar();
	while(ch<'0'||ch>'9') f|=(ch=='-'),ch=getchar();
	while(ch<='9'&&ch>='0') s=(s<<3)+(s<<1)+(ch^48),ch=getchar();
	return f?-s:s;
}
inline void dfs(int x){
	if(!ls[x]&&!rs[x]){
		mx[x]=a[x];
		len[x]=1;
		f[x]=a[x]>0;
		return ;
	}
	if(!ls[x]||!rs[x]){
		int y=ls[x]+rs[x];
		dfs(y);
		mx[x]=mx[y];
		len[x]=len[y]+1;
		f[x]=f[y];
		if(mx[y]+a[x]>len[y]+1) f[x]=max(f[x],len[y]+1);
	}else{
		dfs(ls[x]),dfs(rs[x]);
		mx[x]=max(mx[ls[x]],mx[rs[x]]);
		len[x]=len[ls[x]]+len[rs[x]]+1;
		f[x]=max({f[ls[x]],f[rs[x]],min(len[x],a[x]+mx[x])});
	}
}
inline void solve(){
	top=0;
	for(register int i=1;i<=n;++i) ls[i]=rs[i]=0;
	for(register int i=1;i<=n;++i){
		int lst=top;
		while(top&&a[i]<a[stk[top]]) --top;
		if(top) rs[stk[top]]=i;
		if(top<lst) ls[i]=stk[top+1];
		stk[++top]=i;
	}
	int rt=stk[1];
	dfs(rt);
	cout<<f[rt]<<'\n';
}
int main(){
	n=read(),T=read();
	for(register int i=1;i<=n;++i) a[i]=read();
	solve();
	while(T--){
		int k=read();
		while(k--){
			int x=read(),y=read();
			swap(a[x],a[y]);
		}
		solve();
	}
	return 0;
}

詳細信息

Test #1:

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

input:

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

output:

2
3
4

result:

ok 3 tokens

Test #2:

score: -100
Wrong Answer
time: 614ms
memory: 46956kb

input:

998546 30
998544 998544 998543 998539 998538 998537 998536 998534 998533 998531 998529 998527 998522 998521 998520 998520 998516 998514 998512 998509 998501 998501 998500 998499 998498 998496 998494 998493 998491 998491 998490 998489 998489 998488 998488 998486 998483 998480 998479 998478 998475 998...

output:

212115
16719
12587
9069
8112
7079
7404
7404
5937
5941
5847
5759
6492
5465
5465
5565
5565
5408
5408
5669
5669
5408
6263
6351
6351
5326
4609
4613
4613
4430
4613

result:

wrong answer 1st words differ - expected: '212114', found: '212115'