QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#19074#1877. Matryoshka DollswangtaochunWA 3ms5608kbC++17642b2022-01-27 23:22:172022-05-06 03:54:05

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2022-05-06 03:54:05]
  • 评测
  • 测评结果:WA
  • 用时:3ms
  • 内存:5608kb
  • [2022-01-27 23:22:17]
  • 提交

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'