QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#864927#894. Longest Loose SegmentHMZHMZHMZWA 722ms47056kbC++141.3kb2025-01-21 11:20:582025-01-21 11:20:59

Judging History

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

  • [2025-01-21 11:20:59]
  • 评测
  • 测评结果:WA
  • 用时:722ms
  • 内存:47056kb
  • [2025-01-21 11:20:58]
  • 提交

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]=max(f[y],min(len[x],a[x]+mx[x]));
	}else{
		dfs(ls[x]),dfs(rs[x]);
		mx[x]=max(mx[ls[x]],mx[rs[x]]);
		len[x]=len[ls[x]]+len[rs[x]];
		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: 15952kb

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: 722ms
memory: 47056kb

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:

197715
14695
10803
8105
8105
5905
6184
6117
5739
5225
4672
4458
5193
4120
4039
4071
4082
4082
4082
4082
4007
4001
4722
4737
4737
4737
4190
3874
3874
3563
3563

result:

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