QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#201944 | #5150. Alternating Algorithm | salvator_noster# | WA | 1ms | 7856kb | C++20 | 1.3kb | 2023-10-05 17:49:00 | 2023-10-05 17:49:01 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
typedef pair <int, int> pii;
const int MAX_N = 400000 + 5;
int N, a[MAX_N];
pii b[MAX_N];
int c[MAX_N];
void add(int l, int r) {
for (int i = l; i <= N + 1; i += i & -i) c[i] ++;
for (int i = r + 1; i <= N + 1; i += i & -i) c[i] --;
}
int query(int x) {
int res = 0;
for (int i = x; i; i -= i & -i) res += c[i];
return res;
}
bool check() {
for (int i = 0; i < N; i ++)
if (a[i] > a[i + 1]) return true;
return false;
}
void simulate_odd() {
for (int i = 0; i < N; i += 2)
if (a[i] > a[i + 1]) swap(a[i], a[i + 1]);
}
int main() {
scanf("%d", &N);
for (int i = 0; i <= N; i ++) {
scanf("%d", a + i);
}
if (!check()) {
puts("0"); return 0;
}
simulate_odd();
if (!check()) {
puts("1"); return 0;
}
for (int i = 0; i <= N; i ++) {
b[i] = make_pair(a[i], i);
}
sort(b, b + N + 1);
int ans = 0;
for (int i = 0; i <= N; i ++) {
int backward = max(0, b[i].second - i);
int forward = query(b[i].second + 1);
ans = max(forward * 2 + backward, ans);
if (i < b[i].second) add(i + 1, b[i].second + 1);
}
printf("%d\n", ans + 1);
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5804kb
input:
3 8 13 4 10
output:
3
result:
ok single line: '3'
Test #2:
score: 0
Accepted
time: 1ms
memory: 5848kb
input:
5 13 12 14 10 14 12
output:
3
result:
ok single line: '3'
Test #3:
score: 0
Accepted
time: 1ms
memory: 7856kb
input:
2 2 2 1
output:
3
result:
ok single line: '3'
Test #4:
score: 0
Accepted
time: 1ms
memory: 5728kb
input:
1 300172042 474444146
output:
0
result:
ok single line: '0'
Test #5:
score: 0
Accepted
time: 1ms
memory: 5616kb
input:
1 636357447 557539481
output:
1
result:
ok single line: '1'
Test #6:
score: 0
Accepted
time: 1ms
memory: 5808kb
input:
2 139715426 368724097 417561009
output:
0
result:
ok single line: '0'
Test #7:
score: -100
Wrong Answer
time: 1ms
memory: 7856kb
input:
2 77784868 542697475 509604021
output:
3
result:
wrong answer 1st lines differ - expected: '2', found: '3'