QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#201219 | #5150. Alternating Algorithm | whsyhyyh# | WA | 4ms | 18328kb | C++14 | 1.2kb | 2023-10-05 13:14:12 | 2023-10-05 13:14:12 |
Judging History
answer
#pragma GCC optimize("Ofast","unroll-loops","omit-frame-pointer","inline")
#pragma GCC option("arch=native","tune=native","no-zero-upper")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2")
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define N 400010
#define rep(i,l,r) for(int i=l;i<=r;i++)
#define drep(i,r,l) for(int i=r;i>=l;i--)
using namespace std;
int rd() {
int res=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9') {if(ch=='-') f*=-1;ch=getchar();}
while(ch>='0'&&ch<='9') res=(res<<1)+(res<<3)+(ch^48),ch=getchar();
return res*f;
}
int n,a[N],b[N],pos[N];
unordered_map<int,int>mp;int tot;
vector<int>G[N];int cnt[N];
int main() {
n=rd()+1;
rep(i,1,n) a[i]=rd(),b[i]=a[i];
sort(b+1,b+n+1);
rep(i,1,n) if(i==1||b[i]!=b[i-1]) mp[b[i]]=++tot;
rep(i,1,n) a[i]=mp[a[i]],G[a[i]].push_back(i),cnt[a[i]]++;
rep(i,1,tot) cnt[i]+=cnt[i-1];
drep(i,n,1) pos[i]=cnt[a[i]]--;
int ans=0;
rep(i,1,n) {
if(pos[i]==i) continue;
if(pos[i]>i) {
ans=max(ans,pos[i]-i+((i&1)==0||((i&1)==1&&a[i+1]>a[i])));
}
else {
ans=max(ans,i-pos[i]+((i&1)==1||((i&1)==0&&a[i-1]<a[i])));
}
// cerr<<"FUCK "<<i<<" "<<pos[i]<<" "<<ans<<endl;
}
printf("%d",ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 4ms
memory: 18036kb
input:
3 8 13 4 10
output:
3
result:
ok single line: '3'
Test #2:
score: 0
Accepted
time: 4ms
memory: 18072kb
input:
5 13 12 14 10 14 12
output:
3
result:
ok single line: '3'
Test #3:
score: 0
Accepted
time: 3ms
memory: 15992kb
input:
2 2 2 1
output:
3
result:
ok single line: '3'
Test #4:
score: 0
Accepted
time: 0ms
memory: 18000kb
input:
1 300172042 474444146
output:
0
result:
ok single line: '0'
Test #5:
score: 0
Accepted
time: 3ms
memory: 16364kb
input:
1 636357447 557539481
output:
1
result:
ok single line: '1'
Test #6:
score: 0
Accepted
time: 3ms
memory: 18044kb
input:
2 139715426 368724097 417561009
output:
0
result:
ok single line: '0'
Test #7:
score: 0
Accepted
time: 3ms
memory: 18044kb
input:
2 77784868 542697475 509604021
output:
2
result:
ok single line: '2'
Test #8:
score: 0
Accepted
time: 3ms
memory: 18128kb
input:
2 698395658 71848686 699775597
output:
1
result:
ok single line: '1'
Test #9:
score: 0
Accepted
time: 0ms
memory: 18040kb
input:
2 487635147 571273621 442673389
output:
3
result:
ok single line: '3'
Test #10:
score: 0
Accepted
time: 0ms
memory: 18108kb
input:
2 502022170 254766224 258867503
output:
2
result:
ok single line: '2'
Test #11:
score: 0
Accepted
time: 0ms
memory: 16348kb
input:
2 783651505 271735448 154090385
output:
3
result:
ok single line: '3'
Test #12:
score: 0
Accepted
time: 0ms
memory: 17996kb
input:
3 423187900 701340783 708457090 788989478
output:
0
result:
ok single line: '0'
Test #13:
score: 0
Accepted
time: 3ms
memory: 18004kb
input:
3 172068101 507957913 237246316 805323765
output:
2
result:
ok single line: '2'
Test #14:
score: 0
Accepted
time: 0ms
memory: 16064kb
input:
3 309846480 218704879 536482379 754210806
output:
1
result:
ok single line: '1'
Test #15:
score: 0
Accepted
time: 3ms
memory: 18136kb
input:
3 150235215 485036833 52089968 645641645
output:
3
result:
ok single line: '3'
Test #16:
score: 0
Accepted
time: 0ms
memory: 18072kb
input:
3 735389981 669677621 733676260 858050940
output:
2
result:
ok single line: '2'
Test #17:
score: 0
Accepted
time: 3ms
memory: 16208kb
input:
3 635103474 551413670 85269704 730878535
output:
3
result:
ok single line: '3'
Test #18:
score: 0
Accepted
time: 0ms
memory: 18292kb
input:
3 287528440 314452762 846234936 452787633
output:
1
result:
ok single line: '1'
Test #19:
score: 0
Accepted
time: 0ms
memory: 18048kb
input:
3 276069955 969481471 992185356 536479156
output:
2
result:
ok single line: '2'
Test #20:
score: 0
Accepted
time: 4ms
memory: 17996kb
input:
3 225096493 88165689 415816372 360778803
output:
1
result:
ok single line: '1'
Test #21:
score: 0
Accepted
time: 0ms
memory: 18296kb
input:
3 651934487 760368054 975264908 206290402
output:
3
result:
ok single line: '3'
Test #22:
score: 0
Accepted
time: 0ms
memory: 17980kb
input:
3 668819975 16012633 798541220 258404088
output:
2
result:
ok single line: '2'
Test #23:
score: 0
Accepted
time: 0ms
memory: 18328kb
input:
3 303955151 276719749 324951113 63908344
output:
3
result:
ok single line: '3'
Test #24:
score: 0
Accepted
time: 3ms
memory: 16288kb
input:
3 419862649 709195111 424612582 548104611
output:
3
result:
ok single line: '3'
Test #25:
score: 0
Accepted
time: 3ms
memory: 18044kb
input:
3 46436854 762650424 543885894 63420906
output:
3
result:
ok single line: '3'
Test #26:
score: 0
Accepted
time: 0ms
memory: 18036kb
input:
3 663885616 817966829 428282021 750799481
output:
3
result:
ok single line: '3'
Test #27:
score: 0
Accepted
time: 0ms
memory: 18276kb
input:
3 453815838 784866392 626401113 33629018
output:
3
result:
ok single line: '3'
Test #28:
score: -100
Wrong Answer
time: 3ms
memory: 18328kb
input:
3 612031283 905623341 296446821 317142883
output:
3
result:
wrong answer 1st lines differ - expected: '4', found: '3'