Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:O(sqrt(y))的复杂度TLE,O(log(y)*log(y))复杂度AC

Posted by tasty at 2013-04-28 23:21:22 on Problem 3495
In Reply To:O(sqrt(y))的复杂度TLE,O(log(y)*log(y))复杂度AC Posted by:tasty at 2013-04-28 23:20:26
> RT
代码:
Source Code

Problem: 3495  User: tasty 
Memory: 164K  Time: 32MS 
Language: C++  Result: Accepted 

Source Code 
#include <vector> 
#include <map> 
#include <set> 
#include <algorithm> 
#include <sstream> 
#include <iostream> 
#include <iomanip> 
#include <cstdio> 
#include <cmath> 
#include <cstdlib> 
#include <cctype> 
#include <string> 
#include <cstring> 
#include <ctime> 
#include <string.h> 
using namespace std;
long long x,y,z,ans;
long long fun(long long x,long long a,long long b,long long n)
{
     long long res=0,k=(a/b)&1;
     if(n<0)
         return 0;
     a=a%b;
     if(n&1)
        res=(((n+1)/2)&1);
     else
        res=((n/2)&1);
     res=(res*k)&1;
     if(a==0)
     {
         res+=((x/b)&1)*((n+1)&1);
         res&=1;
         return res;
     }
     res+=((x/b)&1)+(n&1)*(((x+n*a)/b)&1)+fun(b-x%b-1,b,a,(x+n*a)/b-x/b-1);
     return res&1;
}
int main()
{
    int i,j,s,p,q;
    long long k;
    while(scanf("%lld%lld%lld",&x,&y,&z)==3)
    {
         ans=0;
         k=(y-x)/z;
         for(i=0;((long long)1<<(long long)i)<=y;i++)
              ans+=fun(x,z,(long long)1<<(long long)i,k)*((long long)1<<(long long)i);
         printf("%lld\n",ans);
    }
    return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator