QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#19074 | #1877. Matryoshka Dolls | wangtaochun | WA | 3ms | 5608kb | C++17 | 642b | 2022-01-27 23:22:17 | 2022-05-06 03:54:05 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD=998244353;
const ll N=500009;
struct num{
ll val,id;
};
num a[N],b[N];
bool cmp(num f,num g){
return f.val<g.val;
}
ll n,m;
void input(){
cin>>n>>m;
for(int i=1;i<=n;i++){cin>>a[i].val; a[i].id=i;}
for(int i=1;i<=n;i++) b[i]=a[i];
}
void solveBF(){
for(int i=1;i<=m;i++){
ll ans=0;
ll c,d;
cin>>c>>d;
sort(b+c,b+d+1,cmp);
for(int j=c;j<=d-1;j++){
ans+=abs(b[j].id-b[j+1].id);
}
cout<<ans<<endl;
}
}
void solve(){
}
int main(){
input();
if(n<=1000&&m<=1000) solveBF();
else solve();
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 3ms
memory: 5608kb
input:
5 5 1 5 2 4 3 1 5 1 4 1 3 1 2 1 1
output:
7 5 4 2 0
result:
wrong answer 3rd numbers differ - expected: '3', found: '4'