QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#22935 | #2890. 线段树 | WhybullYMe# | AC ✓ | 21ms | 9236kb | C++20 | 2.4kb | 2022-03-11 11:29:15 | 2022-04-30 02:08:54 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define ri int
typedef long long ll;
const int mod=1e9+7;
template<class T>inline bool ckmin(T &x,const T &y){return x>y?x=y,1:0;}
template<class T>inline bool ckmax(T &x,const T &y){return x<y?x=y,1:0;}
template<class T>inline void clear(T *arr,int siz,int val=0){memset(arr,val,sizeof(T)*(siz+1));}
struct modint{
int val;
inline modint(int val_=0):val(val_){}
inline modint &operator=(int val_){return val=val_,*this;}
inline modint &operator+=(const modint &k){return val=val+k.val>=mod?val+k.val-mod:val+k.val,*this;}
inline modint &operator-=(const modint &k){return val=val-k.val<0?val-k.val+mod:val-k.val,*this;}
inline modint &operator*=(const modint &k){return val=1ll*val*k.val%mod,*this;}
inline modint &operator^=(int k){
modint ret=1,tmp=*this;
for(;k;k>>=1,tmp*=tmp)if(k&1)ret*=tmp;
return val=ret.val,*this;
}
inline modint &operator/=(modint k){return *this*=(k^=mod-2);}
inline modint &operator+=(int k){return val=val+k>=mod?val+k-mod:val+k,*this;}
inline modint &operator-=(int k){return val=val<k?val-k+mod:val-k,*this;}
inline modint &operator*=(int k){return val=1ll*val*k%mod,*this;}
inline modint &operator/=(int k){return *this*=((modint(k))^=mod-2);}
template<class T>friend modint operator+(modint a,T b){return a+=b;}
template<class T>friend modint operator-(modint a,T b){return a-=b;}
template<class T>friend modint operator*(modint a,T b){return a*=b;}
template<class T>friend modint operator^(modint a,T b){return a/=b;}
template<class T>friend modint operator/(modint a,T b){return a/=b;}
friend modint operator^(modint a,int b){return a^=b;}
friend bool operator==(modint a,int b){return a.val==b;}
friend bool operator!=(modint a,int b){return a.val!=b;}
inline bool operator!(){return !val;}
inline modint operator-(){return val?mod-val:0;}
inline modint &operator++(){return *this+=1;}
};
using mi=modint;
struct node{mi ans,l,r;};
unordered_map<ll,node>p;
node dfs(ll n){
if(p.count(n))return p[n];
node &cur=p[n],ls=dfs(n>>1),rs=dfs(n-(n>>1));
cur.ans=ls.ans+rs.ans+ls.r*((n-(n>>1))%mod)+rs.l*((n>>1)%mod)-1;
cur.l=ls.l+rs.l+((n-(n>>1))%mod)-1,cur.r=rs.r+ls.r+((n>>1)%mod)-1;
return cur;
}
ll n;
int t_case;
int main(){
p[1]={1,1,1};
scanf("%d",&t_case);
while(t_case--){
scanf("%lld",&n);
printf("%d\n",dfs(n).ans);
}
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 21ms
memory: 9236kb
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