QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#388888 | #3732. 最长上升子序列 | SSAABBEERR | WA | 0ms | 3896kb | C++20 | 3.0kb | 2024-04-13 21:11:50 | 2024-04-13 21:11:52 |
Judging History
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)
{
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;
}
Details
Tip: Click on the bar to expand more detailed information
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: 3544kb
input:
5 0 1 2 0 0
output:
3
result:
ok 1 number(s): "3"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3656kb
input:
5 1 0 3 5 4
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3652kb
input:
5 0 0 0 0 0
output:
16
result:
ok 1 number(s): "16"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3652kb
input:
5 2 1 0 0 5
output:
1
result:
ok 1 number(s): "1"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3896kb
input:
5 0 1 0 4 5
output:
2
result:
ok 1 number(s): "2"
Test #7:
score: 0
Accepted
time: 0ms
memory: 3592kb
input:
5 0 0 4 0 0
output:
6
result:
ok 1 number(s): "6"
Test #8:
score: 0
Accepted
time: 0ms
memory: 3864kb
input:
5 2 0 1 4 5
output:
1
result:
ok 1 number(s): "1"
Test #9:
score: 0
Accepted
time: 0ms
memory: 3588kb
input:
5 0 4 0 0 0
output:
1
result:
ok 1 number(s): "1"
Test #10:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
5 2 0 3 4 5
output:
1
result:
ok 1 number(s): "1"
Test #11:
score: 0
Accepted
time: 0ms
memory: 3664kb
input:
5 0 3 4 0 0
output:
4
result:
ok 1 number(s): "4"
Test #12:
score: -100
Wrong Answer
time: 0ms
memory: 3820kb
input:
5 2 3 0 1 0
output:
2
result:
wrong answer 1st numbers differ - expected: '1', found: '2'