Submission #924106

#TimeUsernameProblemLanguageResultExecution timeMemory
924106TINVudu (COCI15_vudu)C++17
112 / 140
469 ms65536 KiB
#include <bits/stdc++.h> using namespace std; #define FNAME "test" #define sz(v) (int) (v).size() #define all(v) (v).begin(), (v).end() typedef long long ll; const int N = 1e6 + 5; int n; ll a[N]; ll P; ll sum; vector<ll> pre; ll ans = 0; struct Fenwick { int n; vector<ll> f; Fenwick(int n) : n(n), f(n + 1, 0) {} void set(ll i) { for (; i <= n; i += i & (-i)) f[i]++; } ll get(ll i) const { ll r = 0; for (; i >= 1; i -= i &(-i)) r += f[i]; return r; } }; void Task() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout << fixed << setprecision(9); if (fopen(FNAME".inp","r")) { freopen(FNAME".inp","r",stdin); freopen(FNAME".out","w",stdout); } } void compress(vector<ll>& a) { set<ll> s(a.begin(), a.end()); vector<ll> b(s.begin(), s.end()); for (ll &x : a) x = lower_bound(b.begin(), b.end(), x) - b.begin() + 1; } void Solve() { //Your Code cin >> n; for (int i = 1; i <= n; i++) cin >> a[i]; cin >> P; sum = 0; pre.clear(); pre.push_back(sum); for (int i = 1; i <= n; i++) { sum += a[i] - P; pre.push_back(sum); } compress(pre); Fenwick BIT(sz(pre) + 1); for (int i = 1; i <= n; i++) { BIT.set(pre[i - 1]); ans += BIT.get(pre[i]); } cout << ans << '\n'; } int main() { Task(); Solve(); cerr << "\nTime run: " << 1000*clock()/CLOCKS_PER_SEC << "ms"; return 37^37; }

Compilation message (stderr)

vudu.cpp: In function 'void Task()':
vudu.cpp:43:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   43 |   freopen(FNAME".inp","r",stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
vudu.cpp:44:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   44 |   freopen(FNAME".out","w",stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...