QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#139646 | #5405. 爬楼梯 | 1kri# | 0 | 1ms | 3904kb | C++14 | 816b | 2023-08-14 08:52:55 | 2024-07-04 01:41:39 |
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=1;i<=len;i++)ans+=2*c[i];
for (int i=1;i<mid;i++)ans-=4*c[i];
ans-=min(c[mid]+c[mid+1],3*c[mid]-c[mid-1]);
}
else{
int mid=len/2;
for (int i=1;i<=len;i++)ans+=2*c[i];
for (int i=1;i<=mid;i++)ans-=4*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: 5
Accepted
time: 1ms
memory: 3776kb
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:
711577793 1530795597 783685407 1099707620 3625910517 135569108 347631122 3919843439 3442003862 783685407
result:
ok 10 numbers
Test #2:
score: -5
Wrong Answer
time: 1ms
memory: 3904kb
input:
10 10 356685563 915148434 563845435 480227923 510014130 571548808 489307692 666691543 573877683 800166552 5 8 1 4 1 10 3 10 1 7 3 8 5 8 5 6 5 6 2 4
output:
416302380 1200543254 6541968477 5425042735 1427936560 591240777 416302380 61534678 61534678 786223510
result:
wrong answer 3rd numbers differ - expected: '2247001181', found: '6541968477'
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:
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%