Submission #1066311

#TimeUsernameProblemLanguageResultExecution timeMemory
1066311tamthegodMountains (NOI20_mountains)C++17
100 / 100
171 ms19176 KiB
#include<bits/stdc++.h> #define int long long #define pb push_back #define fi first #define se second using namespace std; using ll = long long; using ld = long double; using ull = unsigned long long; mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); const int maxN = 1e6 + 5; const int mod = 1e9 + 7; const ll oo = 1e18; int n, a[maxN]; vector<int> vc; struct BIT { vector<int> bit; int n; void init(int _n) { n = _n; bit.resize(n + 5, 0); } void update(int pos, int val) { for(; pos <= n; pos += (pos & (-pos))) bit[pos] += val; } int get(int pos) { int res = 0; for(; pos; pos -= (pos & (-pos))) res += bit[pos]; return res; } }; void ReadInput() { cin >> n; for(int i=1; i<=n; i++) { cin >> a[i]; vc.pb(a[i]); } sort(vc.begin(), vc.end()); vc.erase(unique(vc.begin(), vc.end()), vc.end()); for(int i=1; i<=n; i++) a[i] = upper_bound(vc.begin(), vc.end(), a[i]) - vc.begin(); } void Solve() { BIT pref, suff; pref.init(n); suff.init(n); for(int i=2; i<=n; i++) suff.update(a[i], 1); pref.update(a[1], 1); int res = 0; for(int i=2; i<n; i++) { suff.update(a[i], - 1); res += pref.get(a[i] - 1) * suff.get(a[i] - 1); pref.update(a[i], 1); } cout << res; } #define taskname "" int32_t main() { if (fopen(taskname ".inp", "r")) { freopen(taskname ".inp", "r", stdin); freopen(taskname ".out", "w", stdout); } ios_base::sync_with_stdio(false); cin.tie(nullptr); int T = 1; //cin >> T; for(int itest=1; itest<=T; itest++) { ReadInput(); Solve(); } }

Compilation message (stderr)

Mountains.cpp: In function 'int32_t main()':
Mountains.cpp:75:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   75 |         freopen(taskname ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Mountains.cpp:76:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   76 |         freopen(taskname ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...