UOJ Logo

NOI.AC

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#193184#3403. XOR就是ADDdiamond_plus100170ms9168kbC++112.2kb2023-10-14 09:37:292023-10-14 12:17:57

answer

#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <deque>

using namespace std;

#define rd read()
#define int long long

const int N = 1e6 + 10;
const int MOD = 998244353;
const int INF = 0x7fffffff;
const int Fill = 0x3f;
const int FillINF = 0x3f3f3f3f;

void write(int n)
{
    if (n < 0)
    {
        putchar('-');
        n = -n;
    }
    if (n < 10)
    {
        putchar(n + '0');
        return;
    }
    write(n / 10);
    putchar(n % 10 + '0');
    return;
}
void wt(int n, bool o = 1)
{
    write(n);
    if (!o)
    {
        putchar(' ');
    }
    else
    {
        putchar('\n');
    }
}

int read()
{
    char ch;
    int type = 1, n = 0;
    ch = getchar();
    while (ch < '0' || ch > '9')
    {
        if (ch == '-')
        {
            type = -1;
        }
        ch = getchar();
    }
    while (ch >= '0' && ch <= '9')
    {
        n = (n << 1) + (n << 3) + (ch ^ 48);
        ch = getchar();
    }
    return n * type;
}

int n;

int f(int x)
{
    int i = 0;
    int ans = x;
    for (i = 0; 1 << i <= x; i++)
    {
        ans ^= 1 << i;
    }
    // ans = ~x;
    // cout << ans;
    // ans = abs(ans ^ x);
    return ans;
    // while (x)
    // {
    //     ans += !(x & 1);
    //     ans <<= 1;
    //     x >>= 1;
    // }
}

void solve()
{
    int i, j;
    stack <int> s;
    int k;
    int lst;
    n = rd;
    // wt(f(n));
    if (n == 1)
    {
        wt(0);
        return ;
    }
    i = n - 1;
    lst = n - 1;
    while (i >= 0)
    {
        if (i == 1 && n & 1)
        {
            s.push(0);
            // wt(0);
            break;
        }
        k = f(i);

        for (j = k; j <= i; j++)
        {
            s.push(j);
            // wt(j, 0);
        }
        i = k - 1;
    }
    while (!s.empty())
    {
        wt(s.top(), 0);
        s.pop();
    }
}

signed main()
{
    int T;
    int i, j;
    T = 1;
    while (T--)
    {

        solve();
    }
    return 0;
}

详细

小提示:点击横条可展开更详细的信息

Test #1:

score: 10
Accepted
time: 0ms
memory: 1168kb

input:

8

output:

7 6 5 4 3 2 1 0 

result:

ok ok n = 8

Test #2:

score: 10
Accepted
time: 0ms
memory: 1164kb

input:

9

output:

0 6 5 4 3 2 1 8 7 

result:

ok ok n = 9

Test #3:

score: 10
Accepted
time: 0ms
memory: 1164kb

input:

10

output:

1 0 5 4 3 2 9 8 7 6 

result:

ok ok n = 10

Test #4:

score: 10
Accepted
time: 0ms
memory: 1164kb

input:

19

output:

0 2 1 12 11 10 9 8 7 6 5 4 3 18 17 16 15 14 13 

result:

ok ok n = 19

Test #5:

score: 10
Accepted
time: 0ms
memory: 1164kb

input:

20

output:

3 2 1 0 11 10 9 8 7 6 5 4 19 18 17 16 15 14 13 12 

result:

ok ok n = 20

Test #6:

score: 10
Accepted
time: 0ms
memory: 1188kb

input:

999

output:

0 6 5 4 3 2 1 24 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 7 998 997 996 995 994 993 992 991 990...

result:

ok ok n = 999

Test #7:

score: 10
Accepted
time: 0ms
memory: 1184kb

input:

1000

output:

7 6 5 4 3 2 1 0 23 22 21 20 19 18 17 16 15 14 13 12 11 10 9 8 999 998 997 996 995 994 993 992 991 99...

result:

ok ok n = 1000

Test #8:

score: 10
Accepted
time: 109ms
memory: 9168kb

input:

1000000

output:

63 62 61 60 59 58 57 56 55 54 53 52 51 50 49 48 47 46 45 44 43 42 41 40 39 38 37 36 35 34 33 32 31 3...

result:

ok ok n = 1000000

Test #9:

score: 10
Accepted
time: 10ms
memory: 2236kb

input:

131315

output:

0 2 1 12 11 10 9 8 7 6 5 4 3 242 241 240 239 238 237 236 235 234 233 232 231 230 229 228 227 226 225...

result:

ok ok n = 131315

Test #10:

score: 10
Accepted
time: 51ms
memory: 9100kb

input:

979797

output:

0 2 1 4 3 10 9 8 7 6 5 20 19 18 17 16 15 14 13 12 11 42 41 40 39 38 37 36 35 34 33 32 31 30 29 28 27...

result:

ok ok n = 979797

Extra Test:

score: 0
Extra Test Passed