Submission #1313391

#TimeUsernameProblemLanguageResultExecution timeMemory
1313391levMountains (NOI20_mountains)C++20
2 / 100
34 ms6480 KiB
#include <bits/stdc++.h> #define ll long long #define fi first #define se second #define pii pair<int, int> #define all(a) a.begin(), a.end() using namespace std; #ifdef LOCAL #include "C:\Users\Dell\Downloads\template\template\icpc-notebook\Utilities\debug.h" #else #define debug(...) 42 #endif const int mn = 5e5 + 5, mod = 1e9 + 7, inf = 2e9; int n, a[mn]; vector <int> line[mn]; int bit[mn]; void add(int u, int val){ while(u <= n){ bit[u] += val; u += (u & -u); } } int get(int u){ int r = 0; while(u){ r += bit[u]; u -= (u & -u); } return r; } int get(int l, int r){ return get(r) - get(l - 1); } void solve() { cin >> n; vector <int> comp; // Compressed for(int i = 1; i <= n; i++){ cin >> a[i]; comp.push_back(a[i]); } sort(all(comp)); comp.erase(unique(all(comp)), comp.end()); for(int i = 1; i <= n; i++){ a[i] = lower_bound(all(comp), a[i]) - comp.begin() + 1; line[a[i]].push_back(i); } int res = 0; for(int i = 1; i <= (int)comp.size(); i++){ for(auto x : line[i]){ if(x > 1 && x < n) res += get(1, x - 1) * get(x + 1, n); } for(auto x : line[i]) add(x, 1); } cout << res << '\n'; } signed main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); #define task "Kawabata" if (fopen(task".INP", "r")) { freopen(task".INP", "r", stdin); freopen(task".OUT", "w", stdout); } int t = 1; // cin >> t; while (t--) solve(); return 0; } // Don't wanna lose anymore T_T // Never let me go - Kazuo Ishiguro

Compilation message (stderr)

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