-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path28.cpp
More file actions
44 lines (40 loc) · 630 Bytes
/
28.cpp
File metadata and controls
44 lines (40 loc) · 630 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#include<bits/stdc++.h>
using namespace std;
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin.tie(NULL);
int t;
cin>>t;
while(t--)
{
int n;
cin>>n;
int a[100000] = {0};
int b[n];
for(int i = 0;i<n;i++)
{
cin>>b[i];
}
unsigned long int sum = 0;
int count = 0;
for(int i = n-1;i>=0;i--)
{
if(a[b[i]]==0)
{
count++;
sum = sum + b[i]*count;
a[b[i]] = 1;
}
else
{
count = 1;
a[100000] = {0};
sum = sum + b[i]*count;
a[b[i]]=1;
}
}
cout<<sum<<"\n";
}
}