Submission #1235156

#TimeUsernameProblemLanguageResultExecution timeMemory
1235156CodeLakVNVudu (COCI15_vudu)C++20
140 / 140
227 ms24324 KiB
#include <bits/stdc++.h> using namespace std; #define task "main" #define no "NO" #define yes "YES" #define F first #define S second #define vec vector #define _mp make_pair #define ii pair<int, int> #define sz(x) (int)x.size() #define all(x) x.begin(), x.end() #define evoid(val) return void(std::cout << val) #define FOR(i, a, b) for(int i = (a); i <= (b); ++i) #define FOD(i, b, a) for(int i = (b); i >= (a); --i) const int MAX_N = (int)1e6 + 6; int n, p; int a[MAX_N]; int bit[MAX_N]; void update(int idx, int val) { for (; idx <= MAX_N - 2; idx += (idx & -idx)) bit[idx] += val; } int get(int idx) { int res = 0; for (; idx > 0; idx -= (idx & -idx)) res += bit[idx]; return res; } void solve() { cin >> n; FOR(i, 1, n) cin >> a[i]; cin >> p; memset(bit, 0, sizeof(bit)); vector<long long> sum(n + 1, 0); vector<long long> com; FOR(i, 1, n) { a[i] -= p; sum[i] = sum[i - 1] + 1LL * a[i]; com.push_back(sum[i]); } com.push_back(0); sort(com.begin(), com.end()); com.erase(unique(com.begin(), com.end()), com.end()); long long ans = 0; update(lower_bound(com.begin(), com.end(), 0) - com.begin() + 1, 1); FOR(i, 1, n) { sum[i] = lower_bound(com.begin(), com.end(), sum[i]) - com.begin() + 1; ans += 1LL * get(sum[i]); update(sum[i], 1); } cout << ans << "\n"; } int32_t main() { if (fopen(task".inp", "r")) { freopen(task".inp", "r", stdin); freopen(task".out", "w", stdout); } ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); bool multitest = 0; int numTest = 1; if (multitest) cin >> numTest; while (numTest--) { solve(); } return 0; } /* Lak lu theo dieu nhac!!!! */

Compilation message (stderr)

vudu.cpp: In function 'int32_t main()':
vudu.cpp:66:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   66 |         freopen(task".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
vudu.cpp:67:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   67 |         freopen(task".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...