UOJ Logo

NOI.AC

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#213192#584. t3quliannanyishou05717ms70108kbC++113.4kb2024-11-09 22:42:222024-11-09 23:29:53

answer

#include <bits/stdc++.h>
using namespace std;
int m,n,a[100010],b,c,d,e,o[12][12],jc[12];
long long ans=0;
const int mod=1e9+7;
inline int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch<'0'||ch>'9')
    {
        if(ch=='-')
            f=-1;
        ch=getchar();
    }
    while(ch>='0' && ch<='9')
        x=x*10+ch-'0',ch=getchar();
    return x*f;
}
struct hh
{
	int lazy1;
	int lazy2=-1;
	long long val;
}t[11][100010<<2];
long long qp(int x,int y)
{
	long long ans=1,temp=x;
	while(y)
	{
		if(y&1)
		{
			ans=(ans*temp)%mod;
		}
		y>>=1;
		temp=(temp*temp)%mod;
	}
	return ans;
}
void build(int l,int r,int u)
{
	if(l==r)
	{
		for(int i=0;i<=10;++i)
		{
			t[i][u].val=qp(a[l],i);
		}
		return;
	}
	int mid=(l+r)/2;
	build(l,mid,u*2);
	build(mid+1,r,u*2+1);
	for(int i=0;i<=10;++i)
	{
		t[i][u].val=(t[i][u*2].val+t[i][u*2+1].val)%mod;
	}
}
void work(int kind,int u,int x)
{
	for(int i=1;i<=kind;++i)
	{
		t[kind][u].val=(t[kind][u].val+((o[kind][i]*qp(x,i))%mod*t[kind-i][u].val)%mod)%mod;
	}
}
void pushdown(int u,int l,int r)
{
	if(t[1][u].lazy2==-1&&!t[1][u].lazy1)
	{
		return;
	}
	for(int i=10;i>=0;--i)
	{
		if(t[i][u].lazy2!=-1)
		{
			t[i][u*2].lazy2=t[i][u].lazy2;
			t[i][u*2+1].lazy2=t[i][u].lazy2;
			t[i][u*2].lazy1=t[i][u].lazy1;
			t[i][u*2+1].lazy1=t[i][u].lazy1;
			t[i][u*2].val=qp(t[i][u].lazy2,i)*(r-l+1)%mod;
			t[i][u*2+1].val=qp(t[i][u].lazy2,i)*(r-l+1)%mod;
			work(i,u*2,t[i][u].lazy1);
			work(i,u*2+1,t[i][u].lazy1);
		}
		else
		{
			t[i][u*2].lazy1+=t[i][u].lazy1;
			t[i][u*2+1].lazy1+=t[i][u].lazy1;
			work(i,u*2,t[i][u].lazy1);
			work(i,u*2+1,t[i][u].lazy1);
		}
		t[i][u].lazy2=-1;
		t[i][u].lazy1=0;
	}
}
void change1(int u,int L,int R)
{
	if(L>=c&&R<=d)
	{
		for(int i=10;i>=0;--i)
		{
			work(i,u,e);
			t[i][u].lazy1+=e;
		}
		return;
	}
	int mid=(L+R)/2;
	if(c<=mid)
	{
		pushdown(u,L,R);
		change1(u*2,L,mid);
	}
	if(d>=mid+1)
	{
		pushdown(u,L,R);
		change1(u*2+1,mid+1,R);
	}
	for(int i=0;i<=10;++i)
	{
		t[i][u].val=(t[i][u*2].val+t[i][u*2+1].val)%mod;
	}
}
void change2(int u,int L,int R)
{
	if(L>=c&&R<=d)
	{
		for(int i=0;i<=10;++i)
		{
			t[i][u].val=qp(e,i)*(R-L+1)%mod;
			t[i][u].lazy2=e;
			t[i][u].lazy1=0;
		}
		return;
	}
	int mid=(L+R)/2;
	if(c<=mid)
	{
		pushdown(u,L,R);
		change2(u*2,L,mid);
	}
	if(d>=mid+1)
	{
		pushdown(u,L,R);
		change2(u*2+1,mid+1,R);
	}
	for(int i=0;i<=10;++i)
	{
		t[i][u].val=(t[i][u*2].val+t[i][u*2+1].val)%mod;
	}
}
void query(int u,int L,int R)
{
	if(L>=c&&R<=d)
	{
		ans=(ans+t[e][u].val)%mod;
		return;
	}
	int mid=(L+R)/2;
	if(c<=mid)
	{
		pushdown(u,L,R);
		query(u*2,L,mid);
	}
	if(d>=mid+1)
	{
		pushdown(u,L,R);
		query(u*2+1,mid+1,R);
	}
	for(int i=0;i<=10;++i)
	{
		t[i][u].val=(t[i][u*2].val+t[i][u*2+1].val)%mod;
	}
}
int main()
{
	m=read();
	n=read();
	for(int i=1;i<=m;++i)
	{
		a[i]=read();
	}
	jc[0]=o[0][0]=1;
	for(int i=1;i<=10;++i)
	{
		jc[i]=jc[i-1]*i;
	}
	for(int i=1;i<=10;++i)
	{
		for(int j=i;j>=0;--j)
		{
			o[i][j]=jc[i]/jc[j]/jc[i-j];
		}
	}
	build(1,m,1);
	for(int i=1;i<=n;++i)
	{
		b=read();
		c=read();
		d=read();
		e=read();
		if(b==1)
		{
			pushdown(1,1,m);
			change1(1,1,m);
		}
		else if(b==2)
		{
			pushdown(1,1,m);
			change2(1,1,m);
		}
		else
		{
			ans=0;
			pushdown(1,1,m);
			query(1,1,m);
			printf("%ld\n",ans);
		}
	}
}

Details

小提示:点击横条可展开更详细的信息

Test #1:

score: 0
Wrong Answer
time: 15ms
memory: 69912kb

input:

458 823
14431 9895 11970 15308 2575 20181 709 27999 12992 18884 11061 16281 5044 28990 25092 28337 3...

output:

806084096
117884357
666037881
287355913
887064912
639885729
734149970
762985600
410530445
89040104
8...

result:

wrong answer 3rd lines differ - expected: '581509507', found: '666037881'

Test #2:

score: 0
Wrong Answer
time: 11ms
memory: 69912kb

input:

481 526
8409 14498 18636 10027 24362 32458 17986 17730 11956 19192 2193 1034 29317 19284 16210 26242...

output:

433393713
717265913
275396376
424410861
249
692955230
770792220
774894526
19973146
468950272
4036568...

result:

wrong answer 1st lines differ - expected: '867105097', found: '433393713'

Test #3:

score: 0
Time Limit Exceeded

input:

100000 100000
15247 4194 9619 4532 22058 2667 21549 16652 25327 12018 13395 11426 7243 11714 22904 2...

output:

54433
544457741
352487648
82525935
554312304
356782578
59973
60091440
38279
880772184
48897
76936962...

result:


Test #4:

score: 0
Time Limit Exceeded

input:

100000 100000
6264 26207 28424 24165 4852 20798 5803 18679 24588 12238 25786 28622 19900 101 25922 2...

output:

18923
26223345
57124
55088
64182
139836
618709032
19955
838216228
36693
877430755
86204949
6279
5085...

result:


Test #5:

score: 0
Time Limit Exceeded

input:

100000 100000
15043 9299 7163 25384 24996 3803 24356 12466 22073 12987 8931 14997 3951 32704 23076 8...

output:

927221841
12594
932255856
779074579
335564192
1368
960714849
117570
111671
33828
350444218
6417
6627...

result:


Test #6:

score: 0
Time Limit Exceeded

input:

100000 100000
14736 16956 19864 23894 29403 5507 12182 6188 17192 14440 18618 3970 15396 15037 23334...

output:

17008
73008
245386275
161341803
19830
50466
347255152
138551
33752
56548
407565443
298062190
4931776...

result:


Test #7:

score: 0
Wrong Answer
time: 3120ms
memory: 70108kb

input:

50000 50000
17799 29763 25337 21321 1391 31852 27418 28753 18524 14044 15976 18893 12274 22834 11348...

output:

19498
473297203
374109381
299749756
810914702
262358504
838433856
696804618
784858637
113094028
5004...

result:

wrong answer 3rd lines differ - expected: '695948777', found: '374109381'

Test #8:

score: 0
Wrong Answer
time: 2571ms
memory: 70108kb

input:

50000 50000
10654 14956 14287 25326 8102 30579 11682 23553 272 22672 14460 30241 13026 12738 4912 72...

output:

704611705
215869428
402361569
67128905
984996330
820518682
20757
7418
40775857
229278069
444002353
9...

result:

wrong answer 1st lines differ - expected: '717018991', found: '704611705'

Test #9:

score: 0
Time Limit Exceeded

input:

90000 90000
29538 28214 24706 30393 27759 9002 13458 10243 15713 14881 10630 5593 7942 24578 29370 1...

output:

738835738
961395102
7775
597370354
64402
360126347
393187978
932214066
257908585
330816812
184332256...

result:


Test #10:

score: 0
Time Limit Exceeded

input:

100000 100000
23515 49 31372 25112 16779 21279 30735 32743 14678 15189 1763 23114 32215 14873 20487 ...

output:

576735050
562509678
416932479
324346197
191245996
145700530
879269281
619865511
120769728
849407635
...

result: