QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#509612 | #5719. Perfect Flush | exxqfu | AC ✓ | 23ms | 7256kb | C++14 | 1.5kb | 2024-08-08 16:31:29 | 2024-08-08 16:31:30 |
Judging History
answer
#include <cstdio>
#include <queue>
#include <utility>
#define rep(i, d, u) for(int i = d; i <= u; ++i)
#define dep(i, u, d) for(int i = u; i >= d; --i)
int ured() {
int ch, re = 0;
do {
ch = getchar();
} while(ch < '0' || '9' < ch);
do {
re = re * 10 + (ch ^ '0');
} while('0' <= (ch = getchar()) && ch <= '9');
return re;
}
void uwit(int da) {
int ch[21], cn = 0;
do {
ch[++cn] = da % 10;
} while(da /= 10);
do {
putchar('0' ^ ch[cn]);
} while(--cn);
}
const int _maxn = 200011;
int n, m, x[_maxn], rans[_maxn], hpos, tpos, firs[_maxn], neig[_maxn];
std :: priority_queue<std :: pair<int, int>> lasq, firq;
bool used[_maxn];
int main() {
n = ured(), m = ured();
rep(i, 1, n) {
x[i] = ured();
}
dep(i, n, 1) {
if(!firs[x[i]]) {
lasq . push(std :: make_pair(-i, x[i]));
}
neig[i] = firs[x[i]], firs[x[i]] = i;
}
rep(i, 1, m) {
while(used[lasq . top() . second]) {
lasq . pop();
}
while(tpos < -lasq . top() . first) {
++tpos;
if(firs[x[tpos]] == tpos && !used[x[tpos]]) {
firq . push(std :: make_pair(-x[tpos], tpos));
}
}
while(firq . top() . second <= hpos) {
std :: pair<int, int> tp = firq . top();
firq . pop();
if((firs[-tp . first] = neig[tp . second]) <= tpos) {
firq . push(std :: make_pair(tp . first, neig[tp . second]));
}
}
used[rans[i] = -firq . top() . first] = 1, hpos = firq . top() . second, firq . pop();
}
rep(i, 1, m) {
uwit(rans[i]), putchar(i == m ? '\n' : ' ');
}
return 0;
}
详细
Test #1:
score: 100
Accepted
time: 1ms
memory: 5724kb
input:
6 3 3 2 1 3 1 3
output:
2 1 3
result:
ok single line: '2 1 3'
Test #2:
score: 0
Accepted
time: 0ms
memory: 3580kb
input:
10 5 5 4 3 2 1 4 1 1 5 5
output:
3 2 1 4 5
result:
ok single line: '3 2 1 4 5'
Test #3:
score: 0
Accepted
time: 23ms
memory: 7256kb
input:
200000 100000 29798 79235 44935 20368 15319 34973 11273 40142 82579 68354 79772 77697 59566 18516 50787 76175 25710 47305 87751 59942 49064 26470 38196 44038 38745 39903 71503 18468 59632 23169 10201 26065 62767 44170 37027 69281 7161 62056 7829 13359 80329 68362 59458 6406 80936 96142 56500 57523 1...
output:
29798 11273 40142 68354 79772 18516 25710 47305 59942 26470 38196 38745 39903 71503 10201 26065 62767 44170 7161 62056 7829 13359 68362 6406 56500 57523 6629 21853 21246 52201 56121 2741 29933 72408 96953 849 22024 68285 86159 24582 9177 8756 52266 85993 1699 18069 29470 31014 36759 93564 3053 13483...
result:
ok single line: '29798 11273 40142 68354 79772 ...6 42906 92073 84291 44638 91402'
Test #4:
score: 0
Accepted
time: 17ms
memory: 6012kb
input:
200000 70000 24584 6697 18673 38293 8404 24994 47707 37053 30991 13653 67519 33504 8731 20485 65913 55807 16427 57137 17079 19944 13392 34408 11797 35484 40943 15167 4562 40466 66626 37190 48145 56716 49502 4084 57593 14543 59858 57061 13403 18538 21409 12339 52049 43056 59512 15385 3130 51397 60057...
output:
6697 8404 13653 67519 8731 11797 35484 40943 15167 4084 12339 52049 3130 6322 8767 16015 20527 30616 51550 4523 6094 15289 17316 5595 17825 6206 2156 24377 29414 1700 3930 40882 5301 15760 17893 20597 33362 36891 36937 59629 4205 8729 48006 60002 6479 7071 11817 20748 16682 20275 31641 31645 42991 4...
result:
ok single line: '6697 8404 13653 67519 8731 117...8 33022 60886 53554 21126 54187'
Test #5:
score: 0
Accepted
time: 20ms
memory: 5652kb
input:
200000 30000 28288 14739 16840 24459 27185 7648 12457 26677 18027 17749 10763 23981 17041 18711 14392 24760 26008 29620 15155 24642 21659 16920 12890 19290 18017 18372 3302 14298 27704 5008 9139 18137 16517 11850 18748 4715 8547 4708 26463 721 13280 6742 29409 4183 27656 23846 9410 21791 8684 12844 ...
output:
5 34 163 327 1131 19803 84 103 231 1599 28 56 73 343 346 1794 3756 3 10 218 729 989 1451 3445 13354 27737 50 10580 18884 2 31 33 67 190 375 735 1432 2096 5433 5697 8090 20751 20 238 406 426 1114 3128 5566 14890 21463 8 2418 3340 3892 6432 10728 22173 24235 41 396 760 1871 4666 6197 6895 78 155 193 3...
result:
ok single line: '5 34 163 327 1131 19803 84 103...6 29378 26953 14607 21349 29273'
Test #6:
score: 0
Accepted
time: 3ms
memory: 4084kb
input:
20000 20000 20000 19999 19998 19997 19996 19995 19994 19993 19992 19991 19990 19989 19988 19987 19986 19985 19984 19983 19982 19981 19980 19979 19978 19977 19976 19975 19974 19973 19972 19971 19970 19969 19968 19967 19966 19965 19964 19963 19962 19961 19960 19959 19958 19957 19956 19955 19954 19953 ...
output:
20000 19999 19998 19997 19996 19995 19994 19993 19992 19991 19990 19989 19988 19987 19986 19985 19984 19983 19982 19981 19980 19979 19978 19977 19976 19975 19974 19973 19972 19971 19970 19969 19968 19967 19966 19965 19964 19963 19962 19961 19960 19959 19958 19957 19956 19955 19954 19953 19952 19951 ...
result:
ok single line: '20000 19999 19998 19997 19996 ...4 13 12 11 10 9 8 7 6 5 4 3 2 1'
Test #7:
score: 0
Accepted
time: 0ms
memory: 5924kb
input:
20000 10000 10000 9999 9998 9997 9996 9995 9994 9993 9992 9991 9990 9989 9988 9987 9986 9985 9984 9983 9982 9981 9980 9979 9978 9977 9976 9975 9974 9973 9972 9971 9970 9969 9968 9967 9966 9965 9964 9963 9962 9961 9960 9959 9958 9957 9956 9955 9954 9953 9952 9951 9950 9949 9948 9947 9946 9945 9944 99...
output:
10000 9999 9997 9996 9995 9989 9987 9984 9983 9982 9974 9973 9969 9967 9965 9964 9962 9958 9956 9953 9951 9949 9945 9944 9941 9940 9936 9935 9934 9928 9925 9924 9922 9920 9913 9910 9909 9904 9902 9901 9898 9891 9889 9884 9881 9879 9873 9866 9864 9861 9860 9857 9856 9853 9848 9843 9842 9839 9838 9837...
result:
ok single line: '10000 9999 9997 9996 9995 9989...0 8780 6890 9482 6299 1634 6604'