QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#830011#2890. 线段树lyxAC ✓102ms21272kbC++14860b2024-12-24 15:28:182024-12-24 15:28:21

Judging History

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

  • [2024-12-24 15:28:21]
  • 评测
  • 测评结果:AC
  • 用时:102ms
  • 内存:21272kb
  • [2024-12-24 15:28:18]
  • 提交

answer

#include<bits/stdc++.h>
#define ll long long
#define rll register ll
#define ri register int
#define fo(i,x,y) for(ri i=(x);i<=(y);++i)
#define fu(i,x,y) for(ri i=(x);i<(y);++i)
#define fd(i,x,y) for(ri i=(x);i>=(y);--i)
#define pb push_back
#define pii pair<int,int>
#define fi first
#define se second
using namespace std;
const int N=1e5+5,p=1e9+7;
int T;ll n;
map<ll,int>f,pre,suf;
//int f[N],pre[N],suf[N];
inline void dfs(rll n){
	if(f[n])return;
	rll r=n/2,l=n-r;
	dfs(l);dfs(r);
	f[n]=(((f[l]+f[r])%p+1ll*r%p*suf[l]%p)%p+1ll*l%p*pre[r]%p-1)%p;
	(f[n]+=p)%=p;
	pre[n]=1ll*(pre[l]+r-1+pre[r])%p;
	suf[n]=1ll*(suf[r]+l-1+suf[l])%p;
}
int main(){
	scanf("%d",&T);
	f[1]=pre[1]=suf[1]=1;
	while(T--){
		scanf("%lld",&n);
		dfs(n);
		printf("%d\n",f[n]);
	}
	cerr<<endl<<endl<<"time:"<<(double)clock()/CLOCKS_PER_SEC<<endl;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 102ms
memory: 21272kb

input:

1000
801549136054373846
392582033805179557
511878130372372526
257940111599777085
892475885170687386
927426094533677854
809316024616696758
904026570459712740
528493133557481688
346972671880529150
563620129550373847
19946657724248713
972555064613600065
138484386550578709
22776759613052249
120476346103...

output:

885946835
744834497
838758522
261969557
605170720
993103931
504548685
555074779
845340557
705544651
902040239
367039298
808204215
482693693
808469119
640136512
624426436
937385148
603485378
866989808
66727680
677225168
429786577
789510234
108145686
744872604
488130173
793078366
348736331
990718224
3...

result:

ok 1000 lines