ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#212176 | #3816. 元素 | Panjunnan | 0 | 166ms | 1328kb | C++11 | 1.0kb | 2024-10-13 11:50:11 | 2024-10-13 12:29:59 |
answer
#include <iostream>
#include <vector>
#include <unordered_set>
#include <algorithm>
using namespace std;
const int MAXN = 100005;
int a[MAXN];
int first[MAXN]; // 存储每个数字首次出现的索引
int last[MAXN]; // 存储每个数字最后一次出现的索引
unordered_set<int> elements; // 存储当前区间内出现过的元素
int main() {
int n, q;
cin >> n >> q;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
first[a[i]] = i;
last[a[i]] = i;
}
while (q--) {
int l, r;
cin >> l >> r;
elements.clear();
int maxR = 0, minL = r + 1;
for (int i = l; i <= r; ++i) {
elements.insert(a[i]);
last[a[i]] = i;
}
for (int num : elements) {
int curL = first[num];
int curR = last[num];
if (curL > maxR) maxR = curL;
if (curR < minL) minL = curR;
}
cout << minL - maxR + 1 << endl;
}
return 0;
}
详细
小提示:点击横条可展开更详细的信息
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 1264kb
input:
10 10 492 1887 1028 1209 252 1860 1527 699 1656 928 6 9 2 8 3 10 2 3 1 8 6 9 3 5 4 7 1 4 2 7
output:
-2 -5 -6 0 -6 -2 -1 -2 -2 -4
result:
wrong answer 1st numbers differ - expected: '4', found: '-2'
Test #2:
score: 0
Wrong Answer
time: 0ms
memory: 1276kb
input:
50 50 413 1208 1780 279 1403 1706 11 1583 333 355 1068 1270 1835 1042 957 423 1140 1153 1709 284 281...
output:
-8 -13 -32 -17 -1 -22 -14 -24 -45 -13 -23 -8 -6 -9 -4 -4 -22 0 -29 -3 -12 -3 1 -9 -8 -12 -19 -11 -24...
result:
wrong answer 1st numbers differ - expected: '10', found: '-8'
Test #3:
score: 0
Wrong Answer
time: 0ms
memory: 1272kb
input:
50 50 407 1089 1459 1626 1917 555 1611 492 443 1149 406 1259 1729 1554 577 1310 1899 1578 1005 1459 ...
output:
-42 -35 -1 -37 1 -24 1 -35 -14 -47 -25 -40 -43 -19 -35 -16 0 0 -23 1 -10 -13 -21 -33 -33 -4 -39 -26 ...
result:
wrong answer 1st numbers differ - expected: '32', found: '-42'
Test #4:
score: 0
Wrong Answer
time: 0ms
memory: 1272kb
input:
50 50 1792 843 1272 547 698 1086 1174 1607 1277 1055 506 881 1445 372 1076 1770 647 1086 320 1912 18...
output:
-32 -17 -36 -19 -3 -7 -45 -39 -7 -10 -4 -33 -36 -17 -8 -21 -24 -46 -7 -23 -2 -25 1 -17 -45 -3 -14 -1...
result:
wrong answer 1st numbers differ - expected: '34', found: '-32'
Test #5:
score: 0
Wrong Answer
time: 0ms
memory: 1272kb
input:
50 50 44 1463 245 1177 1728 1335 768 475 790 623 1466 98 672 230 339 1428 872 1905 405 1260 1503 813...
output:
-17 -23 1 -18 -8 -11 -44 -39 -29 1 -22 -22 -4 -9 -2 -1 -17 -39 -5 -18 -34 -15 -17 0 0 -1 -2 -31 -17 ...
result:
wrong answer 1st numbers differ - expected: '19', found: '-17'
Test #6:
score: 0
Wrong Answer
time: 0ms
memory: 1272kb
input:
50 50 695 974 1078 231 500 498 1308 1666 1925 766 1994 1776 1955 1766 1191 1021 1581 1202 615 1230 1...
output:
-9 -1 -13 -41 -22 -8 -44 -3 -10 -26 -28 -3 -34 -15 -20 -12 -12 -6 -33 -2 -16 -41 0 -5 -26 -3 -22 -9 ...
result:
wrong answer 1st numbers differ - expected: '11', found: '-9'
Test #7:
score: 0
Wrong Answer
time: 0ms
memory: 1272kb
input:
200 200 403 329 389 1103 695 1865 818 671 750 1868 1422 422 1186 1431 172 1569 460 1580 406 1049 138...
output:
-132 -128 -18 -58 -84 -127 -167 -112 -135 -132 -118 -147 -115 -162 -137 -78 -150 -78 -13 -126 -155 -...
result:
wrong answer 1st numbers differ - expected: '131', found: '-132'
Test #8:
score: 0
Wrong Answer
time: 0ms
memory: 1272kb
input:
200 200 147 1386 1788 1493 1919 1136 861 871 1895 1006 1776 346 381 1666 296 289 568 1616 1535 531 2...
output:
-104 -94 -190 -159 0 -30 -116 -188 -187 -151 -9 -65 0 -102 0 -119 -171 -6 -30 -122 -20 -158 -183 -10...
result:
wrong answer 1st numbers differ - expected: '103', found: '-104'
Test #9:
score: 0
Wrong Answer
time: 83ms
memory: 1328kb
input:
2000 2000 1154 852 1088 1530 639 1318 1250 1222 1341 1070 205 656 903 1491 808 317 756 1962 102 1445...
output:
-1748 -444 -1319 -1848 -1243 -1883 -1972 -1858 -1964 -1518 -1392 -1887 -1496 -955 -1713 -1990 -1508 ...
result:
wrong answer 1st numbers differ - expected: '830', found: '-1748'
Test #10:
score: 0
Wrong Answer
time: 83ms
memory: 1328kb
input:
2000 2000 1232 731 1651 991 1681 1739 776 240 829 1337 493 248 214 1852 716 325 1280 1207 380 724 11...
output:
-1406 -1737 -1969 -1786 -946 -1549 -1204 -1602 -1248 -667 -1412 -502 -749 -1661 -1752 -1438 -1722 -9...
result:
wrong answer 1st numbers differ - expected: '1062', found: '-1406'