Submission #933635

# Submission time Handle Problem Language Result Execution time Memory
933635 2024-02-26T02:50:23 Z Spazmash Mountains (NOI20_mountains) C++17
100 / 100
916 ms 76468 KB
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ld long double
#define fastio ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define elif else if
#define x first
#define y second
ll n, a[300001], tree[1300001], ans;
vector<ll> del[300001], vec;
map<ll, bool> vis;
map<ll, ll> eval;

ll query(ll tidx, ll tl, ll tr, ll l, ll r){
	if(l>tr)return 0;
	if(r<tl)return 0;
	if(l<=tl && r>=tr)return tree[tidx];
	ll tmid=(tl+tr)/2;
	return query(tidx*2, tl, tmid, l, r)+query(tidx*2+1, tmid+1, tr, l, r);
}

void update(ll tidx, ll tl, ll tr, ll idx){
	if(tl==tr && tl==idx){
		tree[tidx]=0;
		return;
	}
	if(tl>idx)return;
	if(tr<idx)return;
	ll tmid=(tl+tr)/2;
	update(tidx*2, tl, tmid, idx);
	update(tidx*2+1, tmid+1, tr, idx);
	tree[tidx]=tree[tidx*2]+tree[tidx*2+1];
}

void build(ll tidx, ll tl, ll tr){
	if(tl==tr){
		tree[tidx]=1;
		return ;
	}
	ll tmid=(tl+tr)/2;
	build(tidx*2, tl, tmid);
	build(tidx*2+1, tmid+1, tr);
	tree[tidx]=tree[tidx*2]+tree[tidx*2+1];
}

int main() {
	cin >> n;
	for(int i=1; i<=n; i++){
		cin >> a[i];
		if(!vis[a[i]])vec.pb(a[i]);
		vis[a[i]]=true;
	}
	sort(vec.begin(), vec.end());
	for(int i=0; i<vec.size(); i++){
		eval[vec[i]]=i+1;
	}
	for(int i=1; i<=n; i++){
		a[i]=eval[a[i]];
		del[a[i]].pb(i);
	}
	build(1, 1, n);
	for(int i=vec.size(); i>=1; i--){
		for(auto j:del[i]){
			update(1, 1, n, j);
		}
		for(auto j:del[i]){
			ans+=query(1, 1, n, 1, j-1)*query(1, 1, n, j+1, n);
		}
	}
	cout << ans << endl;
}

Compilation message

Mountains.cpp: In function 'int main()':
Mountains.cpp:60:16: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   60 |  for(int i=0; i<vec.size(); i++){
      |               ~^~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10844 KB Output is correct
2 Correct 434 ms 75824 KB Output is correct
3 Correct 410 ms 74972 KB Output is correct
4 Correct 423 ms 76016 KB Output is correct
5 Correct 407 ms 75780 KB Output is correct
6 Correct 413 ms 76212 KB Output is correct
7 Correct 432 ms 75224 KB Output is correct
8 Correct 412 ms 75316 KB Output is correct
9 Correct 370 ms 51900 KB Output is correct
10 Correct 372 ms 51848 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 144 ms 23072 KB Output is correct
2 Correct 142 ms 23024 KB Output is correct
3 Correct 157 ms 23156 KB Output is correct
4 Correct 142 ms 23008 KB Output is correct
5 Correct 144 ms 22904 KB Output is correct
6 Correct 143 ms 23152 KB Output is correct
7 Correct 143 ms 23072 KB Output is correct
8 Correct 137 ms 23076 KB Output is correct
9 Correct 152 ms 22852 KB Output is correct
10 Correct 2 ms 10844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 144 ms 23072 KB Output is correct
2 Correct 142 ms 23024 KB Output is correct
3 Correct 157 ms 23156 KB Output is correct
4 Correct 142 ms 23008 KB Output is correct
5 Correct 144 ms 22904 KB Output is correct
6 Correct 143 ms 23152 KB Output is correct
7 Correct 143 ms 23072 KB Output is correct
8 Correct 137 ms 23076 KB Output is correct
9 Correct 152 ms 22852 KB Output is correct
10 Correct 2 ms 10844 KB Output is correct
11 Correct 188 ms 24148 KB Output is correct
12 Correct 185 ms 24292 KB Output is correct
13 Correct 184 ms 24096 KB Output is correct
14 Correct 182 ms 24148 KB Output is correct
15 Correct 208 ms 24236 KB Output is correct
16 Correct 193 ms 24248 KB Output is correct
17 Correct 194 ms 23984 KB Output is correct
18 Correct 140 ms 23548 KB Output is correct
19 Correct 141 ms 23376 KB Output is correct
20 Correct 2 ms 10840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 10844 KB Output is correct
2 Correct 3 ms 10844 KB Output is correct
3 Correct 3 ms 10876 KB Output is correct
4 Correct 3 ms 10844 KB Output is correct
5 Correct 3 ms 10840 KB Output is correct
6 Correct 3 ms 10840 KB Output is correct
7 Correct 3 ms 10844 KB Output is correct
8 Correct 3 ms 10844 KB Output is correct
9 Correct 2 ms 10844 KB Output is correct
10 Correct 2 ms 10856 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 10844 KB Output is correct
2 Correct 3 ms 10844 KB Output is correct
3 Correct 3 ms 10876 KB Output is correct
4 Correct 3 ms 10844 KB Output is correct
5 Correct 3 ms 10840 KB Output is correct
6 Correct 3 ms 10840 KB Output is correct
7 Correct 3 ms 10844 KB Output is correct
8 Correct 3 ms 10844 KB Output is correct
9 Correct 2 ms 10844 KB Output is correct
10 Correct 2 ms 10856 KB Output is correct
11 Correct 20 ms 12664 KB Output is correct
12 Correct 18 ms 12636 KB Output is correct
13 Correct 17 ms 12636 KB Output is correct
14 Correct 17 ms 12540 KB Output is correct
15 Correct 16 ms 12636 KB Output is correct
16 Correct 16 ms 12636 KB Output is correct
17 Correct 16 ms 12716 KB Output is correct
18 Correct 14 ms 11684 KB Output is correct
19 Correct 10 ms 11100 KB Output is correct
20 Correct 2 ms 10844 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 144 ms 23072 KB Output is correct
2 Correct 142 ms 23024 KB Output is correct
3 Correct 157 ms 23156 KB Output is correct
4 Correct 142 ms 23008 KB Output is correct
5 Correct 144 ms 22904 KB Output is correct
6 Correct 143 ms 23152 KB Output is correct
7 Correct 143 ms 23072 KB Output is correct
8 Correct 137 ms 23076 KB Output is correct
9 Correct 152 ms 22852 KB Output is correct
10 Correct 2 ms 10844 KB Output is correct
11 Correct 188 ms 24148 KB Output is correct
12 Correct 185 ms 24292 KB Output is correct
13 Correct 184 ms 24096 KB Output is correct
14 Correct 182 ms 24148 KB Output is correct
15 Correct 208 ms 24236 KB Output is correct
16 Correct 193 ms 24248 KB Output is correct
17 Correct 194 ms 23984 KB Output is correct
18 Correct 140 ms 23548 KB Output is correct
19 Correct 141 ms 23376 KB Output is correct
20 Correct 2 ms 10840 KB Output is correct
21 Correct 436 ms 39360 KB Output is correct
22 Correct 441 ms 39108 KB Output is correct
23 Correct 412 ms 39316 KB Output is correct
24 Correct 446 ms 39288 KB Output is correct
25 Correct 436 ms 39108 KB Output is correct
26 Correct 451 ms 39068 KB Output is correct
27 Correct 424 ms 39216 KB Output is correct
28 Correct 268 ms 38868 KB Output is correct
29 Correct 259 ms 38844 KB Output is correct
30 Correct 2 ms 10840 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 10844 KB Output is correct
2 Correct 434 ms 75824 KB Output is correct
3 Correct 410 ms 74972 KB Output is correct
4 Correct 423 ms 76016 KB Output is correct
5 Correct 407 ms 75780 KB Output is correct
6 Correct 413 ms 76212 KB Output is correct
7 Correct 432 ms 75224 KB Output is correct
8 Correct 412 ms 75316 KB Output is correct
9 Correct 370 ms 51900 KB Output is correct
10 Correct 372 ms 51848 KB Output is correct
11 Correct 144 ms 23072 KB Output is correct
12 Correct 142 ms 23024 KB Output is correct
13 Correct 157 ms 23156 KB Output is correct
14 Correct 142 ms 23008 KB Output is correct
15 Correct 144 ms 22904 KB Output is correct
16 Correct 143 ms 23152 KB Output is correct
17 Correct 143 ms 23072 KB Output is correct
18 Correct 137 ms 23076 KB Output is correct
19 Correct 152 ms 22852 KB Output is correct
20 Correct 2 ms 10844 KB Output is correct
21 Correct 188 ms 24148 KB Output is correct
22 Correct 185 ms 24292 KB Output is correct
23 Correct 184 ms 24096 KB Output is correct
24 Correct 182 ms 24148 KB Output is correct
25 Correct 208 ms 24236 KB Output is correct
26 Correct 193 ms 24248 KB Output is correct
27 Correct 194 ms 23984 KB Output is correct
28 Correct 140 ms 23548 KB Output is correct
29 Correct 141 ms 23376 KB Output is correct
30 Correct 2 ms 10840 KB Output is correct
31 Correct 3 ms 10844 KB Output is correct
32 Correct 3 ms 10844 KB Output is correct
33 Correct 3 ms 10876 KB Output is correct
34 Correct 3 ms 10844 KB Output is correct
35 Correct 3 ms 10840 KB Output is correct
36 Correct 3 ms 10840 KB Output is correct
37 Correct 3 ms 10844 KB Output is correct
38 Correct 3 ms 10844 KB Output is correct
39 Correct 2 ms 10844 KB Output is correct
40 Correct 2 ms 10856 KB Output is correct
41 Correct 20 ms 12664 KB Output is correct
42 Correct 18 ms 12636 KB Output is correct
43 Correct 17 ms 12636 KB Output is correct
44 Correct 17 ms 12540 KB Output is correct
45 Correct 16 ms 12636 KB Output is correct
46 Correct 16 ms 12636 KB Output is correct
47 Correct 16 ms 12716 KB Output is correct
48 Correct 14 ms 11684 KB Output is correct
49 Correct 10 ms 11100 KB Output is correct
50 Correct 2 ms 10844 KB Output is correct
51 Correct 436 ms 39360 KB Output is correct
52 Correct 441 ms 39108 KB Output is correct
53 Correct 412 ms 39316 KB Output is correct
54 Correct 446 ms 39288 KB Output is correct
55 Correct 436 ms 39108 KB Output is correct
56 Correct 451 ms 39068 KB Output is correct
57 Correct 424 ms 39216 KB Output is correct
58 Correct 268 ms 38868 KB Output is correct
59 Correct 259 ms 38844 KB Output is correct
60 Correct 2 ms 10840 KB Output is correct
61 Correct 848 ms 76256 KB Output is correct
62 Correct 798 ms 76468 KB Output is correct
63 Correct 800 ms 75768 KB Output is correct
64 Correct 809 ms 75740 KB Output is correct
65 Correct 916 ms 75196 KB Output is correct
66 Correct 807 ms 75824 KB Output is correct
67 Correct 856 ms 76220 KB Output is correct
68 Correct 629 ms 51900 KB Output is correct
69 Correct 562 ms 44464 KB Output is correct
70 Correct 2 ms 10844 KB Output is correct