Submission #684807

#TimeUsernameProblemLanguageResultExecution timeMemory
684807US3RN4M3Vudu (COCI15_vudu)C++17
140 / 140
576 ms37656 KiB
#include<ext/pb_ds/assoc_container.hpp> #include<bits/stdc++.h> using namespace std; using namespace __gnu_pbds; using ll = long long; template<int size> struct st { st<size / 2> l, r; int val = 0; st() {} void add(int pos) { val++; if(pos < size/2) l.add(pos); else r.add(pos - size/2); } int get(int pos) { if(pos == size / 2) return l.val; else if(pos > size / 2) { return l.val + r.get(pos - size / 2); } else return l.get(pos); } }; template<> struct st<1> { int val = 0; st() {} void add(int) { val++; } int get(int) { return val; } }; st<1048576> t; main() { int n; cin >> n; vector<int> nums(n); for(int & i : nums) cin >> i; ll p; cin >> p; vector<pair<ll, int>> vals(n); ll sum = 0; ll ans = 0; for(int i = 0; i < n; i++) { sum += nums[i]; ll goal = p*(i + 1); vals[i] = {sum - goal, i}; if(sum >= goal) ans++; } sort(vals.begin(), vals.end()); for(int i = 0; i < n; i++) { ans += t.get(vals[i].second); t.add(vals[i].second); } cout << ans << endl; }

Compilation message (stderr)

vudu.cpp:36:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   36 | main() {
      | ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...