QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#116780 | #5150. Alternating Algorithm | batrr# | WA | 8ms | 37832kb | C++23 | 3.7kb | 2023-06-30 04:07:46 | 2023-06-30 04:07:46 |
Judging History
answer
#include <bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
const int N = 400500, inf = 1e9, mod = 998244353;
const ll INF = 1e18;
int sum(int a, int b) {
a += b;
if (a >= mod)
a -= mod;
return a;
}
int sub(int a, int b) {
a -= b;
if (a < 0)
a += mod;
return a;
}
int mult(int a, int b) {
return 1ll * a * b % mod;
}
int bp(int a, int b) {
int res = 1;
while (b) {
if (b & 1)
res = mult(res, a);
a = mult(a, a);
b >>= 1;
}
return res;
}
int inv(int x) {
return bp(x, mod - 2);
}
int n, a[N];
int p[N];
int ans;
struct state{
bool emp;
int len, s;
int mx[2];
state(){
emp = true;
}
state(int pos, int val){
emp = false;
len = 1;
s = 0;
for(int i = 0; i < 2; i++)
mx[i] = -inf;
if(val == 0)
val = -2;
else
val = 1;
if(val == -2)
mx[pos & 1] = max(mx[pos & 1], val);
s += val;
}
int calc(){
int res = -inf;
res = max(res, mx[0] + 1);
res = max(res, mx[1]);
return res;
}
} t[N << 2];
state kek(state a, state b){
if(a.emp)
return b;
if(b.emp)
return a;
state c;
c.emp = false;
c.len = a.len + b.len;
c.s = a.s + b.s;
for(int i = 0; i < 2; i++)
c.mx[i] = max(a.mx[i], b.mx[i] + a.s);
return c;
}
void build(int v, int tl, int tr) {
if (tl == tr) {
t[v] = state(tl, 1);
return;
}
int tm = (tl + tr) >> 1;
build(v << 1, tl, tm);
build(v << 1 | 1, tm + 1, tr);
t[v] = kek(t[v << 1], t[v << 1 | 1]);
}
state get(int v, int tl, int tr, int l, int r) {
if (r < tl || tr < l || l > r)
return state();
if (l <= tl && tr <= r)
return t[v];
int tm = (tl + tr) >> 1;
return kek(get(v << 1, tl, tm, l, r), get(v << 1 | 1, tm + 1, tr, l, r));
}
void upd(int v, int tl, int tr, int p) {
if (tl == tr) {
t[v] = state(tl, 0);
return;
}
int tm = (tl + tr) >> 1;
if (p <= tm)
upd(v << 1, tl, tm, p);
else
upd(v << 1 | 1, tm + 1, tr, p);
t[v] = kek(t[v << 1], t[v << 1 | 1]);
}
void solve() {
cin >> n;
n++;
for (int i = 0; i < n; i++)
cin >> a[i];
iota(p, p + n, 0);
sort(p, p + n, [](int i, int j) {
return a[i] < a[j];
});
set<int> st0, st1;
for (int i = 0; i < n; i++)
st1.insert(i);
build(1, 0, n - 1);
for (int i = 0, j = 0; i < n; i = j) {
while (j < n && a[p[i]] == a[p[j]])
j++;
for (int q = i; q < j; q++) {
st1.erase(p[q]);
st0.insert(p[q]);
upd(1, 0, n - 1, p[q]);
}
if (st1.empty())
break;
int L = *st1.begin();
int R = *st0.rbegin();
if(L <= R) {
auto res = get(1, 0, n - 1, L, R);
ans = max(ans, res.calc() + (int) st0.size() - L + 1);
}// cerr << res.calc() << " " << (int)st0.size() - L << endl;
// cerr << res.len << " " << res.s << " " << res.mx[0] << " " << res.mx[1] << endl;
}
cout << ans << "\n";
}
int main() {
#ifdef DEBUG
freopen("input.txt", "r", stdin);
#endif
ios_base::sync_with_stdio(false);
int t = 1;
// cin >> t;
for (int i = 1; i <= t; i++) {
// cout << "Case #" << i << endl;
solve();
}
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 36936kb
input:
3 8 13 4 10
output:
3
result:
ok single line: '3'
Test #2:
score: 0
Accepted
time: 4ms
memory: 36480kb
input:
5 13 12 14 10 14 12
output:
3
result:
ok single line: '3'
Test #3:
score: 0
Accepted
time: 1ms
memory: 37788kb
input:
2 2 2 1
output:
3
result:
ok single line: '3'
Test #4:
score: 0
Accepted
time: 0ms
memory: 35976kb
input:
1 300172042 474444146
output:
0
result:
ok single line: '0'
Test #5:
score: 0
Accepted
time: 1ms
memory: 35984kb
input:
1 636357447 557539481
output:
1
result:
ok single line: '1'
Test #6:
score: 0
Accepted
time: 4ms
memory: 37792kb
input:
2 139715426 368724097 417561009
output:
0
result:
ok single line: '0'
Test #7:
score: 0
Accepted
time: 1ms
memory: 36876kb
input:
2 77784868 542697475 509604021
output:
2
result:
ok single line: '2'
Test #8:
score: 0
Accepted
time: 0ms
memory: 36840kb
input:
2 698395658 71848686 699775597
output:
1
result:
ok single line: '1'
Test #9:
score: 0
Accepted
time: 1ms
memory: 36604kb
input:
2 487635147 571273621 442673389
output:
3
result:
ok single line: '3'
Test #10:
score: 0
Accepted
time: 1ms
memory: 37524kb
input:
2 502022170 254766224 258867503
output:
2
result:
ok single line: '2'
Test #11:
score: 0
Accepted
time: 0ms
memory: 37300kb
input:
2 783651505 271735448 154090385
output:
3
result:
ok single line: '3'
Test #12:
score: 0
Accepted
time: 0ms
memory: 37480kb
input:
3 423187900 701340783 708457090 788989478
output:
0
result:
ok single line: '0'
Test #13:
score: 0
Accepted
time: 7ms
memory: 37832kb
input:
3 172068101 507957913 237246316 805323765
output:
2
result:
ok single line: '2'
Test #14:
score: 0
Accepted
time: 1ms
memory: 37572kb
input:
3 309846480 218704879 536482379 754210806
output:
1
result:
ok single line: '1'
Test #15:
score: 0
Accepted
time: 3ms
memory: 36992kb
input:
3 150235215 485036833 52089968 645641645
output:
3
result:
ok single line: '3'
Test #16:
score: 0
Accepted
time: 3ms
memory: 37396kb
input:
3 735389981 669677621 733676260 858050940
output:
2
result:
ok single line: '2'
Test #17:
score: 0
Accepted
time: 0ms
memory: 37056kb
input:
3 635103474 551413670 85269704 730878535
output:
3
result:
ok single line: '3'
Test #18:
score: 0
Accepted
time: 1ms
memory: 37316kb
input:
3 287528440 314452762 846234936 452787633
output:
1
result:
ok single line: '1'
Test #19:
score: 0
Accepted
time: 0ms
memory: 37552kb
input:
3 276069955 969481471 992185356 536479156
output:
2
result:
ok single line: '2'
Test #20:
score: 0
Accepted
time: 7ms
memory: 37216kb
input:
3 225096493 88165689 415816372 360778803
output:
1
result:
ok single line: '1'
Test #21:
score: 0
Accepted
time: 1ms
memory: 36864kb
input:
3 651934487 760368054 975264908 206290402
output:
3
result:
ok single line: '3'
Test #22:
score: 0
Accepted
time: 1ms
memory: 36576kb
input:
3 668819975 16012633 798541220 258404088
output:
2
result:
ok single line: '2'
Test #23:
score: 0
Accepted
time: 7ms
memory: 35876kb
input:
3 303955151 276719749 324951113 63908344
output:
3
result:
ok single line: '3'
Test #24:
score: 0
Accepted
time: 1ms
memory: 36512kb
input:
3 419862649 709195111 424612582 548104611
output:
3
result:
ok single line: '3'
Test #25:
score: 0
Accepted
time: 7ms
memory: 36920kb
input:
3 46436854 762650424 543885894 63420906
output:
3
result:
ok single line: '3'
Test #26:
score: 0
Accepted
time: 1ms
memory: 35780kb
input:
3 663885616 817966829 428282021 750799481
output:
3
result:
ok single line: '3'
Test #27:
score: 0
Accepted
time: 1ms
memory: 36300kb
input:
3 453815838 784866392 626401113 33629018
output:
3
result:
ok single line: '3'
Test #28:
score: 0
Accepted
time: 7ms
memory: 37572kb
input:
3 612031283 905623341 296446821 317142883
output:
4
result:
ok single line: '4'
Test #29:
score: 0
Accepted
time: 3ms
memory: 35936kb
input:
3 690093550 720639503 493410469 329723725
output:
4
result:
ok single line: '4'
Test #30:
score: 0
Accepted
time: 0ms
memory: 36684kb
input:
3 640270086 11003869 302770972 380428351
output:
3
result:
ok single line: '3'
Test #31:
score: 0
Accepted
time: 1ms
memory: 37132kb
input:
3 813904638 53916473 202342438 178710524
output:
3
result:
ok single line: '3'
Test #32:
score: 0
Accepted
time: 7ms
memory: 35920kb
input:
3 858480562 107901831 70069694 624943715
output:
3
result:
ok single line: '3'
Test #33:
score: 0
Accepted
time: 1ms
memory: 36936kb
input:
3 972814426 208602080 487914166 199127689
output:
3
result:
ok single line: '3'
Test #34:
score: 0
Accepted
time: 1ms
memory: 37788kb
input:
3 527326624 369552716 30514207 190802344
output:
4
result:
ok single line: '4'
Test #35:
score: 0
Accepted
time: 1ms
memory: 37824kb
input:
3 885560774 510753464 330831417 122397162
output:
4
result:
ok single line: '4'
Test #36:
score: 0
Accepted
time: 1ms
memory: 36860kb
input:
1 0 0
output:
0
result:
ok single line: '0'
Test #37:
score: 0
Accepted
time: 1ms
memory: 35912kb
input:
1 1 0
output:
1
result:
ok single line: '1'
Test #38:
score: 0
Accepted
time: 1ms
memory: 35888kb
input:
1 0 1
output:
0
result:
ok single line: '0'
Test #39:
score: 0
Accepted
time: 1ms
memory: 37408kb
input:
1 1000000000 0
output:
1
result:
ok single line: '1'
Test #40:
score: 0
Accepted
time: 1ms
memory: 37300kb
input:
5 870923667 831419329 551216223 626357192 564992248 642950852
output:
6
result:
ok single line: '6'
Test #41:
score: 0
Accepted
time: 1ms
memory: 37008kb
input:
5 436264160 745635157 20618089 707614372 862629566 987729003
output:
3
result:
ok single line: '3'
Test #42:
score: 0
Accepted
time: 8ms
memory: 37352kb
input:
5 112182501 364650582 622093010 819594012 467586768 328068426
output:
4
result:
ok single line: '4'
Test #43:
score: 0
Accepted
time: 1ms
memory: 36356kb
input:
6 440802446 672072796 870079224 289645602 358794408 131990964 936527350
output:
5
result:
ok single line: '5'
Test #44:
score: 0
Accepted
time: 7ms
memory: 37528kb
input:
6 624312076 675425489 51650975 686013685 309942426 127494361 289215201
output:
6
result:
ok single line: '6'
Test #45:
score: 0
Accepted
time: 1ms
memory: 36048kb
input:
7 406067722 563548194 1821761 121198244 605039142 435891339 752521249 231257069
output:
5
result:
ok single line: '5'
Test #46:
score: 0
Accepted
time: 1ms
memory: 37528kb
input:
8 903342821 163731172 682809514 389316549 725357000 720997713 96340788 793801888 869342849
output:
8
result:
ok single line: '8'
Test #47:
score: 0
Accepted
time: 1ms
memory: 36660kb
input:
9 363831817 704177455 355821226 562295495 935390976 836136856 341398270 776676829 529678510 52558572
output:
9
result:
ok single line: '9'
Test #48:
score: 0
Accepted
time: 3ms
memory: 35920kb
input:
10 246145909 225986170 30947233 986106325 383647644 975836729 294340164 499272928 869685867 565345319 614315474
output:
8
result:
ok single line: '8'
Test #49:
score: -100
Wrong Answer
time: 1ms
memory: 36636kb
input:
1000 231332114 230630192 351420646 113555257 459531950 528889159 722843423 767109901 199940885 361818296 601674519 520787125 373984526 131582326 735571682 913614536 427646918 492788875 885493950 729293776 86866411 301642177 596103707 286017188 404978221 99164884 557969075 824451476 786229179 6568911...
output:
987
result:
wrong answer 1st lines differ - expected: '988', found: '987'