QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#865290 | #894. Longest Loose Segment | ucup-team3659 | WA | 768ms | 49604kb | C++20 | 1.3kb | 2025-01-21 16:30:34 | 2025-01-21 16:30:34 |
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(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);
}
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();
}
}
/*
5 2
1 2 -2 3 4
1
2 3
1
1 2
*/
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 9956kb
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: 768ms
memory: 49604kb
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'