QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#347659#6753. Medianswtz2333RE 0ms3608kbC++171.7kb2024-03-09 14:44:372024-03-09 14:44:41

Judging History

你现在查看的是最新测评结果

  • [2024-03-09 14:44:41]
  • 评测
  • 测评结果:RE
  • 用时:0ms
  • 内存:3608kb
  • [2024-03-09 14:44:37]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int mo = 998244353;
const int P = 1e9 + 7;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> p(n + 1),pre(n + 1),nxt(n + 1);
    for (int i = 1; i <= n;i ++) {
        p[i] = i;
        pre[i] = i - 1;
        nxt[i] = i + 1;
    }
    int a;
    cin >> a;
    for(int i = 1;i <= n;i ++) {
        int x = (1ll * a * mo + P) % (P + 2);
        swap(p[i],p[(x % i) + 1]); 
        a = x;
    }
    // vector<int> ans(n + 1);
    int last = (n + 1) / 2;
    int ans;
    int Ans = last;
    for(int i = n - 1;i >= 1;i --) {
        if(p[i + 1] == last) {
            if(i & 1) {
                int x = last;
                x = nxt[x];
                ans = x;
            }else {
                int x = last;
                x = pre[x];
                ans = x; 
            }
        }else if(p[i + 1] < last) {
            if(i & 1) {
                int x = last;
                x = nxt[x];
                ans = x;
            }else ans = last;
        }else {
            if(i & 1) {
                ans = last;
            }else {
                int x = last;
                x = pre[x];
                ans = x; 
            }
        }
        int x = p[i + 1];
        nxt[pre[x]] = nxt[x];
        pre[nxt[x]] = pre[x];
        pre[x] = nxt[x] = -1;
        Ans = (1ll * Ans * 19 % mo + ans) % mo;
        last = ans;
    }
    cout << (1ll * Ans * 19) % mo << endl;
}


// n / 20210926 <= k


/// 1 2 3 4 5 6 7 8

// 14 5 2 2 1 1 1 1

// 13 4 1 1 0 0 0 0

// 12 3 0 0 0 0 0 0

// 

详细

Test #1:

score: 100
Accepted
time: 0ms
memory: 3608kb

input:

5 0

output:

7703113

result:

ok 1 number(s): "7703113"

Test #2:

score: -100
Runtime Error

input:

5 1

output:

7840977

result: