QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#367366 | #6753. Medians | milet | WA | 1ms | 9804kb | C++20 | 1.7kb | 2024-03-25 21:45:12 | 2024-03-25 21:45:12 |
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 long long 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] = (1LL * 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++){
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 += 1LL * ans[i] * res % mod;
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;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 1ms
memory: 9792kb
input:
5 0
output:
7703113
result:
ok 1 number(s): "7703113"
Test #2:
score: 0
Accepted
time: 1ms
memory: 9716kb
input:
5 1
output:
7840977
result:
ok 1 number(s): "7840977"
Test #3:
score: 0
Accepted
time: 1ms
memory: 9800kb
input:
2 1361955
output:
399
result:
ok 1 number(s): "399"
Test #4:
score: 0
Accepted
time: 1ms
memory: 9776kb
input:
4 207579012
output:
274740
result:
ok 1 number(s): "274740"
Test #5:
score: -100
Wrong Answer
time: 1ms
memory: 9804kb
input:
8 628145516
output:
-55471402
result:
wrong answer 1st numbers differ - expected: '783389330', found: '-55471402'