QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#865077 | #894. Longest Loose Segment | CarroT1212 | WA | 897ms | 94548kb | C++14 | 1.5kb | 2025-01-21 14:36:32 | 2025-01-21 14:36:33 |
Judging History
answer
#include <bits/stdc++.h>
#define pb push_back
#define fi first
#define se second
using namespace std; bool MEM;
using ll=long long; using ld=long double;
using pii=pair<int,int>; using pll=pair<ll,ll>;
const int I=1e9;
const ll J=1e18,N=1e6+7;
ll n,m,a[N],s[N][2],rt;
ll mx[N],dp[N];
void dac(ll p,ll l,ll r) {
if (l==r) mx[p]=a[p],dp[p]=a[p]+a[p]>1;
else if (p==l)
dac(s[p][1],p+1,r),
mx[p]=mx[s[p][1]],dp[p]=mx[p]+a[p]>r-l+1?r-l+1:dp[s[p][1]];
else if (p==r)
dac(s[p][0],l,p-1),mx[p]=mx[s[p][0]],dp[p]=mx[p]+a[p]>r-l+1?r-l+1:dp[s[p][0]];
else {
ll sl=p-l,sr=r-p,cl=s[p][0],cr=s[p][1];
dac(cl,l,p-1),dac(cr,p+1,r);
mx[p]=max(mx[cl],mx[cr]),dp[p]=max(dp[cl],dp[cr]);
if (mx[cl]<mx[cr]) swap(sl,sr),swap(cl,cr);
if (mx[p]+a[p]>sl+1) dp[p]=sl+1+min(mx[p]+a[p]-sl-2,sr);
}
// printf("%lld %lld %lld %lld %lld\n",p,l,r,mx[p],dp[p]);
}
void solve() {
stack<ll> st;
for (ll i=1;i<=n;i++) {
while (st.size()&&a[st.top()]>a[i]) s[i][0]=st.top(),st.pop();
if (st.size()) s[st.top()][1]=i;
else rt=i;
st.push(i);
}
dac(rt,1,n);
cout<<dp[rt]<<"\n";
}
void mian() {
scanf("%lld%lld",&n,&m);
for (ll i=1;i<=n;i++) scanf("%lld",&a[i]);
solve();
for (ll x,y,z;m--;) {
scanf("%lld",&x);
for (ll i=1;i<=x;i++) scanf("%lld%lld",&y,&z),swap(a[y],a[z]);
solve();
}
}
bool ORY; int main() {
// freopen("test.out","w",stdout);
// while (1)
// int t; for (scanf("%d",&t);t--;)
mian();
cerr<<"\n"<<abs(&MEM-&ORY)/1048576<<"MB\n";
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 10064kb
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: 897ms
memory: 94548kb
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:
5932 16718 12587 9069 8111 7079 7403 7403 5937 5941 5846 5758 6492 5465 5465 5565 5565 5408 5408 5668 5668 5408 6263 6350 6350 5325 4608 4612 4612 4430 4612
result:
wrong answer 1st words differ - expected: '212114', found: '5932'