Submission #463684

#TimeUsernameProblemLanguageResultExecution timeMemory
463684Hamed5001Vudu (COCI15_vudu)C++14
42 / 140
1095 ms62132 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; map<int, int> ID; const int mxN = 1e6+100; int BIT[mxN], N, P, id = 1; void add(int idx, int delta) { for (; idx < id; idx += idx & -idx) BIT[idx] += delta; } int query(int idx) { int ret = 0; for (; idx > 0; idx -= idx & -idx) ret += BIT[idx]; return ret; } void solve() { cin >> N; vector<int> A(N); for (auto& a : A) scanf("%d", &a); cin >> P; for (auto& a : A) a-=P; vector<int> 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<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("%d", &a);
      |                    ~~~~~^~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...