QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#287583 | #7960. 排序大师 | Crysfly | AC ✓ | 3ms | 7848kb | C++17 | 1.6kb | 2023-12-20 19:33:46 | 2023-12-20 19:33:46 |
Judging History
answer
// what is matter? never mind.
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,sse4,popcnt,abm,mmx,avx,avx2")
#include<bits/stdc++.h>
#define For(i,a,b) for(int i=(a);i<=(b);++i)
#define Rep(i,a,b) for(int i=(a);i>=(b);--i)
#define ll long long
//#define int long long
#define ull unsigned long long
using namespace std;
inline int read()
{
char c=getchar();int x=0;bool f=0;
for(;!isdigit(c);c=getchar())f^=!(c^45);
for(;isdigit(c);c=getchar())x=(x<<1)+(x<<3)+(c^48);
if(f)x=-x;return x;
}
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
typedef pair<int,int>pii;
typedef vector<int>vi;
#define maxn 500005
#define inf 0x3f3f3f3f
int n;
int pos[maxn],a[maxn];
vector<array<int,4>>arr;
int t[maxn],m;
void op(int a,int b,int c,int d){
m=0;
For(i,1,a-1)t[++m]=::a[i];
For(i,c,d)t[++m]=::a[i];
For(i,b+1,c-1)t[++m]=::a[i];
For(i,a,b)t[++m]=::a[i];
For(i,d+1,n)t[++m]=::a[i];
For(i,1,n)::a[i]=t[i],pos[::a[i]]=i;
arr.pb({a,b,c,d});
}
bool chk(){
For(i,1,n)if(a[i]!=i)return 0;
return 1;
}
signed main()
{
n=read();
For(i,1,n)a[i]=read(); a[n+1]=n+1;
while(!chk()){
For(i,1,n+1) pos[a[i]]=i;
For(i,1,n)
if(a[i]!=i){
bool ok=0;
For(j,i,pos[i]-1){
int x=pos[a[j]+1];
if(x>pos[i]){
ok=1;
op(i,j,pos[i],x-1);
break;
}
}
// if(!ok) continue;
assert(ok);
break;
}
}
cout<<arr.size()<<"\n";
for(auto [a,b,c,d]:arr)cout<<a<<" "<<b<<" "<<c<<" "<<d<<"\n";
return 0;
}
/*
*/
詳細信息
Test #1:
score: 100
Accepted
time: 1ms
memory: 5680kb
input:
1 1
output:
0
result:
ok orz U R the sorting master!
Test #2:
score: 0
Accepted
time: 3ms
memory: 7772kb
input:
1970 1452 1799 174 371 132 637 23 1510 1819 1794 1665 450 1183 564 1305 548 554 1310 701 1454 1843 1498 1040 1678 77 614 1928 1761 1718 1637 1853 1026 1804 1062 805 864 1859 586 663 346 335 681 152 1768 1639 1713 856 1401 1833 1350 1842 558 241 1829 802 581 1958 845 722 239 1793 1118 1251 1892 1949 ...
output:
981 1 3 394 418 2 3 999 1008 3 3 199 526 4 4 1758 1862 5 7 1066 1119 6 102 1926 1936 7 146 1957 1969 8 8 447 1658 9 9 325 1039 10 10 160 839 11 20 1834 1920 12 13 696 1512 13 14 407 1255 14 19 1466 1821 15 18 1344 1549 16 16 123 876 17 18 1470 1507 18 18 230 247 19 26 1564 1716 20 20 175 1883 21 21 ...
result:
ok orz U R the sorting master!
Test #3:
score: 0
Accepted
time: 3ms
memory: 7768kb
input:
1983 1002 653 275 1324 1618 1893 1085 342 1858 355 1084 753 910 1417 841 1640 1620 613 311 456 225 51 1316 279 61 1261 68 870 320 147 148 959 49 1862 347 1765 880 293 746 849 488 233 1500 1825 22 547 1363 1034 136 151 1378 1756 1579 1957 647 336 1621 1543 637 214 1717 1871 1339 1732 975 565 919 424 ...
output:
988 1 2 844 1963 2 5 1245 1882 3 10 1665 1677 4 4 844 1691 5 6 1270 1479 6 89 1927 1928 7 8 976 1271 8 8 940 1614 9 9 289 1884 10 10 871 1607 11 11 1004 1165 12 12 30 1366 13 14 358 865 14 14 1229 1567 15 15 146 1546 16 16 801 820 17 19 1741 1773 18 18 448 1056 19 19 1013 1536 20 20 1130 1693 21 21 ...
result:
ok orz U R the sorting master!
Test #4:
score: 0
Accepted
time: 2ms
memory: 7828kb
input:
1967 172 148 690 1375 213 280 435 1727 1442 1579 1876 1455 1341 563 523 456 1712 312 1425 1890 616 1353 391 1957 1755 1155 1481 1402 532 1677 1328 1195 1940 156 188 965 937 1589 1429 1051 1025 1631 983 400 1029 1157 839 1594 1816 1911 46 609 1 1446 709 310 1706 410 1800 1725 124 199 529 131 1628 154...
output:
981 1 1 53 625 2 34 1775 1954 3 4 1126 1468 4 4 839 1534 5 7 813 1625 6 9 1385 1770 7 8 395 1180 8 12 1196 1901 9 10 629 636 10 16 1429 1436 11 11 1054 1448 12 12 615 1825 13 26 1523 1693 14 14 739 953 15 17 1834 1852 16 16 1612 1768 17 45 1753 1846 18 18 1648 1802 19 19 733 1840 20 22 686 879 21 23...
result:
ok orz U R the sorting master!
Test #5:
score: 0
Accepted
time: 0ms
memory: 7772kb
input:
1961 1 2 3 4 5 6 7 8 9 10 11 12 13 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 ...
output:
1 14 283 506 1204
result:
ok orz U R the sorting master!
Test #6:
score: 0
Accepted
time: 1ms
memory: 7668kb
input:
1979 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101...
output:
5 169 248 687 1815 221 643 1390 1976 266 347 1368 1542 376 397 1021 1130 456 536 644 712
result:
ok orz U R the sorting master!
Test #7:
score: 0
Accepted
time: 0ms
memory: 7740kb
input:
1971 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 162 163 164 165 166 167 168 169 170 171 172 17...
output:
20 87 102 633 1000 122 134 945 1093 230 264 1192 1902 241 320 776 1927 264 371 1520 1965 299 324 1633 1782 334 633 1597 1848 343 754 1439 1481 386 386 697 1476 415 1463 1782 1882 455 550 691 1604 552 614 675 1475 642 648 1144 1303 724 849 1096 1765 733 798 1304 1440 758 789 953 993 840 1083 1096 180...
result:
ok orz U R the sorting master!
Test #8:
score: 0
Accepted
time: 1ms
memory: 7744kb
input:
1971 1 2 3 4 5 6 7 8 9 712 1843 131 132 1556 1557 1558 1559 1742 1743 1744 1745 1746 1747 1748 613 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 202 203 204 1767...
output:
100 10 11 1173 1463 12 16 1070 1621 17 18 1200 1934 18 32 1324 1593 23 34 351 779 25 30 782 1218 26 32 905 1030 37 48 1400 1527 42 61 1305 1779 53 67 664 1313 55 56 669 1333 63 63 1357 1679 68 70 647 793 77 95 772 1395 84 97 513 973 86 102 195 1499 93 95 892 1040 107 119 1137 1440 109 109 1021 1604 ...
result:
ok orz U R the sorting master!
Test #9:
score: 0
Accepted
time: 2ms
memory: 7848kb
input:
1973 1470 1471 1472 1473 1266 1959 1648 1649 1337 498 1080 875 1810 775 1448 1111 1112 1260 212 588 589 1128 51 1381 1442 700 701 660 1339 1850 1892 1893 905 1287 628 629 630 650 1262 1263 835 505 506 1773 173 98 1758 627 1677 1808 1809 1585 236 237 1458 1459 1460 1461 1907 1908 1909 1125 1474 37 19...
output:
500 1 5 159 286 5 7 337 1007 6 7 909 1113 7 14 1871 1892 8 10 1253 1536 9 12 856 1833 10 26 1686 1778 12 12 1370 1460 14 22 1219 1521 16 16 1058 1405 17 24 1212 1266 18 19 488 1380 19 22 650 1404 20 20 810 980 21 21 504 751 22 22 1103 1448 24 24 276 759 26 26 705 885 27 33 1516 1576 28 30 566 1025 2...
result:
ok orz U R the sorting master!
Test #10:
score: 0
Accepted
time: 0ms
memory: 7764kb
input:
1959 1 1009 1010 1461 171 1629 1761 1507 1508 1509 1621 992 1901 1154 841 736 737 738 333 1274 1652 1653 452 881 882 541 1247 1177 1662 965 966 1192 1193 1339 1831 1832 1031 1032 1928 105 1634 820 423 1103 1893 1894 163 1759 552 805 555 166 1199 1725 1463 23 1696 464 1787 1254 1655 1656 745 746 1388...
output:
824 2 4 409 1184 3 3 291 730 5 5 1264 1539 6 6 280 373 7 7 509 1885 8 9 1596 1675 9 19 1747 1893 11 15 1267 1924 12 12 850 1310 13 21 1754 1845 14 17 1711 1732 16 16 1400 1818 17 17 310 379 19 19 1021 1463 20 20 881 1528 21 48 1759 1767 22 26 1562 1674 23 25 1433 1804 24 51 1821 1893 25 26 1478 1723...
result:
ok orz U R the sorting master!
Test #11:
score: 0
Accepted
time: 2ms
memory: 5732kb
input:
1966 1070 1605 424 264 1500 626 999 836 794 972 233 136 1256 1591 1271 417 678 235 854 1632 152 1895 257 258 469 1796 1811 1962 1207 934 1857 1089 1090 642 414 242 279 280 145 435 774 1351 1366 403 948 28 260 656 1467 1635 818 1061 1033 736 1706 619 228 1408 739 124 1554 688 1619 917 1332 1435 1015 ...
output:
936 1 1 857 1484 2 3 787 1279 3 3 1309 1714 4 5 688 1894 5 5 414 1456 6 6 204 880 7 11 1229 1767 8 12 1552 1801 9 9 476 1763 10 10 688 786 11 11 1102 1788 12 14 1144 1355 13 16 1405 1646 14 16 504 1500 15 16 432 1832 16 17 925 1232 17 17 466 1344 18 18 645 1578 20 22 1332 1704 21 21 851 1928 23 23 1...
result:
ok orz U R the sorting master!
Test #12:
score: 0
Accepted
time: 1ms
memory: 5688kb
input:
2 2 1
output:
1 1 1 2 2
result:
ok orz U R the sorting master!
Test #13:
score: 0
Accepted
time: 1ms
memory: 7724kb
input:
3 1 3 2
output:
1 2 2 3 3
result:
ok orz U R the sorting master!
Test #14:
score: 0
Accepted
time: 1ms
memory: 7724kb
input:
10 10 1 8 5 7 9 4 3 2 6
output:
5 1 1 2 10 2 3 8 8 3 3 6 6 4 4 5 9 5 6 7 8
result:
ok orz U R the sorting master!
Test #15:
score: 0
Accepted
time: 1ms
memory: 5624kb
input:
1967 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101...
output:
0
result:
ok orz U R the sorting master!
Test #16:
score: 0
Accepted
time: 2ms
memory: 7804kb
input:
1999 1999 1998 1997 1996 1995 1994 1993 1992 1991 1990 1989 1988 1987 1986 1985 1984 1983 1982 1981 1980 1979 1978 1977 1976 1975 1974 1973 1972 1971 1970 1969 1968 1967 1966 1965 1964 1963 1962 1961 1960 1959 1958 1957 1956 1955 1954 1953 1952 1951 1950 1949 1948 1947 1946 1945 1944 1943 1942 1941 ...
output:
999 1 1 1999 1999 2 2 1998 1998 3 3 1997 1997 4 4 1996 1996 5 5 1995 1995 6 6 1994 1994 7 7 1993 1993 8 8 1992 1992 9 9 1991 1991 10 10 1990 1990 11 11 1989 1989 12 12 1988 1988 13 13 1987 1987 14 14 1986 1986 15 15 1985 1985 16 16 1984 1984 17 17 1983 1983 18 18 1982 1982 19 19 1981 1981 20 20 1980...
result:
ok orz U R the sorting master!
Test #17:
score: 0
Accepted
time: 2ms
memory: 7772kb
input:
1961 2 1 4 3 6 5 8 7 10 9 12 11 14 13 16 15 18 17 20 19 22 21 24 23 26 25 28 27 30 29 32 31 34 33 36 35 38 37 40 39 42 41 44 43 46 45 48 47 50 49 52 51 54 53 56 55 58 57 60 59 62 61 64 63 66 65 68 67 70 69 72 71 74 73 76 75 78 77 80 79 82 81 84 83 86 85 88 87 90 89 92 91 94 93 96 95 98 97 100 99 102...
output:
980 1 1 2 3 2 2 3 5 4 4 5 7 6 6 7 9 8 8 9 11 10 10 11 13 12 12 13 15 14 14 15 17 16 16 17 19 18 18 19 21 20 20 21 23 22 22 23 25 24 24 25 27 26 26 27 29 28 28 29 31 30 30 31 33 32 32 33 35 34 34 35 37 36 36 37 39 38 38 39 41 40 40 41 43 42 42 43 45 44 44 45 47 46 46 47 49 48 48 49 51 50 50 51 53 52 ...
result:
ok orz U R the sorting master!
Test #18:
score: 0
Accepted
time: 2ms
memory: 7672kb
input:
1996 3 2 1 6 5 4 9 8 7 12 11 10 15 14 13 18 17 16 21 20 19 24 23 22 27 26 25 30 29 28 33 32 31 36 35 34 39 38 37 42 41 40 45 44 43 48 47 46 51 50 49 54 53 52 57 56 55 60 59 58 63 62 61 66 65 64 69 68 67 72 71 70 75 74 73 78 77 76 81 80 79 84 83 82 87 86 85 90 89 88 93 92 91 96 95 94 99 98 97 102 101...
output:
665 1 1 3 5 2 2 4 8 5 5 7 11 8 8 10 14 11 11 13 17 14 14 16 20 17 17 19 23 20 20 22 26 23 23 25 29 26 26 28 32 29 29 31 35 32 32 34 38 35 35 37 41 38 38 40 44 41 41 43 47 44 44 46 50 47 47 49 53 50 50 52 56 53 53 55 59 56 56 58 62 59 59 61 65 62 62 64 68 65 65 67 71 68 68 70 74 71 71 73 77 74 74 76 ...
result:
ok orz U R the sorting master!
Test #19:
score: 0
Accepted
time: 2ms
memory: 7816kb
input:
1973 4 2 3 1 8 6 7 5 12 10 11 9 16 14 15 13 20 18 19 17 24 22 23 21 28 26 27 25 32 30 31 29 36 34 35 33 40 38 39 37 44 42 43 41 48 46 47 45 52 50 51 49 56 54 55 53 60 58 59 57 64 62 63 61 68 66 67 65 72 70 71 69 76 74 75 73 80 78 79 77 84 82 83 81 88 86 87 85 92 90 91 89 96 94 95 93 100 98 99 97 104...
output:
493 1 1 4 7 2 2 5 11 6 6 9 15 10 10 13 19 14 14 17 23 18 18 21 27 22 22 25 31 26 26 29 35 30 30 33 39 34 34 37 43 38 38 41 47 42 42 45 51 46 46 49 55 50 50 53 59 54 54 57 63 58 58 61 67 62 62 65 71 66 66 69 75 70 70 73 79 74 74 77 83 78 78 81 87 82 82 85 91 86 86 89 95 90 90 93 99 94 94 97 103 98 98...
result:
ok orz U R the sorting master!