3 条题解

  • 2
    @ 2023-12-29 16:45:12

    补一个 Q106Q\le 10^6 数据的代码。顺便还附带了打表的程序片段。

    #include <bits/stdc++.h>
    #define int long long
    using namespace std;
    const int MAXN = 1000000;
    int n, T, Q;
    // 打表看看
    namespace TEST
    {
        vector<int> a, b;
        void out()
        {
            int tim = 1;
            for (int i = 1; i <= n; i++)
                a.push_back(i);
            cout << tim++ << ": ";
            for (int x : a)
                cout << x << " ";
            cout << "\n";
            while (T--)
            {
                b.clear();
                for (int i = 0; i < n; i += 2)
                    b.push_back(a[i]);
                for (int i = 1; i < n; i += 2)
                    b.push_back(a[i]);
                a = b;
                cout << tim++ << ": ";
                for (int x : a)
                    cout << x << " ";
                cout << "\n";
            }
        }
    }
    int nxt[MAXN + 5];
    bool vis[MAXN + 5];
    vector<int> e[MAXN + 5];
    int ans[MAXN + 5];
    signed main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
        cin >> n >> T >> Q;
        // TEST::out();
        int base = n / 2 + (n & 1); // 奇数数量
        for (int i = 1; i <= n; i++)
        {
            if (i % 2 == 1)
                nxt[i] = 1 + i / 2;
            else
                nxt[i] = base + i / 2;
        }
        // 每个点入度出度都是 1,所以必然是形成了几个环,现在把每个环都找到存下来
        // 存成 vector 之后方便一口气做一个 T 轮的轮换
        for (int i = 1; i <= n; i++)
        {
            int now = i;
            while (!vis[now])
            {
                vis[now] = true;
                e[i].push_back(now);
                now = nxt[now];
            }
        }
        // getAns
        for (int i = 1; i <= n; i++)
        {
            if (e[i].empty())
                continue;
            int siz = e[i].size();
            for (int j = 0; j < e[i].size(); j++)
                ans[e[i][j]] = e[i][(j + T) % siz];
        }
        // 输出 Q 次询问的答案
        while (Q--)
        {
            int b;
            cin >> b;
            cout << ans[b] << " ";
        }
        return 0;
    }
    

    信息

    ID
    1384
    时间
    1000ms
    内存
    512MiB
    难度
    9
    标签
    (无)
    递交数
    234
    已通过
    24
    上传者