QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#577480 | #8781. Element-Wise Comparison | myusername# | TL | 392ms | 921248kb | C++14 | 1.6kb | 2024-09-20 11:48:33 | 2024-09-20 11:48:33 |
Judging History
answer
#include<bitset>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
const int N=50009;
int n,m,p[N],id[N];
bitset<N> b[N],pre[N],suf[N],cur;
int bl[N],L[N],R[N];
bool cmp(const int &a,const int &b){
return p[a]<p[b];
}
void solve(){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++){
scanf("%d",&p[i]),id[i]=i,bl[i]=(i-1)/m+1;
if(!L[bl[i]]) L[bl[i]]=i;
R[bl[i]]=i;
}
sort(id+1,id+1+n,cmp);
for(int i=1;i<=n;i++){
int u=id[i];
b[u]=cur>>u+1;
cur[u]=1;
}
// for(int i=1;i<=n;i++,puts(""))
// for(int d=0;d<n-i;d++) printf("%d ",(int)b[i][d]);
for(int i=1;i<=bl[n];i++){
pre[L[i]]=b[L[i]];
for(int j=L[i]+1;j<=R[i];j++) pre[j]=pre[j-1]|b[j];
suf[R[i]]=b[R[i]];
for(int j=R[i]-1;j>=L[i];j--) suf[j]=suf[j+1]|b[j];
}
LL res=0;
for(int i=1;i<=n-m;i++){
//[i,i+m-1]
//d<=n-m+1-i
//0~n+m-i
if(i==L[bl[i]]) res+=(n-m+1)-i-(suf[i].count()-(suf[i]>>n-m-i+1).count())/* ,printf("(%d,%d,%d)",(n-m+1)-i,suf[i].count(),(suf[i]>>n-m-i+1).count()) */;
else cur=suf[i]|pre[i+m-1],res+=(n-m+1)-i-(cur.count()-(cur>>n-m-i+1).count())/* ,printf("(%d,%d,%d)",(n-m+1)-i,cur.count(),(cur>>n-m-i+1).count()) */;
// printf("%lld ",res);
}
printf("%lld\n",res);
}
int main(){
// freopen("t.in","r",stdin);
// freopen("t.out","w",stdout);
int T=1;
// scanf("%d",&T);
while(T--) solve();
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 8240kb
input:
5 3 5 2 1 3 4
output:
0
result:
ok answer is '0'
Test #2:
score: 0
Accepted
time: 1ms
memory: 8288kb
input:
5 2 3 1 4 2 5
output:
2
result:
ok answer is '2'
Test #3:
score: 0
Accepted
time: 1ms
memory: 7956kb
input:
4 2 1 2 3 4
output:
3
result:
ok answer is '3'
Test #4:
score: 0
Accepted
time: 1ms
memory: 9996kb
input:
4 2 4 3 2 1
output:
0
result:
ok answer is '0'
Test #5:
score: 0
Accepted
time: 1ms
memory: 8256kb
input:
1 1 1
output:
0
result:
ok answer is '0'
Test #6:
score: 0
Accepted
time: 387ms
memory: 921248kb
input:
50000 2 44045 29783 5389 7756 44022 45140 21967 5478 10868 49226 21775 31669 49836 13511 46116 14229 27206 31168 37389 3158 10658 41154 14635 18526 40540 6451 23197 46719 30593 13517 8604 46666 39189 43746 12778 3684 3194 36979 43020 14652 19549 31178 17144 27177 44336 2849 40220 11751 41993 32209 4...
output:
310780127
result:
ok answer is '310780127'
Test #7:
score: 0
Accepted
time: 392ms
memory: 921156kb
input:
50000 2 44015 31580 38779 29675 3269 12273 40322 471 4551 44568 21486 17093 43442 11483 9686 39913 36953 47673 34066 4943 28304 34228 9197 43349 1974 32227 8177 33236 24942 42131 34294 48071 17452 9633 18281 13817 27423 9880 15629 6991 20035 13601 39212 33548 8865 39161 48449 22164 36815 28852 43065...
output:
317708201
result:
ok answer is '317708201'
Test #8:
score: -100
Time Limit Exceeded
input:
50000 2 45828 16955 24033 12988 15675 6086 482 27940 30132 39389 14266 35347 46159 8317 24605 9737 30077 32664 6326 43387 7896 17806 20481 8573 8438 36474 33708 42437 8187 12300 13318 48764 34683 14983 40909 34874 47938 31131 12519 21122 22457 21062 32953 47733 46731 18062 1061 28388 27032 47303 390...
output:
309719539