51nod-1285 Peaks and segments

Source: Internet
Author: User

Topic Links: 1285 peaks and segments

Idea: Enumerate the factors of n, and then check that each section has a mountain. Use RMQ when checking. Preprocessing time complexity is O (NLOGN), the total complexity is so much.

There is a solution to the O (n), but it is not.

1#include <bits/stdc++.h>2 using namespacestd;3 4std::vector<int>v;5 Const intMAXN = 5e4 + -;6 BOOLs[maxn][ -];7 intN, t;8 voidRMQ () {9      for(intI=1; i< -; i++) {Ten          for(intj=1; j<=n; J + +) { One             if(J+ (1<< (I-1)) <= n) s[j][i] = s[j][i-1] || s[j+ (1<< (I-1))][i-1]; A         } -     } - } the BOOLQueryintLintLen) { -     intT = (int) log2 (len+0.5); -     returnS[l][t] | | s[l+len-(1<<T)] [t]; - } +std::vector<int> FAC (intN) { -std::vector<int>VV; +      for(intI=1; i*i<=n; i++) { A         if(n%i==0) { at Vv.push_back (i); -             if(i*i!=n) Vv.push_back (n/i); -         } -     } - sort (Vv.begin (), Vv.end ()); -     returnVV; in } - intMain () { tomemset (s),0,sizeof(s)); +scanf"%d", &n); -      for(intI=0; i<n; i++) { thescanf"%d", &t); * V.push_back (t); $     }Panax Notoginseng      for(intI=1; i<n-1; i++) { -         if(V[i] > v[i-1] && V[i] > v[i+1]) s[i+1][0] =true; the     } + RMQ (); A     BOOLOK =false; the     intAns =0; +std::vector<int> VV =FAC (n); -      for(intI=0; I<vv.size (); i++) { $         BOOLOok =true; $         intLen =Vv[i]; -          for(intj=1; j<n; j+=Len) { -             if(!query (J, Len)) { theOok =false; Break; -             }Wuyi         } the         if(ook) OK =true; -         if(OK) { Wuans = n/len; Break; -         } About     } $printf"%d\n", ans); -     return 0; -}

51nod-1285 Peaks and segments

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.