B Beauty Values 2019 cattle off summer school more than an eighth field (law)

Link to the original question: Beauty Values

Meaning of the questions : to give you a sequence, so that you find the number of the sum of all the different numbers of sub-intervals of
thinking : Some people like me think of the first time counting the number of different kind of chairman statistical interval (.. Well on when I do), but to see so many people in the standings over how to say it will not want to go down there, and certainly there is a pattern.
I found a number of intervals in the range of contributions to the analysis of this zone a different number of times. For example swatch 1213 we see that the second one in the interval [2,4] and subranges thereof when considered in a number of statistical contribution
that a large section of the same numbers from the right and left ends thereof Operator a contribution (1 does not affect other sections), then we think this post will find a greater range if, for example, [1,4] who should be considered a contribution.

In fact, we can be counted as contributions to the leftmost or rightmost range of value generated. We fixed a press to produce the contribution of the left-most (so as not to repeat statistics)
i.e., the value of a position pos which contribute to the range of the interval [i + 1, n] (i is a position of occurrence, n is an length). Then count the number of subintervals. Thus we see the 1213 contributions calculated value, that is [2,4] of the second one, [2,3], [3,4], [3,3]

So we find immediate left of the breakpoint in the [i + 1, pos] between the right endpoints between [pos, n]. So finally we can get the relationship :( pos - i) * (n - pos + 1) // where the subscript I is from 1 to start recording, the left endpoint is set to 0

I like this chicken dish so simple estimate will put detailed explanations wrote it ... TAT

code:

#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn = 1e5+5;
ll arr[maxn];
int cur[maxn];
ll ans;
int main(){
    int n;
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>arr[i];
    }
    ll L;
    ans = 0;
    memset(cur,0,sizeof(cur));
    for(int i=1;i<=n;i++){
        ans += (ll)(i-cur[arr[i]]) * (n-i+1);
        cur[arr[i]] = i;
    }
    cout<<ans<<endl;
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/Tianwell/p/11367072.html