Task: | Just do it |
Sender: | (╯°□°)╯︵ ┻━┻ |
Submission time: | 2024-11-16 13:10:07 +0200 |
Language: | C++ (C++17) |
Status: | READY |
Result: | ACCEPTED |
test | verdict | time | |
---|---|---|---|
#1 | ACCEPTED | 0.00 s | details |
#2 | ACCEPTED | 0.00 s | details |
#3 | ACCEPTED | 0.00 s | details |
#4 | ACCEPTED | 0.00 s | details |
#5 | ACCEPTED | 0.00 s | details |
#6 | ACCEPTED | 0.00 s | details |
#7 | ACCEPTED | 0.00 s | details |
#8 | ACCEPTED | 0.00 s | details |
#9 | ACCEPTED | 0.00 s | details |
#10 | ACCEPTED | 0.00 s | details |
#11 | ACCEPTED | 0.00 s | details |
#12 | ACCEPTED | 0.00 s | details |
#13 | ACCEPTED | 0.00 s | details |
#14 | ACCEPTED | 0.00 s | details |
#15 | ACCEPTED | 0.00 s | details |
#16 | ACCEPTED | 0.00 s | details |
#17 | ACCEPTED | 0.00 s | details |
Code
#include <iostream> using namespace std; const int MN = 1024; int cur[MN]; int res[MN]; int V; int getM(int a, int b, int c) { int x = res[cur[a]]; int y = res[cur[b]]; int z = res[cur[c]]; if (x>y) swap(x,y); if (y>z) swap(y,z); if (x>y) swap(x,y); return y; } void solve(int low, int hi) { if (hi-low<=1) return; if (res[cur[low]]==0) res[cur[low]] = V--; if (res[cur[(low+hi)/2]]==0) res[cur[(low+hi)/2]] = V--; if (res[cur[hi-1]]==0) res[cur[hi-1]] = V--; int p = getM(low,hi-1, (low+hi)/2); int a=low; int b=hi-1; while(1) { while(res[cur[a]]<p) ++a; while(res[cur[b]]>p) --b; if (a>=b) break; swap(cur[a],cur[b]); ++a; --b; } solve(low, a); solve(a, hi); } int main() { int n;cin>>n; V=n; for(int i=0; i<n; ++i) cur[i]=i; solve(0, n); for(int i=0; i<n; ++i) cout<<res[i]<<' '; cout<<'\n'; }
Test details
Test 1
Verdict: ACCEPTED
input |
---|
2 |
correct output |
---|
1 2 |
user output |
---|
2 1 |
Test 2
Verdict: ACCEPTED
input |
---|
3 |
correct output |
---|
1 2 3 |
user output |
---|
3 2 1 |
Test 3
Verdict: ACCEPTED
input |
---|
4 |
correct output |
---|
1 2 3 4 |
user output |
---|
4 1 3 2 |
Test 4
Verdict: ACCEPTED
input |
---|
5 |
correct output |
---|
1 2 4 3 5 |
user output |
---|
5 2 4 1 3 |
Test 5
Verdict: ACCEPTED
input |
---|
6 |
correct output |
---|
1 2 3 5 4 6 |
user output |
---|
6 1 3 5 2 4 |
Test 6
Verdict: ACCEPTED
input |
---|
7 |
correct output |
---|
1 2 4 6 5 3 7 |
user output |
---|
7 2 4 6 3 1 5 |
Test 7
Verdict: ACCEPTED
input |
---|
8 |
correct output |
---|
1 2 3 5 7 6 4 8 |
user output |
---|
8 1 3 5 7 4 2 6 |
Test 8
Verdict: ACCEPTED
input |
---|
9 |
correct output |
---|
1 2 4 6 8 3 7 5 9 |
user output |
---|
9 2 4 6 8 1 5 3 7 |
Test 9
Verdict: ACCEPTED
input |
---|
10 |
correct output |
---|
1 2 3 5 7 9 4 8 6 10 |
user output |
---|
10 1 3 5 7 9 2 6 4 8 |
Test 10
Verdict: ACCEPTED
input |
---|
99 |
correct output |
---|
1 2 4 6 8 10 12 14 16 18 20 22... |
user output |
---|
99 2 4 6 8 10 12 14 16 18 20 2... |
Test 11
Verdict: ACCEPTED
input |
---|
100 |
correct output |
---|
1 2 3 5 7 9 11 13 15 17 19 21 ... |
user output |
---|
100 1 3 5 7 9 11 13 15 17 19 2... |
Test 12
Verdict: ACCEPTED
input |
---|
101 |
correct output |
---|
1 2 4 6 8 10 12 14 16 18 20 22... |
user output |
---|
101 2 4 6 8 10 12 14 16 18 20 ... |
Test 13
Verdict: ACCEPTED
input |
---|
300 |
correct output |
---|
1 2 3 5 7 9 11 13 15 17 19 21 ... |
user output |
---|
300 1 3 5 7 9 11 13 15 17 19 2... |
Test 14
Verdict: ACCEPTED
input |
---|
500 |
correct output |
---|
1 2 3 5 7 9 11 13 15 17 19 21 ... |
user output |
---|
500 1 3 5 7 9 11 13 15 17 19 2... |
Test 15
Verdict: ACCEPTED
input |
---|
998 |
correct output |
---|
1 2 3 5 7 9 11 13 15 17 19 21 ... |
user output |
---|
998 1 3 5 7 9 11 13 15 17 19 2... |
Test 16
Verdict: ACCEPTED
input |
---|
999 |
correct output |
---|
1 2 4 6 8 10 12 14 16 18 20 22... |
user output |
---|
999 2 4 6 8 10 12 14 16 18 20 ... |
Test 17
Verdict: ACCEPTED
input |
---|
1000 |
correct output |
---|
1 2 3 5 7 9 11 13 15 17 19 21 ... |
user output |
---|
1000 1 3 5 7 9 11 13 15 17 19 ... |