QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#367361 | #6753. Medians | milet | WA | 0ms | 5612kb | C++20 | 1.8kb | 2024-03-25 21:38:31 | 2024-03-25 21:38:31 |
Judging History
answer
#include <bits/stdc++.h>
using namespace std;
#define ls(x) ((x) << 1)
#define rs(x) ((x) << 1 | 1)
#define lowbit(x) ((x) & (-x))
const int N = 10010007;
const int M = 120;
const int INF = (1ull << 60) - 1;
const int mod = 998244353;
using pii = pair<int, int>;
using ll = long long;
struct node{
int l;int r;
int num;
}b[N];
int a[N];
int p[N];
int ans[N];
void solve(){
int n;
cin >> n;
cin >> a[0];
const int P = 1e9 + 7;
for (int i = 1;i <= n;i++)a[i] = (a[i - 1] * mod + P) % (P + 2);
for (int i = 1;i <= n;i++)p[i] = i;
for (int i = 1;i <= n;i++)swap(p[i], p[a[i] % i + 1]);
//for (int i = 1;i <= n;i++)cout << p[i] << " ";cout << '\n';
for (int i = 1;i <= n;i++){
b[i].l = i - 1;
b[i].r = i + 1;
b[i].num = i;
}
int mid = (n + 1)/2;
b[0].r = 1;
b[n + 1].l = n;
for (int i = n;i >= 1;i--){
ans[i] = b[mid].num;
//cout << ans[i] << '\n';
int L = b[p[i]].l;
int R = b[p[i]].r;
b[L].r = R;
b[R].l = L;
if (i & 1){
if (p[i] == b[mid].num)mid = b[mid].l;
else if (p[i] > b[mid].num)mid = b[mid].l;
}
else{
if (p[i] == b[mid].num)mid = b[mid].r;
else if (p[i] < b[mid].num)mid = b[mid].r;
}
}
int sum = 0;
int res = 19;
for (int i = 1;i <= n;i++){
sum += ans[i] * res;
sum %= mod;
res *= 19;
res %= mod;
}
cout << sum << '\n';
}
void init(int n,int k) {
}
signed main()
{
ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
int T = 1;
//cin >> T;
while (T--) {
solve();
}
return 0;
}
详细
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 5612kb
input:
5 0
output:
7717914
result:
wrong answer 1st numbers differ - expected: '7703113', found: '7717914'