QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#865075#894. Longest Loose SegmentCarroT1212WA 945ms94536kbC++141.5kb2025-01-21 14:35:352025-01-21 14:35:35

Judging History

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

  • [2025-01-21 14:35:35]
  • 评测
  • 测评结果:WA
  • 用时:945ms
  • 内存:94536kb
  • [2025-01-21 14:35:35]
  • 提交

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+max(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;
}

详细

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: 945ms
memory: 94536kb

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:

1994706
1289476
1302158
1619280
1471804
1178668
1358404
1358404
1374686
1540613
1374686
1050582
1041291
1200076
1200076
1798173
1798173
1798173
1798173
1798173
1798173
1758092
1758092
1758092
1758092
1758092
1758092
1758092
1758092
1174200
1174200

result:

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