QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#91720#4900. 数列重排OtoriEmu90 542ms23036kbC++142.5kb2023-03-29 14:35:462023-03-29 14:35:47

Judging History

你现在查看的是最新测评结果

  • [2023-08-10 23:21:45]
  • System Update: QOJ starts to keep a history of the judgings of all the submissions.
  • [2023-03-29 14:35:47]
  • 评测
  • 测评结果:90
  • 用时:542ms
  • 内存:23036kb
  • [2023-03-29 14:35:46]
  • 提交

answer

/*
わんわん……わんだほーいっ☆
Wonderhoy!
*/
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef double DB;
char buf[1<<21],*p1=buf,*p2=buf;
#define getchar() (p1==p2 && (p2=(p1=buf)+fread(buf,1,1<<18,stdin),p1==p2)?EOF:*p1++)
LL read()
{
	LL x=0;
	char c=getchar();
	while(c<'0' || c>'9')	c=getchar();
	while(c>='0' && c<='9')	x=(x<<1)+(x<<3)+(c^'0'),c=getchar();
	return x;
}
void write(LL x)
{
	if(x>9)	write(x/10);
	putchar(x%10+'0');
}
LL rdgt()
{
	char c=getchar();
	while(!isdigit(c))	c=getchar();
	return c^'0';
}
typedef pair<LL,LL> P;
typedef vector<LL> Poly;
typedef vector<P> PolyP;
#define mp make_pair
#define spc putchar(' ')
#define etr putchar('\n')
#define inlp(x,y) putchar(x==y?'\n':' ')
const LL MOD=998244353,inf=1e18;
inline LL Add(LL u,LL v){return u+v>=MOD?u+v-MOD:u+v;}
inline LL Sub(LL u,LL v){return u-v>=0?u-v:u-v+MOD;}
inline LL Mul(LL u,LL v){return LL(u)*LL(v)%MOD;}
inline LL add(LL &u,LL v){return u=Add(u,v);}
inline LL sub(LL &u,LL v){return u=Sub(u,v);}
inline LL mul(LL &u,LL v){return u=Mul(u,v);}
LL QuickPow(LL x,LL p=MOD-2)
{
	LL ans=1,base=x;
	while(p)
	{
		if(p&1)	mul(ans,base);
		mul(base,base);
		p>>=1;
	}
	return ans;
}
inline LL fsum(LL x){return x*(x+1)/2;}
inline LL avediv(LL x,LL n)
{
	if(x==0)	return 0;
	LL p=x/n,q=x%n;
	return fsum(p)*(n-q)+fsum(p+1)*q;
}
inline LL calc(LL p,LL q,LL rst,LL x,LL f){return fsum(p)+fsum(q)+(2*rst-p-q)*(f-1)+avediv(rst-p-q,x-1);}
LL n,m,L,R,c;
LL a[10000005];
int main(){
	m=read(),L=read(),R=read(),c=read();
	for(LL i=0;i<m;++i)	a[i]=rdgt();
	n=accumulate(a,a+m,m*c);
	LL ans=0;
	if(L==0)	ans=fsum(n)%MOD,L=1;
	LL up=n,fl=accumulate(a,a+L-1,0);
	LL pw=QuickPow(233,L-1);
	for(LL i=L;i<=R;++i)
	{
		mul(pw,233);
		fl+=a[i-1];
		LL rst=n-fl-i*c,x=c;
		up=min(up,rst/2);
		if(fl==i)	++x;
		else if(fl==i-1 && a[i-1]==0)	up=rst/2;
		LL ret=inf;
		if(x==1)	ret=calc(rst/2,rst-rst/2,rst,x,i);
		else
		{
			if(m>=2e6 && up<=1e7)	while(up>0 && calc(up,up,rst,x,i)>calc(up-1,up-1,rst,x,i))	--up;
			else
			{
				LL l=1,r=up;
				up=0;
				while(l<=r)
				{
					LL mid=(l+r)>>1;
					if(calc(mid,mid,rst,x,i)<calc(mid-1,mid-1,rst,x,i))		up=mid,l=mid+1;
					else	r=mid-1;
				}
			}
			ret=min(ret,calc(up,up,rst,x,i));
			if(up+up+1<=rst)	ret=min(ret,calc(up,up+1,rst,x,i));
		}
		LL fans=fsum(n)-ret-(n-rst-(i-1))*(i-1)-fsum(i-1);
		ans^=Mul(fans%MOD,pw);
	}
	write(ans),etr;
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 5
Accepted

Test #1:

score: 5
Accepted
time: 0ms
memory: 5404kb

input:

2 0 2 2
01

output:

541257

result:

ok 1 number(s): "541257"

Test #2:

score: 0
Accepted
time: 2ms
memory: 5468kb

input:

4 1 4 2
00001

output:

525797597

result:

ok 1 number(s): "525797597"

Test #3:

score: 0
Accepted
time: 2ms
memory: 5456kb

input:

9 0 9 1
000000000

output:

711136343

result:

ok 1 number(s): "711136343"

Test #4:

score: 0
Accepted
time: 2ms
memory: 5488kb

input:

1 0 1 9
0

output:

10456

result:

ok 1 number(s): "10456"

Test #5:

score: 0
Accepted
time: 2ms
memory: 5420kb

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: 2ms
memory: 5464kb

input:

21 0 21 9
111010011100100100000

output:

171658329

result:

ok 1 number(s): "171658329"

Test #7:

score: 0
Accepted
time: 2ms
memory: 5484kb

input:

200 0 200 1
00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

output:

287932632

result:

ok 1 number(s): "287932632"

Test #8:

score: 0
Accepted
time: 1ms
memory: 5628kb

input:

120 3 119 1
101000110101001100011100001011101110101010000011101110010101101000111100111100001001010010110001110011001010110001101111

output:

856785458

result:

ok 1 number(s): "856785458"

Test #9:

score: 0
Accepted
time: 2ms
memory: 5452kb

input:

2 0 2 99
10

output:

67513337

result:

ok 1 number(s): "67513337"

Subtask #3:

score: 15
Accepted

Dependency #2:

100%
Accepted

Test #10:

score: 15
Accepted
time: 2ms
memory: 5568kb

input:

10 1 9 499
0110011010

output:

47418354

result:

ok 1 number(s): "47418354"

Test #11:

score: 0
Accepted
time: 0ms
memory: 5628kb

input:

100 0 100 49
1100100011111101111111001000000100010000101010110000011011110100100011111000111101100010001000001100

output:

100314042

result:

ok 1 number(s): "100314042"

Test #12:

score: 0
Accepted
time: 2ms
memory: 5468kb

input:

1000 0 1000 4
1011110001101000100110000111011110101100110011100010001100001101000111100011100011110101000010000100101011010110000110100011011010011000111100100100100001000011001000000000111001010001000000110001001011100010011101010011011110001101000010010000101000100001111101001100100001010010001100...

output:

738329201

result:

ok 1 number(s): "738329201"

Test #13:

score: 0
Accepted
time: 2ms
memory: 5660kb

input:

5000 0 5000 1
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

76076468

result:

ok 1 number(s): "76076468"

Subtask #4:

score: 5
Accepted

Test #14:

score: 5
Accepted
time: 2ms
memory: 5456kb

input:

2 0 1 114514
10

output:

934764137

result:

ok 1 number(s): "934764137"

Test #15:

score: 0
Accepted
time: 2ms
memory: 5592kb

input:

2 0 1 1919810
01

output:

685371514

result:

ok 1 number(s): "685371514"

Test #16:

score: 0
Accepted
time: 2ms
memory: 5408kb

input:

2 0 1 500000000
00

output:

318651831

result:

ok 1 number(s): "318651831"

Subtask #5:

score: 10
Accepted

Test #17:

score: 10
Accepted
time: 2ms
memory: 14252kb

input:

1000000 1000000 1000000 928
01100010010000000101111110001111011101111000011110100101011110011001001000011000110101101100111110000100101010111001111100010011100110000000111110110100001100000000011101100001010001010000010000001001000110011111010101111100001001110110010100000011000010010001111010011100...

output:

437299311

result:

ok 1 number(s): "437299311"

Test #18:

score: 0
Accepted
time: 2ms
memory: 5416kb

input:

100 100 100 10000000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

output:

119118463

result:

ok 1 number(s): "119118463"

Subtask #6:

score: 10
Accepted

Test #19:

score: 10
Accepted
time: 8ms
memory: 14208kb

input:

1000000 0 1000000 1
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

852768823

result:

ok 1 number(s): "852768823"

Test #20:

score: 0
Accepted
time: 14ms
memory: 14600kb

input:

1000000 0 1000000 1
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

852768823

result:

ok 1 number(s): "852768823"

Subtask #7:

score: 15
Accepted

Test #21:

score: 15
Accepted
time: 6ms
memory: 13716kb

input:

1000000 0 9823 627
01110001011101001100010011100101001011000011011110001101010000000101010111110111110010010001110100101001111000111100011101111001000000100111000010010100010101110110111110100010101010001110111001100011010001111000101010000110010010101110101010111110110001110111111000001110000110011...

output:

383638431

result:

ok 1 number(s): "383638431"

Test #22:

score: 0
Accepted
time: 6ms
memory: 14168kb

input:

1000000 456755 465755 982
0100111111100111100010100011110111111101011111101110010011101011110011111010110000110001101001011101000110111100110100101111101011111010101011101000011101100000000111000010101011011000111010101101111011100101010010000110101011110010101011111101110101100010000100001110000100...

output:

982882798

result:

ok 1 number(s): "982882798"

Test #23:

score: 0
Accepted
time: 3ms
memory: 5628kb

input:

1000 0 1000 999999
11101000001100101110100011011111010000110101000000010101111010110110100110000001101110100011010111001000000010110101110001010111101000100010010010110000000001011110010010101111110000100001000111000010110001100100011100001000111001110110001010100000110110000110001111101101000010111...

output:

337235666

result:

ok 1 number(s): "337235666"

Test #24:

score: 0
Accepted
time: 6ms
memory: 13792kb

input:

1000000 990001 1000000 999
110110000110101111001000001001011000010000101001111110001101100011001001111001010001110110010111110100000101110000101101000111001100010100010100001001001011011100001010111100110110011001110010001110011001111100011001100111110000111011011100100100011111101100011000100011011...

output:

794028825

result:

ok 1 number(s): "794028825"

Subtask #8:

score: 15
Accepted

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Dependency #5:

100%
Accepted

Dependency #6:

100%
Accepted

Dependency #7:

100%
Accepted

Test #25:

score: 15
Accepted
time: 542ms
memory: 14204kb

input:

1000000 1 999999 632
111111100000011110001111101100010010111100000010101111111001010001101011101110001010010101001000111110101010100010011001101111011111011000011111011100101011110011000100100110111100101010000110010011110010111011001011001001001111000100000011101001100011011001100100011010000010100...

output:

610044514

result:

ok 1 number(s): "610044514"

Test #26:

score: 0
Accepted
time: 530ms
memory: 14920kb

input:

1000000 0 1000000 888
11011001110110111010100110110001000101110100001111110000011110101010110001100101010001110101010111001110100000110101000000011001111100100000010101100000011100110001011010110100001100111010100111011000110100100101110010100001100100000101000001101011010111001000101001110001111000...

output:

255140225

result:

ok 1 number(s): "255140225"

Test #27:

score: 0
Accepted
time: 529ms
memory: 14732kb

input:

1000000 0 1000000 1000
0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000...

output:

1066353724

result:

ok 1 number(s): "1066353724"

Test #28:

score: 0
Accepted
time: 1ms
memory: 5412kb

input:

100 0 100 9999999
1000101010111010100001001100001001100101000000111000000000111010000000000000101001110011001000111011

output:

583823543

result:

ok 1 number(s): "583823543"

Test #29:

score: 0
Accepted
time: 123ms
memory: 21404kb

input:

2000000 0 2000000 499
11100010011000101100101001000010010011110000000110011101001000100010101101010001011001001011100000111010100110011111001100100101000001000010010000000000011111011100100100110001110011101100110101001011011101001111010100010011001101111110110100010011110111010110100000101100101100...

output:

356463868

result:

ok 1 number(s): "356463868"

Test #30:

score: 0
Accepted
time: 116ms
memory: 23036kb

input:

2000000 0 2000000 499
00010101111100001110110010101100100111001010011100011011001100101001001111110001010011100000001101010001111000000010111011111110111010111010010010000011011110001110010000000000110000101110110101010011101101011001011001011110100010101000000011010100010010101000010111101110000111...

output:

111807544

result:

ok 1 number(s): "111807544"

Subtask #9:

score: 0
Time Limit Exceeded

Dependency #1:

100%
Accepted

Dependency #2:

100%
Accepted

Dependency #3:

100%
Accepted

Dependency #4:

100%
Accepted

Dependency #5:

100%
Accepted

Dependency #6:

100%
Accepted

Dependency #7:

100%
Accepted

Dependency #8:

100%
Accepted

Test #31:

score: 0
Time Limit Exceeded

input:

10000000 0 10000000 99
0011100100001001101101010011001111100000001110100000000100110100110110111110010010001001100100000111111100111100001110101001011101000101001001001010001011110101001101011001110011100011010101001101001111000010110011010000011011110110100001001101110111101101010011010011111111011...

output:


result: