Codeforces Round #619 (Div. 2) C. Ayoub's function

When looking for matches at zero law found substring and comprising a number of sub-strings = number behind its nearest 1 starting from seasonal and m = 1 k = (n + 1) / 2 (/ is divisible) answers to k * (n + 1-k)

But I did not expect regular difficult the contrary, in other words with respect irrespective containing exon 1 of the string number ($ \ frac {n (n + 1)} {2} $) reduces the location of the 0 location to its distance behind his recent from 1

And m is a number 0 1 nm can be divided into m + 1 segments intuitive sense to try to average 0

Strict Proof: Since $ \ frac {x (x + 1)} {2} $ is a concave function, the Jensen Inequality has $ f \ left (\ frac {x1 + x2 + ... + xn} {n} \ right) \ leq \ frac {f (x1) + f (x2) + ... + f (xn))} {n} $

Transposition have $ nf \ left (\ frac {x1 + x2 + ... + xn} {n} \ right) \ leq f (x1) + f (x2) + ... + f (xn) $ it will be possible 0 evenly divided

 

 

#include<bits/stdc++.h>
#define ll  long long
using namespace std;
//const int N=e+5;

int main(){
    int T;
    ios::sync_with_stdio(false);cin.tie(0);
    cin>>T;
    while(T--){
        int n,m;
        cin>>n>>m;
        int k1=(n-m)/(m+1),k2=(n-m)%(m+1);
        cout<<1ll*n*(n+1)/2-1ll*(m+1)*k1*(k1+1)/2-1ll*k2*(k1+1)<<endl;//必须每项都先乘1ll
  }
    return 0;
}

 

Guess you like

Origin www.cnblogs.com/wyh447154317/p/12307633.html