QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#18841 | #1877. Matryoshka Dolls | zzy0922 | WA | 23ms | 5744kb | C++ | 750b | 2022-01-27 14:03:55 | 2022-05-06 02:50:35 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
int n, m, a[500005], l, r, c[500005], sum[500005], a_[500005], tmp[500005];
int main() {
//freopen("rrads.in", "r", stdin);
//freopen("rrads.out", "w", stdout);
scanf("%d%d", &n, &m);
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
a_[a[i]] = i;
}
for (int i = 1; i < n; i++) {
c[i] = a_[i + 1] - a_[i];
sum[i + 1] = sum[i] + c[i];
//printf("%d %d\n", i, sum[i]);
}
while (m--) {
scanf("%d%d", &l, &r);
for (int i = l; i <= r; i++) {
tmp[i - l + 1] = a[i];
}
int len = r - l + 1;
sort(tmp + 1, tmp + len + 1);
int ans = 0;
for (int i = 1; i < len; i++) {
ans += abs(sum[tmp[i + 1]] - sum[tmp[i]]);
}
printf("%d\n", ans);
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 3ms
memory: 3784kb
input:
5 5 1 5 2 4 3 1 5 1 4 1 3 1 2 1 1
output:
7 5 3 1 0
result:
ok 5 number(s): "7 5 3 1 0"
Test #2:
score: 0
Accepted
time: 3ms
memory: 3816kb
input:
1 1 1 1 1
output:
0
result:
ok 1 number(s): "0"
Test #3:
score: -100
Wrong Answer
time: 23ms
memory: 5744kb
input:
100000 1 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 86 88 90 92 94 96 98 100 102 104 106 108 110 112 114 116 118 120 122 124 126 128 130 132 134 136 138 140 142 144 146 148 150 152 154 156 158 160 162 164 166 168 170 172 ...
output:
704982704
result:
wrong answer 1st numbers differ - expected: '4999950000', found: '704982704'