QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#388903 | #3732. 最长上升子序列 | SSAABBEERR | WA | 1ms | 3876kb | C++20 | 3.4kb | 2024-04-13 21:18:25 | 2024-04-13 21:18:26 |
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 ++ ;
}
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 ++ ;
}
int cx = 0, cy = 0;
rep(i, 1, n)
{
if(a[i] == 0) continue;
if(a[i] == i + 1) x = 1;
if(a[i] == i - 1) y = 1;
}
int f1 = 0, f2 = 0;
rep(i, 1, n)
{
if(a[i] == i + 1 && !f1) cx ++ , f1 = 1;
else if(a[i] == 0) f1 = 0;
if(a[i] == i - 1 && !f2 && a[i] > 0) cy ++ , f2 = 1;
else if(a[i] == 0) f2 = 0;
}
if(cnt == 1)
{
cout << 1 << endl;
continue;
}
else if(cnt > 1)
{
cout << 0 << endl;
continue;
}
if(x && y)
{
cout << 0 << endl;
continue;
}
if(x)
{
if(cx > 1)
{
cout << 1 << endl;
continue;
}
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)
{
if(cy > 1)
{
cout << 1 << endl;
continue;
}
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: 1ms
memory: 3608kb
input:
5 1 0 0 4 0
output:
1
result:
ok 1 number(s): "1"
Test #2:
score: 0
Accepted
time: 0ms
memory: 3644kb
input:
5 0 1 2 0 0
output:
3
result:
ok 1 number(s): "3"
Test #3:
score: 0
Accepted
time: 0ms
memory: 3800kb
input:
5 1 0 3 5 4
output:
1
result:
ok 1 number(s): "1"
Test #4:
score: 0
Accepted
time: 0ms
memory: 3864kb
input:
5 0 0 0 0 0
output:
16
result:
ok 1 number(s): "16"
Test #5:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
5 2 1 0 0 5
output:
1
result:
ok 1 number(s): "1"
Test #6:
score: 0
Accepted
time: 0ms
memory: 3876kb
input:
5 0 1 0 4 5
output:
2
result:
ok 1 number(s): "2"
Test #7:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
5 0 0 4 0 0
output:
6
result:
ok 1 number(s): "6"
Test #8:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
5 2 0 1 4 5
output:
1
result:
ok 1 number(s): "1"
Test #9:
score: 0
Accepted
time: 1ms
memory: 3872kb
input:
5 0 4 0 0 0
output:
1
result:
ok 1 number(s): "1"
Test #10:
score: 0
Accepted
time: 0ms
memory: 3828kb
input:
5 2 0 3 4 5
output:
1
result:
ok 1 number(s): "1"
Test #11:
score: 0
Accepted
time: 1ms
memory: 3628kb
input:
5 0 3 4 0 0
output:
4
result:
ok 1 number(s): "4"
Test #12:
score: 0
Accepted
time: 0ms
memory: 3868kb
input:
5 2 3 0 1 0
output:
1
result:
ok 1 number(s): "1"
Test #13:
score: 0
Accepted
time: 0ms
memory: 3800kb
input:
5 1 0 0 0 4
output:
3
result:
ok 1 number(s): "3"
Test #14:
score: 0
Accepted
time: 1ms
memory: 3572kb
input:
5 0 0 0 3 0
output:
6
result:
ok 1 number(s): "6"
Test #15:
score: 0
Accepted
time: 1ms
memory: 3632kb
input:
5 1 2 4 0 3
output:
1
result:
ok 1 number(s): "1"
Test #16:
score: 0
Accepted
time: 0ms
memory: 3804kb
input:
5 0 0 4 2 5
output:
1
result:
ok 1 number(s): "1"
Test #17:
score: 0
Accepted
time: 0ms
memory: 3836kb
input:
5 1 0 0 0 0
output:
9
result:
ok 1 number(s): "9"
Test #18:
score: 0
Accepted
time: 0ms
memory: 3864kb
input:
5 0 1 0 0 5
output:
3
result:
ok 1 number(s): "3"
Test #19:
score: 0
Accepted
time: 0ms
memory: 3576kb
input:
5 1 2 3 4 0
output:
0
result:
ok 1 number(s): "0"
Test #20:
score: 0
Accepted
time: 1ms
memory: 3860kb
input:
5 3 1 0 0 5
output:
1
result:
ok 1 number(s): "1"
Test #21:
score: 0
Accepted
time: 0ms
memory: 3628kb
input:
5 0 3 0 1 5
output:
1
result:
ok 1 number(s): "1"
Test #22:
score: 0
Accepted
time: 0ms
memory: 3624kb
input:
5 1 0 2 0 0
output:
3
result:
ok 1 number(s): "3"
Test #23:
score: 0
Accepted
time: 0ms
memory: 3836kb
input:
5 0 0 3 4 5
output:
1
result:
ok 1 number(s): "1"
Test #24:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
5 5 1 2 0 0
output:
1
result:
ok 1 number(s): "1"
Test #25:
score: 0
Accepted
time: 1ms
memory: 3868kb
input:
5 0 3 0 1 0
output:
1
result:
ok 1 number(s): "1"
Test #26:
score: 0
Accepted
time: 0ms
memory: 3628kb
input:
5 1 0 0 0 5
output:
4
result:
ok 1 number(s): "4"
Test #27:
score: 0
Accepted
time: 1ms
memory: 3564kb
input:
5 2 1 3 4 0
output:
1
result:
ok 1 number(s): "1"
Test #28:
score: 0
Accepted
time: 0ms
memory: 3600kb
input:
5 0 2 3 0 5
output:
0
result:
ok 1 number(s): "0"
Test #29:
score: 0
Accepted
time: 0ms
memory: 3796kb
input:
5 2 0 0 5 1
output:
1
result:
ok 1 number(s): "1"
Test #30:
score: 0
Accepted
time: 0ms
memory: 3864kb
input:
5 0 1 2 0 4
output:
1
result:
ok 1 number(s): "1"
Test #31:
score: 0
Accepted
time: 0ms
memory: 3860kb
input:
5 1 0 4 2 5
output:
1
result:
ok 1 number(s): "1"
Test #32:
score: 0
Accepted
time: 0ms
memory: 3876kb
input:
5 0 0 2 0 0
output:
6
result:
ok 1 number(s): "6"
Test #33:
score: 0
Accepted
time: 0ms
memory: 3560kb
input:
5 1 2 0 0 5
output:
1
result:
ok 1 number(s): "1"
Test #34:
score: 0
Accepted
time: 0ms
memory: 3564kb
input:
5 1 2 0 4 0
output:
0
result:
ok 1 number(s): "0"
Test #35:
score: 0
Accepted
time: 0ms
memory: 3864kb
input:
5 0 0 3 0 0
output:
2
result:
ok 1 number(s): "2"
Test #36:
score: 0
Accepted
time: 0ms
memory: 3872kb
input:
5 1 0 5 3 4
output:
1
result:
ok 1 number(s): "1"
Test #37:
score: 0
Accepted
time: 1ms
memory: 3632kb
input:
5 0 3 0 0 0
output:
6
result:
ok 1 number(s): "6"
Test #38:
score: 0
Accepted
time: 1ms
memory: 3564kb
input:
5 2 0 0 4 5
output:
2
result:
ok 1 number(s): "2"
Test #39:
score: 0
Accepted
time: 0ms
memory: 3632kb
input:
5 0 0 4 0 5
output:
3
result:
ok 1 number(s): "3"
Test #40:
score: 0
Accepted
time: 0ms
memory: 3800kb
input:
5 5 0 0 3 0
output:
1
result:
ok 1 number(s): "1"
Test #41:
score: 0
Accepted
time: 0ms
memory: 3568kb
input:
5 2 0 0 0 5
output:
3
result:
ok 1 number(s): "3"
Test #42:
score: -100
Wrong Answer
time: 0ms
memory: 3576kb
input:
5 0 3 0 4 0
output:
4
result:
wrong answer 1st numbers differ - expected: '2', found: '4'