QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#347659 | #6753. Medians | wtz2333 | RE | 0ms | 3608kb | C++17 | 1.7kb | 2024-03-09 14:44:37 | 2024-03-09 14:44:41 |
Judging History
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