QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#388891#3732. 最长上升子序列SSAABBEERRWA 0ms3892kbC++203.0kb2024-04-13 21:13:122024-04-13 21:13:12

Judging History

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

  • [2024-04-13 21:13:12]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3892kb
  • [2024-04-13 21:13:12]
  • 提交

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 ++ ;
		}
		rep(i, 1, n)
		{
			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)
		{
			ll res = 1;
			rep(i, 1, n)
			{
				if(a[i] == 0) res ++ ;
				else if(a[i] == i + 1)
				{
					ll cc = 0;
					rep(j, i + 1, n)
					{
						if(a[j] == 0) cc ++ ;
					}
					cout << res * cc << endl;
					break;
				}
			}
			continue;
		}
		if(y)
		{
			ll res = 1;
			pre(i, n, 1)
			{
				if(a[i] == 0) res ++ ;
				else if(a[i] == i - 1)
				{
					ll cc = 0;
					pre(j, i - 1, 1)
					{
						if(a[j] == 0) cc ++ ;
					}
					cout << res * cc << endl;
					break;
				}
			}
			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: 3592kb

input:

5
1 0 0 4 0

output:

1

result:

ok 1 number(s): "1"

Test #2:

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

input:

5
0 1 2 0 0

output:

3

result:

ok 1 number(s): "3"

Test #3:

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

input:

5
1 0 3 5 4

output:

1

result:

ok 1 number(s): "1"

Test #4:

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

input:

5
0 0 0 0 0

output:

16

result:

ok 1 number(s): "16"

Test #5:

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

input:

5
2 1 0 0 5

output:

1

result:

ok 1 number(s): "1"

Test #6:

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

input:

5
0 1 0 4 5

output:

2

result:

ok 1 number(s): "2"

Test #7:

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

input:

5
0 0 4 0 0

output:

6

result:

ok 1 number(s): "6"

Test #8:

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

input:

5
2 0 1 4 5

output:

1

result:

ok 1 number(s): "1"

Test #9:

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

input:

5
0 4 0 0 0

output:

1

result:

ok 1 number(s): "1"

Test #10:

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

input:

5
2 0 3 4 5

output:

1

result:

ok 1 number(s): "1"

Test #11:

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

input:

5
0 3 4 0 0

output:

4

result:

ok 1 number(s): "4"

Test #12:

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

input:

5
2 3 0 1 0

output:

1

result:

ok 1 number(s): "1"

Test #13:

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

input:

5
1 0 0 0 4

output:

3

result:

ok 1 number(s): "3"

Test #14:

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

input:

5
0 0 0 3 0

output:

6

result:

ok 1 number(s): "6"

Test #15:

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

input:

5
1 2 4 0 3

output:

1

result:

ok 1 number(s): "1"

Test #16:

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

input:

5
0 0 4 2 5

output:

1

result:

ok 1 number(s): "1"

Test #17:

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

input:

5
1 0 0 0 0

output:

9

result:

ok 1 number(s): "9"

Test #18:

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

input:

5
0 1 0 0 5

output:

3

result:

ok 1 number(s): "3"

Test #19:

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

input:

5
1 2 3 4 0

output:

0

result:

ok 1 number(s): "0"

Test #20:

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

input:

5
3 1 0 0 5

output:

1

result:

ok 1 number(s): "1"

Test #21:

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

input:

5
0 3 0 1 5

output:

1

result:

ok 1 number(s): "1"

Test #22:

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

input:

5
1 0 2 0 0

output:

3

result:

ok 1 number(s): "3"

Test #23:

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

input:

5
0 0 3 4 5

output:

1

result:

ok 1 number(s): "1"

Test #24:

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

input:

5
5 1 2 0 0

output:

1

result:

ok 1 number(s): "1"

Test #25:

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

input:

5
0 3 0 1 0

output:

1

result:

ok 1 number(s): "1"

Test #26:

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

input:

5
1 0 0 0 5

output:

4

result:

ok 1 number(s): "4"

Test #27:

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

input:

5
2 1 3 4 0

output:

1

result:

ok 1 number(s): "1"

Test #28:

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

input:

5
0 2 3 0 5

output:

0

result:

ok 1 number(s): "0"

Test #29:

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

input:

5
2 0 0 5 1

output:

1

result:

ok 1 number(s): "1"

Test #30:

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

input:

5
0 1 2 0 4

output:

2

result:

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