QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#388830#3732. 最长上升子序列SSAABBEERRWA 0ms3972kbC++202.1kb2024-04-13 20:39:212024-04-13 20:39:22

Judging History

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

  • [2024-04-13 20:39:22]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3972kb
  • [2024-04-13 20:39:21]
  • 提交

answer

#include<bits/stdc++.h>
#define lowbit(x) (x&(-x))
#define rep(x,a,b) for(int x=a;x<=b;x++)
#define pre(x,a,b) for(int x=a;x>=b;x--)
#define endl "\n"
#define pb push_back
#define ll long long
// #define int long long
#define pii pair<ll,ll>
#define psi pair<string, ll>
#define de cout<<1;
#define mem(a,x) memset(a,x,sizeof a)
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
const int mod1=998244353;
const int mod2=1e9+7;
const int N = 1e5 + 60;
int number;
ll n, m;
int a[N], b[N];
int dp[N];
void solve()
{
	while(scanf("%d", &n) != EOF)
	{
		int f = 0, ff = 0;
		map<int, int>mp;
		rep(i, 1, n) scanf("%d", &a[i]), mp[a[i]] = 1;
		rep(i, 1, n) b[i] = a[n - i + 1];
		int l = 0;
		rep(i, 1, n)
		{
			if(a[i] && abs(a[i] - i) > 1) f ++ ;
			if(a[i] && a[i] != i && abs(a[i] - i) <= 1) ff ++ ;
			if(b[i])
			{
				dp[1] = b[i];
				l = i;
				break;
			}
		}
		int idx = 1;
		if(l)
		{
			rep(i, l + 1, n)
			{
				if(b[i] == 0) continue;
				if(b[i] > dp[idx]) dp[++idx] = b[i];
				else
				{
					int p = lower_bound(dp + 1, dp + idx + 1, b[i]) - dp;
					dp[p] = b[i];
				}
			}
			if(idx >= 3)
			{
				cout << 0 << endl;
				continue;
			}
		}
		if(l == 0)
		{
			cout << (n - 1) * (n - 1) << endl;
			continue;
		}
		if(f || ff)
		{
			int now = 1;
			rep(i, 1, n)
			{
				if(a[i] == 0)
				{
					while(mp[now]) now ++ ;
					a[i] = now;
					mp[now] = 1;
				}
			}
			dp[1] = a[1];
			idx = 1;
			rep(i, 2, n)
			{
				if(a[i] == 0) continue;
				if(a[i] > dp[idx]) dp[++idx] = a[i];
				else
				{
					int p = lower_bound(dp + 1, dp + idx + 1, a[i]) - dp;
					dp[p] = a[i];
				}
			}
			if(idx == n - 1)
			{
				cout << 1 << endl;
				continue;
			}
			else
			{
				cout << 0 << endl;
				continue;
			}
		}
		ll ans = 0;
		rep(i, 1, n)
		{
			if(a[i]) continue;
			ll l = i, r = i;
			while(a[r + 1] == 0 && r + 1 <= n) r ++ ;
			ans += (r - l) * (r - l);
			i = r;
		}
		cout << ans << endl;
	}
}
int main()
{
	//IOS;
	int _;
	//cin >> _;
	_ = 1;
	while(_ -- )
	{
		number++;
		solve();
	}
	return 0;
}

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3972kb

input:

5
1 0 0 4 0

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: -100
Wrong Answer
time: 0ms
memory: 3972kb

input:

5
0 1 2 0 0

output:

1

result:

wrong answer 1st numbers differ - expected: '3', found: '1'