QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#85362 | #5238. Fotografia [C] | anhduc2701 | 0 | 28ms | 52344kb | C++23 | 3.0kb | 2023-03-07 17:35:33 | 2023-03-07 17:35:36 |
Judging History
answer
/*
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
using namespace std;
#define all(x) x.begin(), x.end()
#define len(x) (int)(x.size())
#define eb emplace_back
#define PI 3.14159265359
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define MIN(v) *min_element(all(v))
#define MAX(v) *max_element(all(v))
#define BIT(x,i) (1&((x)>>(i)))
#define MASK(x) (1LL<<(x))
#define task "FOT"
typedef long long ll;
const ll INF=1e18;
const int maxn=1e6+5;
const int mod=1e9+7;
const int mo=998244353;
using pi=pair<ll,ll>;
using vi=vector<ll>;
using pii=pair<pair<ll,ll>,ll>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n;
int a[maxn];
int ok[maxn];
vector<int>vt;
vector<int>q[maxn];
int st[maxn];
vector<pair<int,int>>ans[maxn];
int k=0;
void dequy(vector<int>q,int ti){
if(len(q)<=1){
return;
}
if(len(q)==2){
ans[ti].pb({q[0],q[1]});
return;
}
k=max(k,ti);
if(len(q)%2==0){
int sz=len(q);
vector<int>d1;
int so=sz-1;
for(int i=1;i<=so;i++){
ans[ti].pb({q[i],q[so]});
swap(q[i],q[so]);
so--;
d1.pb(q[i]);
}
for(int i=0;i<q.size();i++){
ans[ti+1].pb({q[i],q[i+1]});
}
k=2;
}
else{
int sz=len(q);
vector<int>d1;
if(sz==3){
ans[ti].pb({q[0],q[1]});
ans[ti+1].pb({q[0],q[2]});
k=2;
}
else{
ans[ti].pb({q[0],q[1]});
ans[ti].pb({q[2],q.back()});
swap(q[0],q[1]);
int so=sz-2;
for(int i=3;i<so;i++){
ans[ti].pb({q[i],q[so]});
swap(q[i],q[so]);
so--;
}
for(int i=1;i<q.size();i+=2){
ans[ti+1].pb({q[i],q[i+1]});
}
k=2;
}
}
}
signed main()
{
cin.tie(0),cout.tie(0)->sync_with_stdio(0);
// freopen(task".inp" , "r" , stdin);
// freopen(task".out" , "w" , stdout);
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];
vt.pb(a[i]);
}
sort(vt.begin(),vt.end());
vt.resize(distance(vt.begin(),unique(vt.begin(),vt.end())));
for(int i=1;i<=n;i++){
a[i]=lower_bound(vt.begin(),vt.end(),a[i])-vt.begin()+1;
// cout<<a[i]<<" ";
}
int cycle=0;
int d=0;
for(int i=1;i<=n;i++){
if(ok[a[i]]==0){
int x=i;
cycle++;
while(ok[x]==0){
ok[x]=1;
q[cycle].pb(x);
x=a[x];
}
dequy(q[cycle],1);
}
}
cout<<k<<"\n";
for(int i=1;i<=k;i++){
deque<int>de;
for(auto v:ans[i]){
de.push_front(v.fi);
de.push_back(v.se);
}
cout<<de.size()<<"\n";
for(auto v:de){
cout<<v<<" ";
}
cout<<'\n';
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 1
Accepted
time: 28ms
memory: 52344kb
input:
5 138 352 915 1375 2848
output:
0
result:
ok correct plan!
Test #2:
score: -1
Wrong Answer
time: 8ms
memory: 51560kb
input:
5 2182 1715 524 2331 2791
output:
0
result:
wrong answer the array is not sorted
Subtask #2:
score: 0
Wrong Answer
Test #18:
score: 1
Accepted
time: 17ms
memory: 50452kb
input:
10 321 457 797 885 892 1367 2480 2742 2767 2955
output:
0
result:
ok correct plan!
Test #19:
score: -1
Wrong Answer
time: 16ms
memory: 50384kb
input:
10 1237 39 2762 2728 2645 2669 1833 1836 1572 1560
output:
0
result:
wrong answer the array is not sorted
Subtask #3:
score: 0
Wrong Answer
Test #35:
score: 0
Wrong Answer
time: 7ms
memory: 50388kb
input:
20 29 2902 1870 1908 711 1878 2034 1658 1690 533 1080 689 2282 2637 1599 1912 2365 2015 2659 275
output:
0
result:
wrong answer the array is not sorted
Subtask #4:
score: 0
Wrong Answer
Test #51:
score: 0
Wrong Answer
time: 12ms
memory: 50392kb
input:
100 2985 38 1126 111 1953 886 2186 417 776 326 2961 388 240 1592 1203 1768 581 514 494 2762 1954 641 1731 685 723 1718 1143 761 318 2532 1193 1596 194 2014 2703 2515 2107 1049 2504 1088 1327 102 744 1162 1177 830 2579 461 1362 1100 1273 2471 2077 2628 1541 426 839 1643 1708 732 652 2665 1765 483 191...
output:
0
result:
wrong answer the array is not sorted
Subtask #5:
score: 0
Wrong Answer
Test #67:
score: 0
Wrong Answer
time: 8ms
memory: 50372kb
input:
1000 2271 250 4 10 11 13 404 15 1911 2785 308 32 975 2111 1010 2335 2200 1626 45 46 2125 52 53 59 63 2138 2101 837 71 2503 2508 2659 79 542 90 92 299 602 106 2181 159 2167 2550 482 2702 1390 1487 2903 125 1687 129 466 143 279 1319 748 132 148 1141 111 336 164 175 2267 633 186 483 548 946 196 1085 20...
output:
0
result:
wrong answer the array is not sorted
Subtask #6:
score: 0
Wrong Answer
Test #78:
score: 0
Wrong Answer
time: 12ms
memory: 51620kb
input:
3000 1 2 3 2029 1711 669 2046 1892 2438 2863 279 12 2604 478 1122 2318 17 497 1969 775 21 2173 865 24 2682 1567 27 551 29 2699 600 32 33 2996 2960 1779 37 38 214 2590 1241 2518 43 1781 2824 390 1384 524 432 50 51 2975 53 406 55 56 57 2188 1410 2578 1447 1060 63 2081 580 2755 67 2560 2722 1071 71 72 ...
output:
0
result:
wrong answer the array is not sorted
Subtask #7:
score: 0
Wrong Answer
Test #94:
score: 0
Wrong Answer
time: 8ms
memory: 51828kb
input:
3000 729 1498 1848 569 1429 1721 2356 2504 483 158 2104 2471 2942 994 2046 2784 1613 1648 2834 1108 1805 1328 1984 1853 1180 2517 109 2601 2144 30 53 2173 1992 944 121 1595 1943 755 2732 2833 233 2934 1147 1091 2478 1948 252 962 221 400 1235 1486 31 69 1318 804 70 851 1026 930 2731 1922 713 1282 292...
output:
2 2430 2843 2821 2753 2712 2711 2666 2663 2631 2590 2531 2491 2454 2405 2398 2383 2382 2380 2375 2363 2323 2314 2271 2263 2212 2211 2190 2182 2160 2152 2106 2105 2090 2075 2072 2053 2042 2026 2024 2021 2019 1994 1993 1965 1960 1940 1931 1919 1896 1976 1892 1890 1882 2163 1881 2139 2706 2495 2384 186...
result:
wrong answer invalid operation #1: duplicated elements
Subtask #8:
score: 0
Wrong Answer
Test #105:
score: 0
Wrong Answer
time: 13ms
memory: 50528kb
input:
3000 766 1622 2731 1980 5 6 200 671 2792 1172 2005 1950 2806 557 2069 2552 1768 2600 2312 346 21 2376 2267 691 2995 26 2319 28 2148 30 970 2779 2645 1580 2627 1900 149 226 1642 1383 928 2575 1648 1859 2203 2701 1100 1391 1745 293 1625 670 1189 54 1413 1733 2878 2501 1765 841 61 454 2372 2901 1420 25...
output:
2 2390 2935 2642 2558 2514 2493 2446 2389 2314 2280 2351 2384 2241 2231 2230 2711 2679 2225 2218 2197 2192 2170 2169 2162 2861 2610 2056 2040 2038 2382 2146 1997 1991 1987 1983 1971 1970 1955 1925 1917 1889 1880 2710 2201 1870 1828 1820 2640 1813 1807 1800 1865 1794 2766 1789 1781 1762 1761 2649 210...
result:
wrong answer invalid operation #1: duplicated elements
Subtask #9:
score: 0
Wrong Answer
Test #116:
score: 0
Wrong Answer
time: 11ms
memory: 50472kb
input:
3000 361 2 3 1184 5 6 7 8 2192 866 1680 935 13 14 618 16 140 18 1462 20 21 600 23 24 749 26 27 28 29 1947 54 2298 33 1313 303 2036 742 723 39 40 41 42 1381 2372 1112 46 2748 2536 49 50 51 52 53 31 1080 2481 57 82 59 2238 1647 62 2271 64 65 2773 67 167 2308 2022 252 794 73 74 2020 916 1141 1461 2287 ...
output:
0
result:
wrong answer the array is not sorted
Subtask #10:
score: 0
Wrong Answer
Test #132:
score: 1
Accepted
time: 7ms
memory: 50488kb
input:
3000 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 correct plan!
Test #133:
score: -1
Wrong Answer
time: 9ms
memory: 50568kb
input:
3000 1 2977 74 1664 2956 968 7 612 1394 839 147 1582 1970 506 15 16 17 18 444 1032 21 1634 1941 676 2222 1028 2266 1986 1565 30 2798 32 33 573 35 36 388 240 39 917 1047 2755 2894 44 45 257 1953 1436 49 50 51 52 1982 54 2766 1075 57 58 59 982 2441 1339 63 777 1298 816 2845 2098 69 70 2105 1868 73 3 1...
output:
0
result:
wrong answer the array is not sorted