Submission #1095357

#TimeUsernameProblemLanguageResultExecution timeMemory
1095357kh0iMountains (NOI20_mountains)C++17
100 / 100
140 ms19460 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using pii = pair<int, int>; #define F first #define S second #define sz(x) (int)(x).size() #define all(x) (x).begin(), (x).end() mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count()); ll get_rand(ll l, ll r){ assert(l <= r); return uniform_int_distribution<ll>(l, r)(rng); } const int N = 3e5 + 3; struct Fenwick{ #define gb(x) (x) & -(x) int n; vector<ll> bit; Fenwick(int n) : n(n), bit(n + 2) {} void add(int pos, ll x){ for(; pos <= n; pos += gb(pos)) bit[pos] += x; } ll get(int l, int r){ ll res = 0; --l; for(; r > 0; r -= gb(r)) res += bit[r]; for(; l > 0; l -= gb(l)) res -= bit[l]; return res; } }; int n; ll a[N], r[N]; vector<ll> xx; void solve(){ cin >> n; for(int i = 1; i <= n; ++i){ cin >> a[i]; xx.push_back(a[i]); } sort(all(xx)); xx.resize(unique(all(xx)) - xx.begin()); for(int i = 1; i <= n; ++i) a[i] = lower_bound(all(xx), a[i]) - xx.begin() + 1; Fenwick fi(n); for(int i = n; i >= 1; --i){ r[i] = fi.get(1, a[i] - 1); fi.add(a[i], 1); } Fenwick se(n); ll res = 0; for(int i = 1; i <= n; ++i){ res += se.get(1, a[i] - 1) * r[i]; se.add(a[i], 1); } cout << res; } signed main(){ cin.tie(nullptr)->sync_with_stdio(false); #define task "troll" if(fopen(task".inp", "r")){ freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } solve(); return 0; }

Compilation message (stderr)

Mountains.cpp: In function 'int main()':
Mountains.cpp:81:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   81 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
Mountains.cpp:82:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   82 |         freopen(task".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...