Submission #265368

# Submission time Handle Problem Language Result Execution time Memory
265368 2020-08-14T16:42:00 Z T0p_ Mountains (NOI20_mountains) C++14
100 / 100
409 ms 29684 KB
#include<bits/stdc++.h>
using namespace std;

#define pb push_back

long long arr[300300], fw[2][300300];
vector<long long> v;
unordered_map<long long, int> com;

void update(int idx1, int idx2, int val)
{
	while(idx2 <= 300000)
	{
		fw[idx1][idx2] += val;
		idx2 += -idx2&idx2;
	}
}

long long query(int idx1, int idx2)
{
	long long ret = 0;
	while(idx2)
	{
		ret += fw[idx1][idx2];
		idx2 -= -idx2&idx2;
	}
	return ret;
}

int main()
{
	int n, sz = 0;
	long long ans = 0;
	scanf(" %d",&n);
	for(int i=1 ; i<=n ; i++)
	{
		scanf(" %lld",&arr[i]);
		v.push_back(arr[i]);
	}
	sort(v.begin(), v.end());
	for(int i=0 ; i<n ; i++)
		if(!com.count(v[i]))
			com[v[i]] = ++sz;
	for(int i=1 ; i<=n ; i++)
	{
		arr[i] = com[arr[i]];
		update(1, arr[i], 1);
	}
	for(int i=1 ; i<=n ; i++)
	{
		update(1, arr[i], -1);
		ans += query(0, arr[i]-1) * query(1, arr[i]-1);
		update(0, arr[i], 1);
	}
	printf("%lld\n",ans);
	return 0;
}

Compilation message

Mountains.cpp: In function 'int main()':
Mountains.cpp:34:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   34 |  scanf(" %d",&n);
      |  ~~~~~^~~~~~~~~~
Mountains.cpp:37:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   37 |   scanf(" %lld",&arr[i]);
      |   ~~~~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 347 ms 29404 KB Output is correct
3 Correct 306 ms 29404 KB Output is correct
4 Correct 284 ms 29408 KB Output is correct
5 Correct 288 ms 29684 KB Output is correct
6 Correct 282 ms 29552 KB Output is correct
7 Correct 290 ms 29532 KB Output is correct
8 Correct 283 ms 29404 KB Output is correct
9 Correct 140 ms 20060 KB Output is correct
10 Correct 137 ms 20060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 103 ms 7272 KB Output is correct
2 Correct 101 ms 7272 KB Output is correct
3 Correct 89 ms 7272 KB Output is correct
4 Correct 88 ms 7308 KB Output is correct
5 Correct 85 ms 7272 KB Output is correct
6 Correct 85 ms 7280 KB Output is correct
7 Correct 84 ms 7268 KB Output is correct
8 Correct 90 ms 7272 KB Output is correct
9 Correct 83 ms 7276 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 103 ms 7272 KB Output is correct
2 Correct 101 ms 7272 KB Output is correct
3 Correct 89 ms 7272 KB Output is correct
4 Correct 88 ms 7308 KB Output is correct
5 Correct 85 ms 7272 KB Output is correct
6 Correct 85 ms 7280 KB Output is correct
7 Correct 84 ms 7268 KB Output is correct
8 Correct 90 ms 7272 KB Output is correct
9 Correct 83 ms 7276 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 93 ms 7536 KB Output is correct
12 Correct 91 ms 7524 KB Output is correct
13 Correct 94 ms 7528 KB Output is correct
14 Correct 92 ms 7528 KB Output is correct
15 Correct 91 ms 7528 KB Output is correct
16 Correct 94 ms 7528 KB Output is correct
17 Correct 90 ms 7536 KB Output is correct
18 Correct 79 ms 7528 KB Output is correct
19 Correct 81 ms 7524 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 512 KB Output is correct
2 Correct 1 ms 512 KB Output is correct
3 Correct 1 ms 512 KB Output is correct
4 Correct 1 ms 512 KB Output is correct
5 Correct 1 ms 512 KB Output is correct
6 Correct 1 ms 512 KB Output is correct
7 Correct 1 ms 512 KB Output is correct
8 Correct 1 ms 384 KB Output is correct
9 Correct 1 ms 384 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 8 ms 1312 KB Output is correct
12 Correct 8 ms 1280 KB Output is correct
13 Correct 8 ms 1280 KB Output is correct
14 Correct 8 ms 1280 KB Output is correct
15 Correct 8 ms 1280 KB Output is correct
16 Correct 8 ms 1280 KB Output is correct
17 Correct 9 ms 1280 KB Output is correct
18 Correct 7 ms 1024 KB Output is correct
19 Correct 4 ms 768 KB Output is correct
20 Correct 1 ms 512 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 103 ms 7272 KB Output is correct
2 Correct 101 ms 7272 KB Output is correct
3 Correct 89 ms 7272 KB Output is correct
4 Correct 88 ms 7308 KB Output is correct
5 Correct 85 ms 7272 KB Output is correct
6 Correct 85 ms 7280 KB Output is correct
7 Correct 84 ms 7268 KB Output is correct
8 Correct 90 ms 7272 KB Output is correct
9 Correct 83 ms 7276 KB Output is correct
10 Correct 1 ms 384 KB Output is correct
11 Correct 93 ms 7536 KB Output is correct
12 Correct 91 ms 7524 KB Output is correct
13 Correct 94 ms 7528 KB Output is correct
14 Correct 92 ms 7528 KB Output is correct
15 Correct 91 ms 7528 KB Output is correct
16 Correct 94 ms 7528 KB Output is correct
17 Correct 90 ms 7536 KB Output is correct
18 Correct 79 ms 7528 KB Output is correct
19 Correct 81 ms 7524 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 131 ms 12428 KB Output is correct
22 Correct 135 ms 12252 KB Output is correct
23 Correct 136 ms 12252 KB Output is correct
24 Correct 133 ms 12252 KB Output is correct
25 Correct 134 ms 12252 KB Output is correct
26 Correct 141 ms 12380 KB Output is correct
27 Correct 133 ms 12252 KB Output is correct
28 Correct 92 ms 12304 KB Output is correct
29 Correct 89 ms 12252 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 384 KB Output is correct
2 Correct 347 ms 29404 KB Output is correct
3 Correct 306 ms 29404 KB Output is correct
4 Correct 284 ms 29408 KB Output is correct
5 Correct 288 ms 29684 KB Output is correct
6 Correct 282 ms 29552 KB Output is correct
7 Correct 290 ms 29532 KB Output is correct
8 Correct 283 ms 29404 KB Output is correct
9 Correct 140 ms 20060 KB Output is correct
10 Correct 137 ms 20060 KB Output is correct
11 Correct 103 ms 7272 KB Output is correct
12 Correct 101 ms 7272 KB Output is correct
13 Correct 89 ms 7272 KB Output is correct
14 Correct 88 ms 7308 KB Output is correct
15 Correct 85 ms 7272 KB Output is correct
16 Correct 85 ms 7280 KB Output is correct
17 Correct 84 ms 7268 KB Output is correct
18 Correct 90 ms 7272 KB Output is correct
19 Correct 83 ms 7276 KB Output is correct
20 Correct 1 ms 384 KB Output is correct
21 Correct 93 ms 7536 KB Output is correct
22 Correct 91 ms 7524 KB Output is correct
23 Correct 94 ms 7528 KB Output is correct
24 Correct 92 ms 7528 KB Output is correct
25 Correct 91 ms 7528 KB Output is correct
26 Correct 94 ms 7528 KB Output is correct
27 Correct 90 ms 7536 KB Output is correct
28 Correct 79 ms 7528 KB Output is correct
29 Correct 81 ms 7524 KB Output is correct
30 Correct 1 ms 384 KB Output is correct
31 Correct 1 ms 512 KB Output is correct
32 Correct 1 ms 512 KB Output is correct
33 Correct 1 ms 512 KB Output is correct
34 Correct 1 ms 512 KB Output is correct
35 Correct 1 ms 512 KB Output is correct
36 Correct 1 ms 512 KB Output is correct
37 Correct 1 ms 512 KB Output is correct
38 Correct 1 ms 384 KB Output is correct
39 Correct 1 ms 384 KB Output is correct
40 Correct 1 ms 384 KB Output is correct
41 Correct 8 ms 1312 KB Output is correct
42 Correct 8 ms 1280 KB Output is correct
43 Correct 8 ms 1280 KB Output is correct
44 Correct 8 ms 1280 KB Output is correct
45 Correct 8 ms 1280 KB Output is correct
46 Correct 8 ms 1280 KB Output is correct
47 Correct 9 ms 1280 KB Output is correct
48 Correct 7 ms 1024 KB Output is correct
49 Correct 4 ms 768 KB Output is correct
50 Correct 1 ms 512 KB Output is correct
51 Correct 131 ms 12428 KB Output is correct
52 Correct 135 ms 12252 KB Output is correct
53 Correct 136 ms 12252 KB Output is correct
54 Correct 133 ms 12252 KB Output is correct
55 Correct 134 ms 12252 KB Output is correct
56 Correct 141 ms 12380 KB Output is correct
57 Correct 133 ms 12252 KB Output is correct
58 Correct 92 ms 12304 KB Output is correct
59 Correct 89 ms 12252 KB Output is correct
60 Correct 1 ms 384 KB Output is correct
61 Correct 374 ms 29404 KB Output is correct
62 Correct 384 ms 29532 KB Output is correct
63 Correct 381 ms 29404 KB Output is correct
64 Correct 409 ms 29404 KB Output is correct
65 Correct 375 ms 29396 KB Output is correct
66 Correct 372 ms 29404 KB Output is correct
67 Correct 345 ms 29408 KB Output is correct
68 Correct 225 ms 20060 KB Output is correct
69 Correct 174 ms 15868 KB Output is correct
70 Correct 1 ms 384 KB Output is correct