QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#139642 | #5405. 爬楼梯 | 1kri# | 0 | 1ms | 3784kb | C++14 | 819b | 2023-08-14 08:50:53 | 2024-07-04 01:41:38 |
answer
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#define ll long long
using namespace std;
int n,m;
int a[200005];
int l,r;
int len,c[200005];
ll work(){
ll ans=0;
sort(c+1,c+1+len);
if (len&1){
int mid=(len+1)/2;
for (int i=mid;i<=len;i++)ans+=2*c[i];
for (int i=1;i<mid;i++)ans-=2*c[i];
ans-=(c[mid]+c[mid+1],3*c[mid]-c[mid-1]);
}
else{
int mid=len/2;
for (int i=mid+1;i<=len;i++)ans+=2*c[i];
for (int i=1;i<=mid;i++)ans-=2*c[i];
ans-=c[mid+1];
ans+=c[mid];
}
return ans;
}
int main(){
scanf("%d%d",&n,&m);
for (int i=1;i<=n;i++)scanf("%d",&a[i]);
while(m--){
scanf("%d%d",&l,&r);
len=0;
for (int i=l;i<=r;i++)c[++len]=a[i];
sort(c+1,c+1+len);
ll ans=0;
ans+=work();
printf("%lld\n",ans);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 1ms
memory: 3784kb
input:
10 10 323351358 540774025 513831404 171513818 162079008 234580967 887182642 765979034 329924749 677555871 2 4 1 6 8 10 2 5 1 9 4 6 9 10 2 10 1 8 8 10
output:
396202828 1530795597 524477448 1099707620 3625910517 135569108 347631122 3762879405 3442003862 524477448
result:
wrong answer 1st numbers differ - expected: '711577793', found: '396202828'
Subtask #2:
score: 0
Time Limit Exceeded
Test #11:
score: 0
Time Limit Exceeded
input:
200000 200000 1 2 1 2 1 1 1 2 2 1 1 1 1 1 1 1 1 2 1 1 1 1 2 1 2 1 1 1 1 1 2 2 1 1 1 1 1 1 2 2 2 1 1 2 2 1 2 1 2 1 2 1 1 1 1 1 1 2 1 1 2 1 1 1 1 2 1 2 1 2 2 1 1 2 1 1 1 2 1 1 2 1 2 1 1 1 2 1 2 2 2 2 1 2 2 1 1 2 2 1 2 2 1 1 1 1 2 2 2 1 1 1 1 1 2 2 1 1 1 1 2 1 2 1 2 2 2 2 1 1 2 1 2 1 1 2 1 2 2 2 1 1 1 ...
output:
17766 92870 56732 16462 79590 3872 79674 3370 151158 52672 41424 27644 52872 33690 47896 76136 59296 75972 113274 89092 114330 48490 24112 6810 164898 10914 9738 3316 33638 1510 16344 10722 89260 87924 12710 11498 464 61810 9336 100798 59812 170450 7374 78296 10230 173826 56696 106278 7504 141524 52...
result:
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Skipped
Dependency #1:
0%
Subtask #5:
score: 0
Skipped
Dependency #1:
0%