Submission #234124

# Submission time Handle Problem Language Result Execution time Memory
234124 2020-05-23T08:36:23 Z anubhavdhar Mountains (NOI20_mountains) C++14
100 / 100
298 ms 20088 KB
#include<bits/stdc++.h>

#define ll long long
#define int ll
#define pb push_back
#define mp make_pair
#define FOR(i,n) for(i=0;i<(n);++i)
#define FORe(i,n) for(i=1;i<=(n);++i)
#define FORr(i,a,b) for(i=(a);i<(b);++i)
#define FORrev(i,n) for(i=(n);i>=0;--i)
#define F0R(i,n) for(int i=0;i<(n);++i)
#define F0Re(i,n) for(int i=1;i<=(n);++i)
#define F0Rr(i,a,b) for(ll i=(a);i<(b);++i)
#define F0Rrev(i,n) for(int i=(n);i>=0;--i)
#define ii pair<ll,ll>
#define vi vector<ll>
#define vii vector<ii>
#define ff first 
#define ss second
#define cd complex<double>
#define vcd vector<cd>
#define ldd long double
#define dbgLine cout<<"Line : "<<__LINE__<<'\n'
#define all(x) (x).begin(),(x).end()

using namespace std;

const int __PRECISION = 10;

const ll MOD = 1e9+7;
const ll INF = 1e17 + 1101;
const ll LOGN = 17;
const ll MAXN = 3e5+5;
const ll ROOTN = 320;

const ldd PI = acos(-1);
const ldd EPS = 1e-7;

struct SegTree
{
	int st[4*MAXN];

	void upd(int node, int ss, int se, int i)
	{
		if(ss >  i or se < i)
			return;
		if(ss == se)
		{
			++st[node];
			return;
		}
		int mid = (ss + se)/2;
		upd(node*2 + 1, ss, mid, i);
		upd(node*2 + 2, mid+1, se, i);
		st[node] = st[node*2+1] + st[node*2+2];
	}

	ll quer(int node, int ss, int se, int l, int r)
	{
		if(ss > r or se < l)	return 0;
		if(ss >= l and se <= r)	return st[node];
		int mid = (ss + se) / 2;
		return quer(node*2+1, ss, mid,l,r) + quer(node*2+2,mid+1,se,l,r);
	}

	SegTree()
	{
		F0R(i, 4*MAXN)
			st[i] = 0;
	}

	inline void update(int i)
	{
		upd(0, 0, MAXN, i);
	}

	inline ll query(int i, int ded)
	{
		ll a = quer(0, 0, MAXN, 0, i-1) - ded, b = quer(0, 0, MAXN, i+1, MAXN);
		// cout<<"a = "<<a<<", b = "<<b<<'\n';
		return (a*b);
	}
} S;

signed main()
{
	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	int N;
	cin>>N;
	pair<ll, int> A[N];
	F0R(i, N)
	{
		ll j;
		cin>>j;
		A[i] = mp(j, i+1);
	}
	sort(A, A + N);
	ll previo = -1, tot = 0, ans = 0;
	F0R(i, N)
	{
		// cout<<"for ("<<A[i].ff<<','<<A[i].ss<<") : ";
		if(A[i].ff != previo)
			tot = 0;
		S.update(A[i].ss);
		int tmp = S.query(A[i].ss, tot);
		// cout<<"tot = "<<tot<<", previo = "<<previo<<", no. of combinations is "<<tmp<<'\n';
		previo = A[i].ff;
		++tot;
		ans += tmp;
	}
	cout<<ans;
	return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 10 ms 9728 KB Output is correct
2 Correct 189 ms 14464 KB Output is correct
3 Correct 191 ms 14464 KB Output is correct
4 Correct 189 ms 14584 KB Output is correct
5 Correct 182 ms 14584 KB Output is correct
6 Correct 188 ms 14464 KB Output is correct
7 Correct 183 ms 14464 KB Output is correct
8 Correct 180 ms 14584 KB Output is correct
9 Correct 196 ms 14464 KB Output is correct
10 Correct 197 ms 14464 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 168 ms 14464 KB Output is correct
2 Correct 175 ms 15060 KB Output is correct
3 Correct 169 ms 15064 KB Output is correct
4 Correct 167 ms 15072 KB Output is correct
5 Correct 172 ms 14976 KB Output is correct
6 Correct 167 ms 14976 KB Output is correct
7 Correct 165 ms 14976 KB Output is correct
8 Correct 147 ms 14976 KB Output is correct
9 Correct 143 ms 14976 KB Output is correct
10 Correct 9 ms 9728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 168 ms 14464 KB Output is correct
2 Correct 175 ms 15060 KB Output is correct
3 Correct 169 ms 15064 KB Output is correct
4 Correct 167 ms 15072 KB Output is correct
5 Correct 172 ms 14976 KB Output is correct
6 Correct 167 ms 14976 KB Output is correct
7 Correct 165 ms 14976 KB Output is correct
8 Correct 147 ms 14976 KB Output is correct
9 Correct 143 ms 14976 KB Output is correct
10 Correct 9 ms 9728 KB Output is correct
11 Correct 224 ms 15352 KB Output is correct
12 Correct 231 ms 15352 KB Output is correct
13 Correct 224 ms 15232 KB Output is correct
14 Correct 228 ms 15232 KB Output is correct
15 Correct 229 ms 15352 KB Output is correct
16 Correct 230 ms 15232 KB Output is correct
17 Correct 230 ms 15352 KB Output is correct
18 Correct 149 ms 15232 KB Output is correct
19 Correct 146 ms 15232 KB Output is correct
20 Correct 9 ms 9728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 9728 KB Output is correct
2 Correct 9 ms 9728 KB Output is correct
3 Correct 9 ms 9728 KB Output is correct
4 Correct 9 ms 9728 KB Output is correct
5 Correct 10 ms 9728 KB Output is correct
6 Correct 9 ms 9728 KB Output is correct
7 Correct 9 ms 9728 KB Output is correct
8 Correct 9 ms 9728 KB Output is correct
9 Correct 9 ms 9728 KB Output is correct
10 Correct 9 ms 9728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 9 ms 9728 KB Output is correct
2 Correct 9 ms 9728 KB Output is correct
3 Correct 9 ms 9728 KB Output is correct
4 Correct 9 ms 9728 KB Output is correct
5 Correct 10 ms 9728 KB Output is correct
6 Correct 9 ms 9728 KB Output is correct
7 Correct 9 ms 9728 KB Output is correct
8 Correct 9 ms 9728 KB Output is correct
9 Correct 9 ms 9728 KB Output is correct
10 Correct 9 ms 9728 KB Output is correct
11 Correct 17 ms 9856 KB Output is correct
12 Correct 17 ms 9856 KB Output is correct
13 Correct 17 ms 9856 KB Output is correct
14 Correct 20 ms 9984 KB Output is correct
15 Correct 17 ms 9856 KB Output is correct
16 Correct 17 ms 9856 KB Output is correct
17 Correct 17 ms 9856 KB Output is correct
18 Correct 17 ms 9856 KB Output is correct
19 Correct 16 ms 9856 KB Output is correct
20 Correct 9 ms 9728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 168 ms 14464 KB Output is correct
2 Correct 175 ms 15060 KB Output is correct
3 Correct 169 ms 15064 KB Output is correct
4 Correct 167 ms 15072 KB Output is correct
5 Correct 172 ms 14976 KB Output is correct
6 Correct 167 ms 14976 KB Output is correct
7 Correct 165 ms 14976 KB Output is correct
8 Correct 147 ms 14976 KB Output is correct
9 Correct 143 ms 14976 KB Output is correct
10 Correct 9 ms 9728 KB Output is correct
11 Correct 224 ms 15352 KB Output is correct
12 Correct 231 ms 15352 KB Output is correct
13 Correct 224 ms 15232 KB Output is correct
14 Correct 228 ms 15232 KB Output is correct
15 Correct 229 ms 15352 KB Output is correct
16 Correct 230 ms 15232 KB Output is correct
17 Correct 230 ms 15352 KB Output is correct
18 Correct 149 ms 15232 KB Output is correct
19 Correct 146 ms 15232 KB Output is correct
20 Correct 9 ms 9728 KB Output is correct
21 Correct 263 ms 16120 KB Output is correct
22 Correct 273 ms 16252 KB Output is correct
23 Correct 261 ms 16128 KB Output is correct
24 Correct 263 ms 16200 KB Output is correct
25 Correct 260 ms 16120 KB Output is correct
26 Correct 266 ms 16248 KB Output is correct
27 Correct 259 ms 16248 KB Output is correct
28 Correct 158 ms 16120 KB Output is correct
29 Correct 167 ms 16120 KB Output is correct
30 Correct 9 ms 9728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 10 ms 9728 KB Output is correct
2 Correct 189 ms 14464 KB Output is correct
3 Correct 191 ms 14464 KB Output is correct
4 Correct 189 ms 14584 KB Output is correct
5 Correct 182 ms 14584 KB Output is correct
6 Correct 188 ms 14464 KB Output is correct
7 Correct 183 ms 14464 KB Output is correct
8 Correct 180 ms 14584 KB Output is correct
9 Correct 196 ms 14464 KB Output is correct
10 Correct 197 ms 14464 KB Output is correct
11 Correct 168 ms 14464 KB Output is correct
12 Correct 175 ms 15060 KB Output is correct
13 Correct 169 ms 15064 KB Output is correct
14 Correct 167 ms 15072 KB Output is correct
15 Correct 172 ms 14976 KB Output is correct
16 Correct 167 ms 14976 KB Output is correct
17 Correct 165 ms 14976 KB Output is correct
18 Correct 147 ms 14976 KB Output is correct
19 Correct 143 ms 14976 KB Output is correct
20 Correct 9 ms 9728 KB Output is correct
21 Correct 224 ms 15352 KB Output is correct
22 Correct 231 ms 15352 KB Output is correct
23 Correct 224 ms 15232 KB Output is correct
24 Correct 228 ms 15232 KB Output is correct
25 Correct 229 ms 15352 KB Output is correct
26 Correct 230 ms 15232 KB Output is correct
27 Correct 230 ms 15352 KB Output is correct
28 Correct 149 ms 15232 KB Output is correct
29 Correct 146 ms 15232 KB Output is correct
30 Correct 9 ms 9728 KB Output is correct
31 Correct 9 ms 9728 KB Output is correct
32 Correct 9 ms 9728 KB Output is correct
33 Correct 9 ms 9728 KB Output is correct
34 Correct 9 ms 9728 KB Output is correct
35 Correct 10 ms 9728 KB Output is correct
36 Correct 9 ms 9728 KB Output is correct
37 Correct 9 ms 9728 KB Output is correct
38 Correct 9 ms 9728 KB Output is correct
39 Correct 9 ms 9728 KB Output is correct
40 Correct 9 ms 9728 KB Output is correct
41 Correct 17 ms 9856 KB Output is correct
42 Correct 17 ms 9856 KB Output is correct
43 Correct 17 ms 9856 KB Output is correct
44 Correct 20 ms 9984 KB Output is correct
45 Correct 17 ms 9856 KB Output is correct
46 Correct 17 ms 9856 KB Output is correct
47 Correct 17 ms 9856 KB Output is correct
48 Correct 17 ms 9856 KB Output is correct
49 Correct 16 ms 9856 KB Output is correct
50 Correct 9 ms 9728 KB Output is correct
51 Correct 263 ms 16120 KB Output is correct
52 Correct 273 ms 16252 KB Output is correct
53 Correct 261 ms 16128 KB Output is correct
54 Correct 263 ms 16200 KB Output is correct
55 Correct 260 ms 16120 KB Output is correct
56 Correct 266 ms 16248 KB Output is correct
57 Correct 259 ms 16248 KB Output is correct
58 Correct 158 ms 16120 KB Output is correct
59 Correct 167 ms 16120 KB Output is correct
60 Correct 9 ms 9728 KB Output is correct
61 Correct 293 ms 20012 KB Output is correct
62 Correct 291 ms 19960 KB Output is correct
63 Correct 294 ms 19960 KB Output is correct
64 Correct 291 ms 19960 KB Output is correct
65 Correct 286 ms 20088 KB Output is correct
66 Correct 285 ms 20088 KB Output is correct
67 Correct 290 ms 20088 KB Output is correct
68 Correct 298 ms 20032 KB Output is correct
69 Correct 265 ms 16248 KB Output is correct
70 Correct 9 ms 9760 KB Output is correct