Codeforces Round #305 (Div. 1) A. B .C solution report

Source: Internet
Author: User
Tags acos

Codeforces Round #305 (Div. 1) A. B .C solution report

A. Mike and Frog
Enumeration.
First, find the loop, and then it is easy to get a two-element equation, and then we can find that the solution also has a circular section, so the smallest one must appear within a certain range, otherwise it will not appear in the future. Assume that the two variables are x and y, and the coefficients are z1 and Z2. Obviously, the minimum public multiple of the two is a cycle, so if you enumerate x, you only need to enumerate to Z2.
There are many details .. It is wrong many times .. The competition also broke down ..
The Code is as follows:

#include 
  
   #include 
   
    #include 
    
     #include 
     
      #include #include 
      
       #include
       #include 
        
         #include 
         
          using namespace std;#define LL __int64#define pi acos(-1.0)#define root1 0, 1000001, 1#define lson l, mid, rt<<1#define rson mid+1, r, rt<<1|1//#pragma comment(linker, "/STACK:1024000000")const int mod=1e4+7;const int INF=0x3f3f3f3f;const double eqs=1e-3;const int MAXN=600000+10;int a[MAXN], c[20], ha[MAXN], vis[MAXN];LL Cal(int x, int f){ int i, cnt=0, tmp, tot, y, j; LL ans=0; for(i=2;i*i<=x;i++){ if(x%i==0){ while(x%i==0) x/=i; c[cnt++]=i; } } if(x!=1) c[cnt++]=x; tot=1<
          
         
        
      
     
    
   
  

B. Mike and Feet
Monotonous stack (or line segment tree)
The general idea of this question is very easy, that is, to find the maximum range of each number extending to the left to the right as the minimum value, then all the values in this range may use this minimum value as the maximum value, so you can mark the maximum value of the prefix with the TAG method.
Then you can find the extended range. Weak thinking only refers to the omnipotent idea Of discretization + line segment tree. It is not very troublesome, but the complexity is slightly higher. Another simpler method is the monotonous stack concept. The complexity is not only low, but only O (n). The Code complexity is also low. The monotonous stack is used to ensure that the stack is always increasing, so the bottom of the stack is the maximum extension range. Here we only post the idea of Line Segment tree, which is also written during the weak competition.
This is because two n pairs are defined during the competition .. Debugging took nearly an hour... Time is wasted on this ....
The Code is as follows:

#include  #include  #include  #include  #include #include  #include #include  #include  using namespace std;#define LL __int64#define pi acos(-1.0)#define root 0, cnt-1, 1#define lson l, mid, rt<<1#define rson mid+1, r, rt<<1|1//#pragma comment(linker, "/STACK:1024000000")const int mod=1e4+7;const int INF=0x3f3f3f3f;const double eqs=1e-3;const int MAXN=200000+10;int dp[MAXN], b[MAXN], ans[MAXN], a[MAXN], c[MAXN], cnt, fro[MAXN], last[MAXN], n;int Max[800000], Min[800000];int BS(int x){ int low=0, high=cnt-1, mid; while(low<=high){ mid=low+high>>1; if(c[mid]==x) return mid; else if(c[mid]>x) high=mid-1; else low=mid+1; }}void PushUp(int rt){ Max[rt]=max(Max[rt<<1],Max[rt<<1|1]); Min[rt]=min(Min[rt<<1],Min[rt<<1|1]);}void Update(int p, int x, int l, int r, int rt){ if(l==r){ Max[rt]=Min[rt]=x; return ; } int mid=l+r>>1; if(p<=mid) Update(p,x,lson); else Update(p,x,rson); PushUp(rt);}int Query(int f, int ll, int rr, int l, int r, int rt){ if(ll<=l&&rr>=r){ if(f) return Max[rt]; return Min[rt]; } int mid=l+r>>1, ans; if(f) ans=-1; else ans=n; if(f){ if(ll<=mid) ans=max(ans,Query(f,ll,rr,lson)); if(rr>mid) ans=max(ans,Query(f,ll,rr,rson)); } else{ if(ll<=mid) ans=min(ans,Query(f,ll,rr,lson)); if(rr>mid) ans=min(ans,Query(f,ll,rr,rson)); } return ans;}int main(){ int i, j, x; while(scanf("%d",&n)!=EOF){ for(i=0;i  =0;i--){ x=BS(a[i]); if(x==0) last[i]=n; else last[i]=Query(0,0,x-1,root); Update(x,i,root); } memset(dp,0,sizeof(dp)); memset(ans,0,sizeof(ans)); int tmp; for(i=0;i  =1;i--){ ans[i]=max(ans[i+1],dp[i]); } for(i=1;i<=n;i++){ printf("%d ",ans[i]); } puts(""); } return 0;}         

C. Mike and Foam
Pressure + rejection
It's easy to think clearly about this question... That is, the number of quality factors of any number in the range of 5*10 ^ 5 will not exceed 6 .. As long as you think of this, it will be very simple. If you press it and then let it go, you can solve it.
The Code is as follows:

#include  #include  #include  #include  #include #include  #include #include  #include  using namespace std;#define LL __int64#define pi acos(-1.0)#define root1 0, 1000001, 1#define lson l, mid, rt<<1#define rson mid+1, r, rt<<1|1//#pragma comment(linker, "/STACK:1024000000")const int mod=1e4+7;const int INF=0x3f3f3f3f;const double eqs=1e-3;const int MAXN=600000+10;int a[MAXN], c[20], ha[MAXN], vis[MAXN];LL Cal(int x, int f){ int i, cnt=0, tmp, tot, y, j; LL ans=0; for(i=2;i*i<=x;i++){ if(x%i==0){ while(x%i==0) x/=i; c[cnt++]=i; } } if(x!=1) c[cnt++]=x; tot=1<        

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.