HDU 5288 OO ' s Sequence

Source: Internet
Author: User

Test instructions: Given a sequence, the function f (l, R) indicates how many numbers in the [L, R] interval are not multiples of other numbers, and the sum of F (L, r) for all intervals.

Solution: First dozen more schools ... My heart is still a little excited ... But a check-in question did two things ... Woo-hoo ... Today's question is fairly simple ... Tomorrow will be more difficult ... Write a puzzle to commemorate the multi-school ...

For each number in the sequence, to find from its position to the left and right to find the furthest continuous can not be divisible by it the position of the number is set to L and R, the position of this number is POS, the answer is (pos-l + 1) * (R-pos + 1), as long as the analysis of the sample can be obtained this formula ... Then in order to find L and R, first preprocessing the multiples of each number, respectively, the positive and reverse sequence, each time the tag with the array update multiples corresponding to the factor position, and so on to this multiple can know the nearest factor position.

Code:

#include <stdio.h> #include <iostream> #include <algorithm> #include <string> #include < string.h> #include <math.h> #include <limits.h> #include <time.h> #include <stdlib.h># include<map> #include <queue> #include <set> #include <stack> #include <vector> #define LL  Long longusing namespace Std;vector <int> v[10005];int num[100005];const int mod = 1e9 + 7;void init () {for (int i = 1; i < 10005; i++) {for (int j = 1; J * J <= I; j + +) {if (i% J = = 0) {V[j].pu                Sh_back (i);            if (J * j! = i) v[i/j].push_back (i);    }}}}int s[10005], Flag[10005];int minn1[100005], Minn2[100005];int main () {int n;    Init ();        while (~SCANF ("%d", &n)) {for (int i = 0; i < n; i++) {scanf ("%d", &num[i]);        } int ans = 0; for (int i = 0; i < n; i++) {minn1[I] = n-1, minn2[i] = 0;        } memset (s, 0, sizeof s);        memset (flag, 0, sizeof flag);            for (int i = 0; i < n; i++) {int len = v[num[i]].size ();            Minn1[i] = s[num[i]];            if (Flag[num[i]]) minn1[i]++;                for (int j = 0; J < Len; J + +) {Flag[v[num[i]][j]] = 1;            S[V[NUM[I]][J]] = i;        }} for (int i = 0; i < 10005; i++) s[i] = n-1;        memset (flag, 0, sizeof flag);            for (int i = n-1; I >= 0; i--) {int len = v[num[i]].size ();            Minn2[i] = s[num[i]];            if (Flag[num[i]]) minn2[i]--;                for (int j = 0; J < Len; J + +) {Flag[v[num[i]][j]] = 1;            S[V[NUM[I]][J]] = i;            }} for (int i = 0; i < n; i++) {ans + = (I-minn1[i] + 1) * (Minn2[i]-i + 1)% MoD; if (Ans > moD) ans-= mod;    } printf ("%d\n", ans); } return 0;}

  

HDU 5288 OO ' s Sequence

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.