QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#749625 | #4900. 数列重排 | NineSuns | 0 | 9ms | 3700kb | C++14 | 1.5kb | 2024-11-15 08:05:05 | 2024-11-15 08:05:06 |
answer
#include <bits/stdc++.h>
#define ll long long
#define pii pair <int, int>
#define fi first
#define se second
#define pb push_back
#define int long long
using namespace std;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
const int N = 1e7+5, inf = 0x3f3f3f3f3f3f3f3f, mod = 998244353;
int m, l, r, x, pr[N], n;
string str;
int sum (int n) { return n*(n+1)/2; }
int gets (int k, int c) {
if (c == 0 && k) return inf;
return sum(k/c)*(c-k%c)+sum(k/c+1)*(k%c);
}
void solve () {
cin >> m >> l >> r >> x >> str;
n = m*x;
for (int i = 0;i < m;i++) {
n += str[i]-'0';
pr[i] = str[i] == '1' ? (i ? pr[i-1]+1 : 1) : 0;
}
// cout << n << end l;
int lt = 1, res = 0;
if (l == 0) res ^= sum(n)%mod;
// cout << sum(n) << endl;
for (int i = 0, lst = -1;i < m;i++) {
lt = lt*233%mod;
if (lst == i-1 && str[i] == '1') lst++;
int ans = 0, sl, cx;
if (lst == i) {
sl = n-(i+1)*(x+1); cx = x+1;
}
else {
sl = n-(i+1)*x-(lst+1)-pr[i]; cx = x;
ans += (lst+1+pr[i])*i;
}
int sv = inf;
for (int j = sl/(cx+1);j <= sl;j++) sv = min(sv, -j*i+gets(j, 2)+gets(sl-j, cx-1));
ans += sv+2*i*sl+i*(i+1)*(cx-1)+sum(i)+i;
ans = sum(n)-ans;
if (l <= i+1 && i+1 <= r) res ^= ans%mod*lt%mod;
// cout << ans << endl;
}
cout << res;
}
signed main () {
// ios::sync_with_stdio(0);
// 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
Subtask #1:
score: 0
Runtime Error
Test #1:
score: 5
Accepted
time: 0ms
memory: 3696kb
input:
2 0 2 2 01
output:
541257
result:
ok 1 number(s): "541257"
Test #2:
score: 5
Accepted
time: 0ms
memory: 3700kb
input:
4 1 4 2 00001
output:
525797597
result:
ok 1 number(s): "525797597"
Test #3:
score: 0
Runtime Error
input:
9 0 9 1 000000000
output:
result:
Subtask #2:
score: 0
Skipped
Dependency #1:
0%
Subtask #3:
score: 0
Skipped
Dependency #2:
0%
Subtask #4:
score: 0
Time Limit Exceeded
Test #14:
score: 5
Accepted
time: 1ms
memory: 3512kb
input:
2 0 1 114514 10
output:
934764137
result:
ok 1 number(s): "934764137"
Test #15:
score: 5
Accepted
time: 9ms
memory: 3636kb
input:
2 0 1 1919810 01
output:
685371514
result:
ok 1 number(s): "685371514"
Test #16:
score: 0
Time Limit Exceeded
input:
2 0 1 500000000 00
output:
result:
Subtask #5:
score: 0
Time Limit Exceeded
Test #17:
score: 0
Time Limit Exceeded
input:
1000000 1000000 1000000 928 01100010010000000101111110001111011101111000011110100101011110011001001000011000110101101100111110000100101010111001111100010011100110000000111110110100001100000000011101100001010001010000010000001001000110011111010101111100001001110110010100000011000010010001111010011100...
output:
result:
Subtask #6:
score: 0
Runtime Error
Test #19:
score: 0
Runtime Error
input:
1000000 0 1000000 1 0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...
output:
result:
Subtask #7:
score: 0
Time Limit Exceeded
Test #21:
score: 0
Time Limit Exceeded
input:
1000000 0 9823 627 01110001011101001100010011100101001011000011011110001101010000000101010111110111110010010001110100101001111000111100011101111001000000100111000010010100010101110110111110100010101010001110111001100011010001111000101010000110010010101110101010111110110001110111111000001110000110011...
output:
result:
Subtask #8:
score: 0
Skipped
Dependency #1:
0%
Subtask #9:
score: 0
Skipped
Dependency #1:
0%