QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#201969 | #5150. Alternating Algorithm | salvator_noster# | WA | 1ms | 7788kb | C++20 | 1.3kb | 2023-10-05 17:59:31 | 2023-10-05 17:59:31 |
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 ++) {
if (b[i].second < i) continue;
int backward = b[i].second - i;
int forward = query(b[i].second + 1);
ans = max(forward * 2 + (forward & 1) + 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: 0ms
memory: 7712kb
input:
3 8 13 4 10
output:
3
result:
ok single line: '3'
Test #2:
score: 0
Accepted
time: 1ms
memory: 5904kb
input:
5 13 12 14 10 14 12
output:
3
result:
ok single line: '3'
Test #3:
score: 0
Accepted
time: 1ms
memory: 7704kb
input:
2 2 2 1
output:
3
result:
ok single line: '3'
Test #4:
score: 0
Accepted
time: 0ms
memory: 5732kb
input:
1 300172042 474444146
output:
0
result:
ok single line: '0'
Test #5:
score: 0
Accepted
time: 1ms
memory: 3524kb
input:
1 636357447 557539481
output:
1
result:
ok single line: '1'
Test #6:
score: 0
Accepted
time: 1ms
memory: 5408kb
input:
2 139715426 368724097 417561009
output:
0
result:
ok single line: '0'
Test #7:
score: 0
Accepted
time: 1ms
memory: 7708kb
input:
2 77784868 542697475 509604021
output:
2
result:
ok single line: '2'
Test #8:
score: 0
Accepted
time: 0ms
memory: 3424kb
input:
2 698395658 71848686 699775597
output:
1
result:
ok single line: '1'
Test #9:
score: 0
Accepted
time: 1ms
memory: 7704kb
input:
2 487635147 571273621 442673389
output:
3
result:
ok single line: '3'
Test #10:
score: 0
Accepted
time: 1ms
memory: 5860kb
input:
2 502022170 254766224 258867503
output:
2
result:
ok single line: '2'
Test #11:
score: 0
Accepted
time: 1ms
memory: 5668kb
input:
2 783651505 271735448 154090385
output:
3
result:
ok single line: '3'
Test #12:
score: 0
Accepted
time: 1ms
memory: 5568kb
input:
3 423187900 701340783 708457090 788989478
output:
0
result:
ok single line: '0'
Test #13:
score: 0
Accepted
time: 1ms
memory: 7788kb
input:
3 172068101 507957913 237246316 805323765
output:
2
result:
ok single line: '2'
Test #14:
score: 0
Accepted
time: 1ms
memory: 5564kb
input:
3 309846480 218704879 536482379 754210806
output:
1
result:
ok single line: '1'
Test #15:
score: 0
Accepted
time: 0ms
memory: 7720kb
input:
3 150235215 485036833 52089968 645641645
output:
3
result:
ok single line: '3'
Test #16:
score: 0
Accepted
time: 1ms
memory: 5664kb
input:
3 735389981 669677621 733676260 858050940
output:
2
result:
ok single line: '2'
Test #17:
score: 0
Accepted
time: 1ms
memory: 5664kb
input:
3 635103474 551413670 85269704 730878535
output:
3
result:
ok single line: '3'
Test #18:
score: 0
Accepted
time: 1ms
memory: 5568kb
input:
3 287528440 314452762 846234936 452787633
output:
1
result:
ok single line: '1'
Test #19:
score: 0
Accepted
time: 1ms
memory: 5864kb
input:
3 276069955 969481471 992185356 536479156
output:
2
result:
ok single line: '2'
Test #20:
score: 0
Accepted
time: 0ms
memory: 3440kb
input:
3 225096493 88165689 415816372 360778803
output:
1
result:
ok single line: '1'
Test #21:
score: 0
Accepted
time: 0ms
memory: 7716kb
input:
3 651934487 760368054 975264908 206290402
output:
3
result:
ok single line: '3'
Test #22:
score: 0
Accepted
time: 0ms
memory: 7736kb
input:
3 668819975 16012633 798541220 258404088
output:
2
result:
ok single line: '2'
Test #23:
score: 0
Accepted
time: 1ms
memory: 7736kb
input:
3 303955151 276719749 324951113 63908344
output:
3
result:
ok single line: '3'
Test #24:
score: -100
Wrong Answer
time: 1ms
memory: 7708kb
input:
3 419862649 709195111 424612582 548104611
output:
2
result:
wrong answer 1st lines differ - expected: '3', found: '2'