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