QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#439946 | #8781. Element-Wise Comparison | as_lyr | WA | 1ms | 8028kb | C++14 | 1.0kb | 2024-06-12 20:59:43 | 2024-06-12 20:59:43 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
const int N=51000;
int n,m;
int a[N];
pair <int,int> p[N];
bitset <N> b[N];
int tp[N],lx[N],rx[N];
bitset <N> l[N],r[N];
int main(){
scanf("%d%d",&n,&m);
for(int i=1;i<=n;i++){
scanf("%d",&a[i]);
p[i]=make_pair(a[i],i);
}
sort(p+1,p+n+1,[](const pair <int,int> x,const pair <int,int> y){
return x.first<y.first;
});
for(int i=1;i<=n;i++){
b[p[i].second]=b[p[i-1].second];
if(i!=1)
b[p[i].second][n-p[i-1].second+1]=1;
}
for(int i=1;i<=n;i++)
b[i]>>=(n-i);
for(int i=1;i<=n;i++)
tp[i]=(i-1)/m+1;
for(int i=n;i;i--)
lx[tp[i]]=i;
for(int i=1;i<=n;i++)
rx[tp[i]]=i;
for(int i=1;i<=tp[n];i++){
l[lx[i]]=b[lx[i]];
for(int j=lx[i]+1;j<=rx[i];j++)
l[j]=l[j-1]&b[j];
r[rx[i]]=b[rx[i]];
for(int j=rx[i]-1;j>=lx[i];j--)
r[j]=r[j+1]&b[j];
}
int ans=0;
for(int i=1;i+m-1<=n;i++){
if(tp[i]==tp[i+m-1])
ans+=(int)(r[i]).count();
else
ans+=(int)(r[i]&l[i+m-1]).count();
}
printf("%d",ans);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 6016kb
input:
5 3 5 2 1 3 4
output:
0
result:
ok answer is '0'
Test #2:
score: 0
Accepted
time: 0ms
memory: 7912kb
input:
5 2 3 1 4 2 5
output:
2
result:
ok answer is '2'
Test #3:
score: 0
Accepted
time: 1ms
memory: 8028kb
input:
4 2 1 2 3 4
output:
3
result:
ok answer is '3'
Test #4:
score: -100
Wrong Answer
time: 1ms
memory: 5924kb
input:
4 2 4 3 2 1
output:
2
result:
wrong answer expected '0', found '2'