QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#91103 | #4900. 数列重排 | wyzwyz | 20 | 527ms | 1872kb | C++14 | 2.1kb | 2023-03-27 12:19:28 | 2023-03-27 12:19:32 |
Judging History
answer
#include<cstdio>
#include<cctype>
#define maxn 10011001
template<class T>
inline T read(){
T r=0,f=0;
char c;
while(!isdigit(c=getchar()))f|=(c=='-');
while(isdigit(c))r=(r*10)+(c^48),c=getchar();
return f?-r:r;
}
template<class T>
inline T min(T a,T b){
return a<b?a:b;
}
template<class T>
inline T max(T a,T b){
return a>b?a:b;
}
int N,n,L,R,X;
char S[maxn];
namespace bf{
int b[5555],sum[5555];
inline int add(int K,int len){
sum[0]=b[0];
for(int i=1;i<=len;i++)
sum[i]=sum[i-1]+b[i];
int pos=0,Min=sum[K-1];
for(int i=1;i<=len;i++){
int val=sum[min(i+K-1,len)]-(i-K<0?0:sum[i-K]);
if(val<Min)pos=i,Min=val;
}
b[pos]++;
return sum[len]-Min;
}
inline long long F(int K,int len){
if(!K)return N*(N+1ll)/2;
long long ans=0;
for(int i=0;i<=len;i++)
b[i]=1,ans+=max(i-K+1,0);
for(int i=N-len;i;i--)ans+=add(K,len);
return ans;
}
inline void work(){
int cnt=0;
long long P=1;
for(int i=0;i<L;i++)
cnt+=S[i]-'0'+X,(P*=233)%=998244353;
long long ans=0;
for(int i=L;i<=R;i++){
ans^=P*F(i,cnt)%998244353;
cnt+=S[i]-'0'+X,(P*=233)%=998244353;
}
printf("%lld\n",ans);
}
}
namespace BF{
int b[5555],sum[5555];
inline long long F(int K,int len){
if(!K)return N*(N+1ll)/2;
long long ans=0;
for(int i=0;i<=len;i++)b[i]=1;
int Add=N-len;
int c=min(Add,2*(K-1));
b[len]+=c/2,b[1]+=c-c/2,Add-=c;
int val=c/(len/K+1),r=c%(len/K+1);
for(int i=0;i+K<=len;i+=K)
b[i]+=val+(!!r),r--;
b[len]+=val+(!!r),r--;
for(int i=K,sum=0;i<=len;i++)
sum+=b[i-K],ans+=1ll*b[i]*sum;
return ans;
}
inline void work(){
int cnt=0;
long long P=1;
for(int i=0;i<L;i++)
cnt+=S[i]-'0'+X,(P*=233)%=998244353;
long long ans=0;
for(int i=L;i<=R;i++){
ans^=P*F(i,cnt)%998244353;
cnt+=S[i]-'0'+X,(P*=233)%=998244353;
}
printf("%lld\n",ans);
}
}
int main(){
n=read<int>();
L=read<int>();
R=read<int>();
X=read<int>();
scanf("%s",S);
for(int i=0;i<n;i++)
N+=S[i]-'0'+X;
if(n<=200)return bf::work(),0;
return BF::work(),0;
return 0;
}
详细
Subtask #1:
score: 5
Accepted
Test #1:
score: 5
Accepted
time: 0ms
memory: 1764kb
input:
2 0 2 2 01
output:
541257
result:
ok 1 number(s): "541257"
Test #2:
score: 0
Accepted
time: 1ms
memory: 1472kb
input:
4 1 4 2 00001
output:
525797597
result:
ok 1 number(s): "525797597"
Test #3:
score: 0
Accepted
time: 1ms
memory: 1708kb
input:
9 0 9 1 000000000
output:
711136343
result:
ok 1 number(s): "711136343"
Test #4:
score: 0
Accepted
time: 1ms
memory: 1452kb
input:
1 0 1 9 0
output:
10456
result:
ok 1 number(s): "10456"
Test #5:
score: 0
Accepted
time: 1ms
memory: 1872kb
input:
2 1 2 3 11
output:
1518844
result:
ok 1 number(s): "1518844"
Subtask #2:
score: 15
Accepted
Dependency #1:
100%
Accepted
Test #6:
score: 15
Accepted
time: 1ms
memory: 1524kb
input:
21 0 21 9 111010011100100100000
output:
171658329
result:
ok 1 number(s): "171658329"
Test #7:
score: 0
Accepted
time: 3ms
memory: 1748kb
input:
200 0 200 1 00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
output:
287932632
result:
ok 1 number(s): "287932632"
Test #8:
score: 0
Accepted
time: 0ms
memory: 1532kb
input:
120 3 119 1 101000110101001100011100001011101110101010000011101110010101101000111100111100001001010010110001110011001010110001101111
output:
856785458
result:
ok 1 number(s): "856785458"
Test #9:
score: 0
Accepted
time: 1ms
memory: 1728kb
input:
2 0 2 99 10
output:
67513337
result:
ok 1 number(s): "67513337"
Subtask #3:
score: 0
Wrong Answer
Dependency #2:
100%
Accepted
Test #10:
score: 15
Accepted
time: 50ms
memory: 1732kb
input:
10 1 9 499 0110011010
output:
47418354
result:
ok 1 number(s): "47418354"
Test #11:
score: 0
Accepted
time: 527ms
memory: 1572kb
input:
100 0 100 49 1100100011111101111111001000000100010000101010110000011011110100100011111000111101100010001000001100
output:
100314042
result:
ok 1 number(s): "100314042"
Test #12:
score: -15
Wrong Answer
time: 2ms
memory: 1524kb
input:
1000 0 1000 4 1011110001101000100110000111011110101100110011100010001100001101000111100011100011110101000010000100101011010110000110100011011010011000111100100100100001000011001000000000111001010001000000110001001011100010011101010011011110001101000010010000101000100001111101001100100001010010001100...
output:
202868299
result:
wrong answer 1st numbers differ - expected: '738329201', found: '202868299'
Subtask #4:
score: 0
Time Limit Exceeded
Test #14:
score: 0
Time Limit Exceeded
input:
2 0 1 114514 10
output:
result:
Subtask #5:
score: 0
Runtime Error
Test #17:
score: 0
Runtime Error
input:
1000000 1000000 1000000 928 01100010010000000101111110001111011101111000011110100101011110011001001000011000110101101100111110000100101010111001111100010011100110000000111110110100001100000000011101100001010001010000010000001001000110011111010101111100001001110110010100000011000010010001111010011100...
output:
result:
Subtask #6:
score: 0
Time Limit Exceeded
Test #19:
score: 0
Time Limit Exceeded
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:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
0%
Subtask #9:
score: 0
Skipped
Dependency #1:
100%
Accepted
Dependency #2:
100%
Accepted
Dependency #3:
0%