Submission #240982

# Submission time Handle Problem Language Result Execution time Memory
240982 2020-06-22T00:11:19 Z AmineWeslati Mountains (NOI20_mountains) C++14
100 / 100
156 ms 22880 KB
//Never stop trying
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//s.order_of_key(), *s.find_by_order()

using namespace std;
#define boost ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

typedef string str;
typedef long long ll;
#define int ll
typedef double db;
typedef long double ld;

typedef pair<int,int> pi;
#define fi first
#define se second

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<str> vs;
typedef vector<pi> vpi;

#define pb push_back
#define eb emplace_back
#define pf push_front

#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define endl "\n"

const int MOD = 1e9+7; //998244353
const ll INF = 1e18;
const int nx[4]={0,0,1,-1}, ny[4]={1,-1,0,0}; //right left down up

const int MX=3e5+70;
int N;
int t[MX];
int bit[MX];
int r[MX],l[MX];


int lsb(int i){return i&-i;}
void update(int idx){
   while(idx<MX){
      bit[idx]++;
      idx+=lsb(idx);
   }
}

int getSum(int idx){
   int ans=0;
   while(idx>0){
      ans+=bit[idx];
      idx-=lsb(idx);
   }
   return ans;
}

int32_t main(){
   boost;
	for(int i=0; i<MX; i++) r[i]=l[i]=bit[i]=0;
	cin>>N;
	
	vpi vec;
	for(int i=0; i<N; i++){
      cin>>t[i];
      vec.pb({t[i],i});
	}sort(all(vec));

	int nb=0;
	for(int i=0; i<N; i++){
      if(i==0||vec[i-1].fi<vec[i].fi) nb++;
      t[vec[i].se]=nb;
	}


	for(int i=0; i<N; i++){
      l[i]=getSum(t[i]-1);
      update(t[i]);
	}

	for(int i=0; i<MX; i++) bit[i]=0;
	for(int i=N-1; i>=0; i--){
      r[i]=getSum(t[i]-1);
      update(t[i]);
	}

	int res=0;
	for(int i=0; i<N; i++) res+=r[i]*l[i];
	cout << res << endl;

   return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 9 ms 7424 KB Output is correct
2 Correct 102 ms 17760 KB Output is correct
3 Correct 111 ms 22752 KB Output is correct
4 Correct 105 ms 22752 KB Output is correct
5 Correct 103 ms 22752 KB Output is correct
6 Correct 107 ms 22748 KB Output is correct
7 Correct 108 ms 22752 KB Output is correct
8 Correct 112 ms 22752 KB Output is correct
9 Correct 107 ms 22756 KB Output is correct
10 Correct 112 ms 22880 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 95 ms 17832 KB Output is correct
2 Correct 110 ms 17768 KB Output is correct
3 Correct 99 ms 17776 KB Output is correct
4 Correct 95 ms 17776 KB Output is correct
5 Correct 101 ms 17776 KB Output is correct
6 Correct 107 ms 17648 KB Output is correct
7 Correct 104 ms 17776 KB Output is correct
8 Correct 78 ms 17896 KB Output is correct
9 Correct 75 ms 17776 KB Output is correct
10 Correct 9 ms 7424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 95 ms 17832 KB Output is correct
2 Correct 110 ms 17768 KB Output is correct
3 Correct 99 ms 17776 KB Output is correct
4 Correct 95 ms 17776 KB Output is correct
5 Correct 101 ms 17776 KB Output is correct
6 Correct 107 ms 17648 KB Output is correct
7 Correct 104 ms 17776 KB Output is correct
8 Correct 78 ms 17896 KB Output is correct
9 Correct 75 ms 17776 KB Output is correct
10 Correct 9 ms 7424 KB Output is correct
11 Correct 98 ms 17768 KB Output is correct
12 Correct 99 ms 17768 KB Output is correct
13 Correct 97 ms 17768 KB Output is correct
14 Correct 98 ms 17768 KB Output is correct
15 Correct 100 ms 17776 KB Output is correct
16 Correct 102 ms 17776 KB Output is correct
17 Correct 98 ms 17772 KB Output is correct
18 Correct 72 ms 17768 KB Output is correct
19 Correct 72 ms 17768 KB Output is correct
20 Correct 8 ms 7424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 7424 KB Output is correct
2 Correct 9 ms 7424 KB Output is correct
3 Correct 8 ms 7424 KB Output is correct
4 Correct 9 ms 7424 KB Output is correct
5 Correct 8 ms 7424 KB Output is correct
6 Correct 9 ms 7424 KB Output is correct
7 Correct 9 ms 7424 KB Output is correct
8 Correct 9 ms 7552 KB Output is correct
9 Correct 9 ms 7424 KB Output is correct
10 Correct 8 ms 7424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 7424 KB Output is correct
2 Correct 9 ms 7424 KB Output is correct
3 Correct 8 ms 7424 KB Output is correct
4 Correct 9 ms 7424 KB Output is correct
5 Correct 8 ms 7424 KB Output is correct
6 Correct 9 ms 7424 KB Output is correct
7 Correct 9 ms 7424 KB Output is correct
8 Correct 9 ms 7552 KB Output is correct
9 Correct 9 ms 7424 KB Output is correct
10 Correct 8 ms 7424 KB Output is correct
11 Correct 13 ms 7808 KB Output is correct
12 Correct 13 ms 7808 KB Output is correct
13 Correct 13 ms 7808 KB Output is correct
14 Correct 13 ms 7808 KB Output is correct
15 Correct 12 ms 7808 KB Output is correct
16 Correct 14 ms 7936 KB Output is correct
17 Correct 13 ms 7808 KB Output is correct
18 Correct 12 ms 7936 KB Output is correct
19 Correct 11 ms 7808 KB Output is correct
20 Correct 9 ms 7424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 95 ms 17832 KB Output is correct
2 Correct 110 ms 17768 KB Output is correct
3 Correct 99 ms 17776 KB Output is correct
4 Correct 95 ms 17776 KB Output is correct
5 Correct 101 ms 17776 KB Output is correct
6 Correct 107 ms 17648 KB Output is correct
7 Correct 104 ms 17776 KB Output is correct
8 Correct 78 ms 17896 KB Output is correct
9 Correct 75 ms 17776 KB Output is correct
10 Correct 9 ms 7424 KB Output is correct
11 Correct 98 ms 17768 KB Output is correct
12 Correct 99 ms 17768 KB Output is correct
13 Correct 97 ms 17768 KB Output is correct
14 Correct 98 ms 17768 KB Output is correct
15 Correct 100 ms 17776 KB Output is correct
16 Correct 102 ms 17776 KB Output is correct
17 Correct 98 ms 17772 KB Output is correct
18 Correct 72 ms 17768 KB Output is correct
19 Correct 72 ms 17768 KB Output is correct
20 Correct 8 ms 7424 KB Output is correct
21 Correct 123 ms 17764 KB Output is correct
22 Correct 124 ms 19428 KB Output is correct
23 Correct 124 ms 19428 KB Output is correct
24 Correct 118 ms 19428 KB Output is correct
25 Correct 120 ms 19432 KB Output is correct
26 Correct 121 ms 19424 KB Output is correct
27 Correct 120 ms 19432 KB Output is correct
28 Correct 79 ms 19420 KB Output is correct
29 Correct 84 ms 19432 KB Output is correct
30 Correct 9 ms 7424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 7424 KB Output is correct
2 Correct 102 ms 17760 KB Output is correct
3 Correct 111 ms 22752 KB Output is correct
4 Correct 105 ms 22752 KB Output is correct
5 Correct 103 ms 22752 KB Output is correct
6 Correct 107 ms 22748 KB Output is correct
7 Correct 108 ms 22752 KB Output is correct
8 Correct 112 ms 22752 KB Output is correct
9 Correct 107 ms 22756 KB Output is correct
10 Correct 112 ms 22880 KB Output is correct
11 Correct 95 ms 17832 KB Output is correct
12 Correct 110 ms 17768 KB Output is correct
13 Correct 99 ms 17776 KB Output is correct
14 Correct 95 ms 17776 KB Output is correct
15 Correct 101 ms 17776 KB Output is correct
16 Correct 107 ms 17648 KB Output is correct
17 Correct 104 ms 17776 KB Output is correct
18 Correct 78 ms 17896 KB Output is correct
19 Correct 75 ms 17776 KB Output is correct
20 Correct 9 ms 7424 KB Output is correct
21 Correct 98 ms 17768 KB Output is correct
22 Correct 99 ms 17768 KB Output is correct
23 Correct 97 ms 17768 KB Output is correct
24 Correct 98 ms 17768 KB Output is correct
25 Correct 100 ms 17776 KB Output is correct
26 Correct 102 ms 17776 KB Output is correct
27 Correct 98 ms 17772 KB Output is correct
28 Correct 72 ms 17768 KB Output is correct
29 Correct 72 ms 17768 KB Output is correct
30 Correct 8 ms 7424 KB Output is correct
31 Correct 9 ms 7424 KB Output is correct
32 Correct 9 ms 7424 KB Output is correct
33 Correct 8 ms 7424 KB Output is correct
34 Correct 9 ms 7424 KB Output is correct
35 Correct 8 ms 7424 KB Output is correct
36 Correct 9 ms 7424 KB Output is correct
37 Correct 9 ms 7424 KB Output is correct
38 Correct 9 ms 7552 KB Output is correct
39 Correct 9 ms 7424 KB Output is correct
40 Correct 8 ms 7424 KB Output is correct
41 Correct 13 ms 7808 KB Output is correct
42 Correct 13 ms 7808 KB Output is correct
43 Correct 13 ms 7808 KB Output is correct
44 Correct 13 ms 7808 KB Output is correct
45 Correct 12 ms 7808 KB Output is correct
46 Correct 14 ms 7936 KB Output is correct
47 Correct 13 ms 7808 KB Output is correct
48 Correct 12 ms 7936 KB Output is correct
49 Correct 11 ms 7808 KB Output is correct
50 Correct 9 ms 7424 KB Output is correct
51 Correct 123 ms 17764 KB Output is correct
52 Correct 124 ms 19428 KB Output is correct
53 Correct 124 ms 19428 KB Output is correct
54 Correct 118 ms 19428 KB Output is correct
55 Correct 120 ms 19432 KB Output is correct
56 Correct 121 ms 19424 KB Output is correct
57 Correct 120 ms 19432 KB Output is correct
58 Correct 79 ms 19420 KB Output is correct
59 Correct 84 ms 19432 KB Output is correct
60 Correct 9 ms 7424 KB Output is correct
61 Correct 149 ms 22748 KB Output is correct
62 Correct 151 ms 22756 KB Output is correct
63 Correct 148 ms 22756 KB Output is correct
64 Correct 155 ms 22752 KB Output is correct
65 Correct 146 ms 22756 KB Output is correct
66 Correct 153 ms 22752 KB Output is correct
67 Correct 154 ms 22756 KB Output is correct
68 Correct 156 ms 22880 KB Output is correct
69 Correct 123 ms 19556 KB Output is correct
70 Correct 8 ms 7424 KB Output is correct