标签:line eof let tmp put tle form long creat
#include <iostream> #include <algorithm> #include <cstring> #include <cstdio> using namespace std; typedef long long LL; LL lowbit(LL x) { return x&(-x); } LL query(LL x,LL n) { LL ans=0; while(x<=n) { ans++; x+=lowbit(x); } return ans; } LL cal(LL x) { LL ans=0; LL tmp=1; for(LL i=0; tmp<=x; i++) ans+=(x/(tmp)-x/(tmp<<1))*tmp,tmp<<=1; return ans; } int main() { LL n,q; while(scanf("%lld%lld",&n,&q)!=EOF) { while(q--) { int op; scanf("%d",&op); if(op==1) { LL x,y; scanf("%lld%lld",&x,&y); LL ans=cal(y)-cal(x-1); printf("%lld\n",ans); } else { LL x; scanf("%lld",&x); LL ans=query(x,n); printf("%lld\n",ans); } } } return 0; }
hdu 5975---Aninteresting game(树状数组)
标签:line eof let tmp put tle form long creat
原文地址:http://www.cnblogs.com/chen9510/p/6953494.html