Submission #463702

#TimeUsernameProblemLanguageResultExecution timeMemory
463702Hamed5001Vudu (COCI15_vudu)C++14
56 / 140
1093 ms65540 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; unordered_map<ll, ll> ID; const int mxN = 1e6+100; ll BIT[mxN], N, P, id = 1; void add(int idx, ll delta) { for (; idx < id; idx += idx & -idx) BIT[idx] += delta; } ll query(int idx) { ll ret = 0; for (; idx > 0; idx -= idx & -idx) ret += BIT[idx]; return ret; } void solve() { cin >> N; vector<ll> A(N); for (auto& a : A) scanf("%lld", &a); cin >> P; for (auto& a : A) a-=P; vector<ll> AA; ll sum = 0; AA.push_back(sum); for (auto& a : A) { sum += a; AA.push_back(sum); } sort(AA.rbegin(), AA.rend()); for (int i = 0; i < AA.size(); ++i) { if (!ID[AA[i]]) ID[AA[i]] = id++; } for (auto& aa : AA) { add(ID[aa], 1); } add(ID[0], -1); sum = 0; ll ans = 0; for (auto a : A) { ans += query(ID[sum]); sum += a; add(ID[sum], -1); } printf("%lld", ans); } int main() { solve(); }

Compilation message (stderr)

vudu.cpp: In function 'void solve()':
vudu.cpp:41:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   41 |  for (int i = 0; i < AA.size(); ++i) {
      |                  ~~^~~~~~~~~~~
vudu.cpp:25:25: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   25 |  for (auto& a : A) scanf("%lld", &a);
      |                    ~~~~~^~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...