首页 > 其他分享 >HDU 5496 Beauty of Sequence

HDU 5496 Beauty of Sequence

时间:2022-11-09 20:01:09浏览次数:49  
标签:HDU Beauty sequence int base maxn test 5496 now


Problem Description


Sequence is beautiful and the beauty of an integer sequence is defined as follows: removes all but the first element from every consecutive group of equivalent elements of the sequence (i.e. unique function in C++ STL) and the summation of rest integers is the beauty of the sequence.

Now you are given a sequence HDU 5496	 Beauty of Sequence_HDU of HDU 5496	 Beauty of Sequence_#include_02 integers HDU 5496	 Beauty of Sequence_HDU_03. You need find the summation of the beauty of all the sub-sequence of HDU 5496	 Beauty of Sequence_HDU. As the answer may be very large, print it modulo HDU 5496	 Beauty of Sequence_ios_05.

Note: In mathematics, a sub-sequence is a sequence that can be derived from another sequence by deleting some elements without changing the order of the remaining elements. For example HDU 5496	 Beauty of Sequence_i++_06 is a sub-sequence of HDU 5496	 Beauty of Sequence_#include_07.


Input



There are multiple test cases. The first line of input contains an integer HDU 5496	 Beauty of Sequence_i++_08, indicating the number of test cases. For each test case:

The first line contains an integer HDU 5496	 Beauty of Sequence_#include_02 HDU 5496	 Beauty of Sequence_HDU_10, indicating the size of the sequence. The following line contains HDU 5496	 Beauty of Sequence_#include_02 integers HDU 5496	 Beauty of Sequence_i++_12, denoting the sequence HDU 5496	 Beauty of Sequence_i++_13.

The sum of values HDU 5496	 Beauty of Sequence_#include_02 for all the test cases does not exceed HDU 5496	 Beauty of Sequence_i++_15.


Output



For each test case, print the answer modulo HDU 5496	 Beauty of Sequence_ios_05


Sample Input


3
5
1 2 3 4 5
4
1 2 1 3
5
3 3 2 1 2


Sample Output

240
54

144


找到递推方法然后就好了。。。

#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
#include<iostream>
using namespace std;
typedef long long LL;
const int maxn = 300005;
const LL base = 1e9 + 7;
int T, n, m, a[maxn], b[maxn], c[maxn];
LL now, bef, f[maxn], sum[maxn], tot;

int main()
{
scanf("%d", &T);
while (T--)
{
scanf("%d", &n); tot = 0;
for (int i = 1; i <= n; i++)
{
scanf("%d", &a[i]);
b[i] = a[i];
sum[i] = f[i] = 0;
}
sort(b + 1, b + n + 1);
m = unique(b + 1, b + n + 1) - b;
now = 1;
for (int i = 1; i <= n; i++) c[i] = lower_bound(b + 1, b + m, a[i]) - b;
for (int i = 1; i <= n; i++)
{
bef = (now - f[c[i]] + base) % base*a[i] % base;
(f[c[i]] += now) %= base;
(sum[c[i]] += tot + bef) %= base;

((tot <<= 1) += bef) %= base;
(now <<= 1) %= base;
}
printf("%I64d\n", tot);
}
return 0;
}



标签:HDU,Beauty,sequence,int,base,maxn,test,5496,now
From: https://blog.51cto.com/u_15870896/5838706

相关文章

  • HDU 5433 Xiao Ming climbing
    ProblemDescriptionDuetothecursemadebythedevil,XiaoMingisstrandedonamountainandcanhardlyescape.Thismountainisprettystrangethat......
  • HDU 1542 Atlantis
    ProblemDescriptionThereareseveralancientGreektextsthatcontaindescriptionsofthefabledislandAtlantis.Someofthesetextsevenincludemaps......
  • HDU 3308 LCIS
    ProblemDescriptionGivennintegers.Youhavetwooperations:UAB:replacetheAthnumberbyB.(indexcountingfrom0)QAB:outputthelength......
  • HDU 5874 Friends and Enemies
    ProblemDescriptionOnanisolatedisland,livedsomedwarves.Aking(notadwarf)ruledtheislandandtheseasnearby,thereareabundantcobblestones......
  • HDU 5876 Sparse Graph
    ProblemDescriptioncomplement ofagraph G isagraph H onthesameverticessuchthattwodistinctverticesof H areadjacentifand......
  • HDU 5877 Weak Pair
    ProblemDescriptionrooted treeof N nodes,labeledfrom1to N.Tothe ithnodeanon-negativevalue ai isassigned.An order......
  • HDU 5875 Function
    ProblemDescriptionTheshorter,thesimpler.Withthisproblem,youshouldbeconvincedofthistruth.    Youaregivenanarray A of ......
  • HDU 5320 Fan Li
    DescriptionFanLi(范蠡)wasanancientChineseadvisorinthestateofYueintheSpringandAutumnperiod.Heisasuccessfulmilitaristandasuccessf......
  • HDU 5399 Too Simple
    ProblemDescriptionRhasonCheunghadasimpleproblem,andaskedTeacherMaiforhelp.ButTeacherMaithoughtthisproblemwastoosimple,sometimesna......
  • HDU 5402 Travelling Salesman Problem
    ProblemDescriptionn rowsand m columns.Thereisanon-negativenumberineachcell.TeacherMaiwantstowalkfromthetopleftcorner (1,1......