Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _USE_MATH_DEFINES
- #define _CRT_SECURE_NO_WARNINGS
- #include <bits/stdc++.h>
- using namespace std;
- #define forn(i, n) for(int i = 0; i < n; i++)
- #define fore(i, l, r) for(int i = int(l); i < int(r); i++)
- #define sqr(a) ((a) * (a))
- #define sz(a) int(a.size())
- #define all(a) a.begin(), a.end()
- #define x first
- #define y second
- #define pb push_back
- #define mp make_pair
- template<class A, class B> ostream& operator <<(ostream &out, const pair<A, B> &p) {
- return out << "(" << p.x << ", " << p.y << ")";
- }
- template<class T> ostream& operator <<(ostream &out, const vector<T> &v) {
- out << "[";
- forn(i, sz(v) - 1)
- out << v[i] << ", ";
- return out << v.back() << "]";
- }
- typedef long double ld;
- typedef long long li;
- typedef pair <int, int> pt;
- const ld EPS = 1e-9;
- const int INF = int(1e9);
- const li INF64 = li(1e18);
- const int N = 100 * 1000 + 11;
- int n;
- int a[N];
- pt mnl[N], mnr[N];
- inline bool read() {
- if(scanf("%d", &n) != 1)
- return false;
- forn(i, n) scanf("%d", &a[i]);
- return true;
- }
- struct triplet{
- int x, y, z;
- };
- bool operator ==(const triplet &a, const triplet &b){
- return a.x == b.x && a.y == b.y && a.z == b.z;
- }
- void norm(triplet &p){
- if (p.y < p.x)
- swap(p.y, p.x);
- if (p.z < p.x)
- swap(p.z, p.x);
- if (p.z < p.y)
- swap(p.z, p.y);
- }
- void solve() {
- nth_element(a, a + 2, a + n);
- triplet mns = {a[0], a[1], a[2]};
- norm(mns);
- mnl[0] = mp(a[0], 1);
- mnr[n - 1] = mp(a[n - 1], 1);
- for(int i = 1; i < n; i++) {
- if(a[i] < mnl[i - 1].x)
- mnl[i] = mp(a[i], 1);
- else if(a[i] == mnl[i - 1].x)
- mnl[i] = mp(mnl[i - 1].x, mnl[i - 1].y + 1);
- else
- mnl[i] = mnl[i - 1];
- }
- for(int i = n - 2; i >= 0; i--) {
- if(a[i] < mnr[i + 1].x)
- mnr[i] = mp(a[i], 1);
- else if(a[i] == mnr[i + 1].x)
- mnr[i] = mp(mnr[i + 1].x, mnr[i + 1].y + 1);
- else
- mnr[i] = mnr[i + 1];
- }
- li ans = 0;
- triplet cmns;
- for(int i = 1; i < n - 1; i++) {
- cmns = {mnl[i - 1].x, a[i], mnr[i + 1].x};
- norm(cmns);
- if(mns == cmns)
- ans += mnl[i - 1].y * 1ll * mnr[i + 1].y;
- }
- printf("%lld\n", ans);
- }
- int main() {
- #ifdef _DEBUG
- int t = 0;
- freopen("input.txt", "r", stdin);
- // freopen("output.txt", "w", stdout);
- #endif
- cout << fixed << setprecision(15);
- while(read()) {
- solve();
- #ifdef _DEBUG
- cerr << "TIME = " << clock() - t << endl;
- t = clock();
- #endif
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement