QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#388877#3732. 最长上升子序列SSAABBEERRWA 1ms3872kbC++202.6kb2024-04-13 21:03:582024-04-13 21:03:59

Judging History

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

  • [2024-04-13 21:03:59]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:3872kb
  • [2024-04-13 21:03:58]
  • 提交

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(cin >> n)
	{
		int f = 0, ff = 0;
		map<int, int>mp;
		rep(i, 1, n) cin >> 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(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)
		{
			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;
			}
		}
		int cnt = 0;
		int x = 0, y = 0;
		rep(i, 1, n - 1)
		{
			if(a[i] == i + 1 && a[i + 1] == i) cnt ++ ;
		}
		rep(i, 1, n)
		{
			if(a[i] == 0) continue;
			if(a[i] == i + 1) x = 1;
			if(a[i] == i - 1) y = 1;
		}
		if(cnt == 1)
		{
			cout << 1 << endl;
			continue;
		}
		else if(cnt > 1)
		{
			cout << 0 << endl;
			continue;
		}
		if(x && y)
		{
			cout << 0 << endl;
			continue;
		}
		if(x || y)
		{
			ll ans = 0;
			rep(i, 1, n)
			{
				if(!a[i]) ans ++ ;
			}
			cout << ans << 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: 3520kb

input:

5
1 0 0 4 0

output:

1

result:

ok 1 number(s): "1"

Test #2:

score: 0
Accepted
time: 0ms
memory: 3872kb

input:

5
0 1 2 0 0

output:

3

result:

ok 1 number(s): "3"

Test #3:

score: 0
Accepted
time: 0ms
memory: 3608kb

input:

5
1 0 3 5 4

output:

1

result:

ok 1 number(s): "1"

Test #4:

score: 0
Accepted
time: 1ms
memory: 3644kb

input:

5
0 0 0 0 0

output:

16

result:

ok 1 number(s): "16"

Test #5:

score: 0
Accepted
time: 1ms
memory: 3832kb

input:

5
2 1 0 0 5

output:

1

result:

ok 1 number(s): "1"

Test #6:

score: 0
Accepted
time: 0ms
memory: 3572kb

input:

5
0 1 0 4 5

output:

2

result:

ok 1 number(s): "2"

Test #7:

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

input:

5
0 0 4 0 0

output:

4

result:

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