Submission #226363

#TimeUsernameProblemLanguageResultExecution timeMemory
226363ezdpMountains (NOI20_mountains)C++14
100 / 100
192 ms17784 KiB
/** link: https://oj.uz/problem/view/NOI20_mountains */ #include<bits/stdc++.h> #define endl '\n' #define pb push_back #define fr first #define sc second #define ll long long int #define bit(idx) idx&(-idx) #define bin(x, a) bitset<a>(x) #define all(A) A.begin(), A.end() #define debug(x) cout << #x << " = " << x << endl; using namespace std; const int MAXN = 3e5 + 5; ll n, A[MAXN], BIT[MAXN], tmp[MAXN], sz; void upd(int idx){ for(int _idx = idx + 1; _idx < MAXN; _idx += bit(_idx)){ ++ BIT[_idx]; } } ll qry(int idx){ ll ret = 0; for(int _idx = idx + 1; _idx > 0; _idx -= bit(_idx)){ ret += BIT[_idx]; } return ret; } int main(){ ios_base::sync_with_stdio(NULL); cin.tie(); cout.tie(); cin >> n; for(int i = 0; i < n; i ++){ cin >> A[i]; tmp[sz ++] = A[i]; } sort(tmp, tmp + sz); sz = unique(tmp, tmp + sz) - tmp; for(int i = 0; i < n; i ++) A[i] = lower_bound(tmp, tmp + sz, A[i]) - tmp; ll L[MAXN] = {0}, R[MAXN] = {0}; for(int i = 0; i < n; i ++){ L[i] = qry(A[i] - 1); upd(A[i]); } memset(BIT, 0, sizeof(BIT)); for(int i = n - 1; i >= 0; i --){ R[i] = qry(A[i] - 1); upd(A[i]); } /// cout << "A: "; for(int i = 0; i < n; i ++) cout << A[i] << " "; cout << endl; /// cout << "L: "; for(int i = 0; i < n; i ++) cout << L[i] << " "; cout << endl; /// cout << "R: "; for(int i = 0; i < n; i ++) cout << R[i] << " "; cout << endl; ll ans = 0; for(int i = 0; i < n; i ++) ans += L[i] * R[i]; cout << ans << endl; } /** 5 0 1 1 0 1 2 6 500 20 900 0 900 70 7 */
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...