标签:tac stack turn source clu multiple tle miss ring
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 670 Accepted Submission(s): 235
#include<iostream> #include<cstdio> #include<cmath> #include<cstring> #include<algorithm> #include<set> #include<bitset> #include<map> #include<queue> #include<stack> #include<vector> using namespace std; typedef long long ll; typedef pair<int,int> P; #define bug(x) cout<<"bug"<<x<<endl; #define PI acos(-1.0) #define eps 1e-8 const int N=2e5+100,M=1e5+100; const int inf=0x3f3f3f3f; const ll INF=1e18+7,mod=1e9+7; ll n; char s[100]; map<ll,ll> vis,deep; ll getnum(ll tmp) { ll ans=0; while(tmp<=n) { if(deep.find(tmp)!=deep.end()) return ans+deep[tmp]; if(vis.find(tmp)==vis.end()) ans+=tmp; else ans+=vis[tmp]; ll tmp1=tmp<<1,tmp2=tmp<<1|1; int h1=0,h2=0; while(tmp1<=n) tmp1=tmp1<<1,h1++; while(tmp2<=n) tmp2=tmp2<<1,h2++; if(h1==h2) tmp=tmp<<1|1; else tmp=tmp<<1; } return ans; } void getchild(ll u,ll &ch1,ll &ch2) { ch1=getnum(u<<1),ch2=getnum(u<<1|1); } int main() { int m; while(scanf("%lld%d",&n,&m)!=EOF) { vis.clear(),deep.clear(); for(int i=1; i<=m; i++) { ll u,x; scanf("%s %lld",s,&u); if(s[0]==‘c‘) { scanf("%lld",&x); vis[u]=x; while(u>=1) { ll ch1,ch2; getchild(u,ch1,ch2); if(vis.find(u)==vis.end()) deep[u]=max(ch1,ch2)+u; else deep[u]=max(ch1,ch2)+vis[u]; u/=2; } } else { ll ch1,ch2; getchild(u,ch1,ch2); u=ch1>ch2?(u<<1):(u<<1|1); ll cou=max(ch1,ch2); ll ans=0; while(u>1) { if(vis.find(u/2)==vis.end()) cou+=u/2; else cou+=vis[u/2]; ans=max(ans,getnum(u^1)+cou); u/=2; } printf("%lld\n",ans); } } } return 0; }
标签:tac stack turn source clu multiple tle miss ring
原文地址:http://www.cnblogs.com/GeekZRF/p/7606236.html