题目链接
- 像这样的操作密集型题目,需要你细致入微的演算来领会题目的本质,而不是居高临下地“运筹帷幄”,并始终保持理智。诚然,这样的题目在区域赛中并不多见,但并不代表不会出现,一旦出现,就有可能成为你的阿喀琉斯之踵
点击查看代码
#include <bits/stdc++.h>
using namespace std;
const int mod=1000000007;
long long a[200005],b[200005],c[200005];
long long suma[200005],sumb[200005],cnt[200005];
stack<long long>B,C;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int T;
cin>>T;
while(T--)
{
int n;
cin>>n;
for(int i=1;i<=n;i++)
{
cin>>a[i];
c[i]=0;
b[i]=a[i];
while(b[i]%2==0)
{
b[i]/=2;
c[i]++;
}
suma[i]=suma[i-1]+a[i];
sumb[i]=sumb[i-1]+b[i];
cnt[i]=cnt[i-1]+c[i];
}
long long ans=0;
while(B.size())
{
B.pop();
C.pop();
}
for(int i=1;i<=n;i++)
{
if(i!=1)
{
cout<<" ";
}
bool f=false;
while(!B.empty())
{
if(f==true||a[i]>B.top())
{
ans=ans-B.top()*power(2,C.top())%mod+B.top();
ans%=mod;
if(C.top()>=30)
{
f=true;
}
a[i]=a[i]*power(2,C.top());
if(a[i]>1000000000)
{
f=true;
}
a[i]%=mod;
c[i]+=C.top();
B.pop();
C.pop();
}
else
{
break;
}
}
ans=(ans+a[i])%mod;
B.push(b[i]);
C.push(c[i]);
cout<<(ans+mod)%mod;
}
cout<<"\n";
}
return 0;
}