QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#865332 | #894. Longest Loose Segment | ucup-team3659 | WA | 806ms | 49564kb | C++20 | 1.4kb | 2025-01-21 16:48:14 | 2025-01-21 16:48:14 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int n,m;
int a[1000005];
int l[1000005],r[1000005];
const int inf=0x3f3f3f3f;
int mx[1000005],sz[1000005],ans[1000005];
void dfs(int pos)
{
if(l[pos])
dfs(l[pos]);
if(r[pos])
dfs(r[pos]);
mx[pos]=max({mx[l[pos]],mx[r[pos]],a[pos]});
sz[pos]=sz[l[pos]]+sz[r[pos]]+1;
ans[pos]=max(ans[l[pos]],ans[r[pos]]);
if(a[pos]*2>1&&!l[pos]&&!r[pos])
ans[pos]=1;
if(mx[l[pos]]>mx[r[pos]])
if(mx[l[pos]]+a[pos]>sz[l[pos]]+1)
ans[pos]=max(ans[pos],min(mx[l[pos]]+a[pos]-1,sz[pos]));else;
else
if(mx[r[pos]]+a[pos]>sz[r[pos]]+1)
ans[pos]=max(ans[pos],min(mx[r[pos]]+a[pos]-1,sz[pos]));else;
// cout<<pos<<" "<<l[pos]<<" "<<r[pos]<<" "<<mx[pos]<<" "<<sz[pos]<<" "<<ans[pos]<<"\n";
}
void work()
{
stack<int> z;
int rt=0;
for(int i=1;i<=n;i++)
{
l[i]=r[i]=0;
int lst=0;
while(!z.empty()&&z.top()>a[i])
lst=z.top(),z.pop();
if(!z.empty())
r[z.top()]=i;
else
rt=i;
l[i]=lst;
z.push(i);
}
mx[0]=-inf;
dfs(rt);
cout<<ans[rt]<<"\n";
}
signed main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>m;
for(int i=1;i<=n;i++)
cin>>a[i];
work();
for(int i=1;i<=m;i++)
{
int k;
cin>>k;
for(int j=1;j<=k;j++)
{
int u,v;
cin>>u>>v;
swap(a[u],a[v]);
}
work();
}
}
/*
10 0
100 99 100 94 98 -99 -100 -97 -97 -98
*/
详细
Test #1:
score: 100
Accepted
time: 0ms
memory: 11820kb
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: 806ms
memory: 49564kb
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:
998546 998546 998546 998546 998546 998546 998546 998545 998545 998545 998545 998545 998545 998545 998545 998545 998545 998545 998545 998545 998546 998546 998546 998546 998546 998546 998546 998546 998546 998546 998546
result:
wrong answer 1st words differ - expected: '212114', found: '998546'