-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDCEPC206.cs
58 lines (55 loc) · 1.38 KB
/
DCEPC206.cs
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
45
46
47
48
49
50
51
52
53
54
55
56
57
using System;
using System.Collections.Generic;
using System.Text;
namespace AlgoSolution
{
class DCEPC206
{
static long[] tree;
static void Update(int idx, int val, int maxVal)
{
while (idx <= maxVal)
{
tree[idx] += val;
idx += (idx & -idx);
}
}
static long Sum(int idx)
{
long sum = 0;
while (idx > 0)
{
sum += tree[idx];
idx -= (idx & -idx);
}
return sum;
}
static void Main()
{
Run();
Console.ReadLine();
}
static void Run()
{
int t = int.Parse(Console.ReadLine());
while (t > 0)
{
int n = int.Parse(Console.ReadLine());
tree = new long[1000001];
string[] str = Console.ReadLine().Split();
long totalSum = 0;
for (int i = 0; i < n; i++)
{
int num = int.Parse(str[i]);
if (num > 0)
{
Update(num, num, 1000001);
totalSum += Sum(num - 1);
}
}
Console.WriteLine(totalSum);
t--;
}
}
}
}