# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
629519 | Elnady | Vudu (COCI15_vudu) | C++17 | 378 ms | 65536 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#include <unordered_map>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define endl '\n'
//#define long long long long
#define all(pr1) pr1.begin(),pr1.end()
#define alr(pr1) pr1.rbegin(),pr1.rend()
#define CEIL(pr1, pr2) (pr1 + pr2 - 1) / pr2
#define IOS std::ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define RT(s) return cout<<s,0
#define sz(s) (long long)(s.size())
const long long N = 3e5 + 9, M = 1e9 + 9, MOD = 1e9 + 7, OO = 0x3f3f3f3f, MAX = 2147483647, LOO = 0x3f3f3f3f3f3f3f3f;
int32_t main()
{
IOS;
long long n, m;
cin >> n;
vector<long long> a(n), c;
vector<pair<long long, long long>> b;
map<long long, int> mp;
for (long long i = 0; i < n; i++)
cin >> a[i];
cin >> m;
a[0] -= m;
for (long long i = 1; i < n; i++)
{
a[i] -= m;
a[i] += a[i - 1];
}
for (long long i = 0; i < n; i++)
mp[a[i]]++;
for (auto ch : mp)
b.push_back({ ch.first, ch.second });
sort(alr(b));
for (long long i = 1; i < sz(b); i++)
b[i].second += b[i - 1].second;
sort(all(b));
for (long long i = 0; i < sz(b); i++)
c.push_back(b[i].first);
tree <pair<long long, long long>, null_type, less<pair<long long, long long>>, rb_tree_tag, tree_order_statistics_node_update> st;
long long cur = 0, ans = 0;
for (long long i = 0; i < n; i++)
{
if (c.back() >= cur)
{
long long x = (lower_bound(all(c), cur) - c.begin());
long long y = (i - st.order_of_key({ cur, 0 }));
ans += (b[x].second - y);
}
st.insert({ a[i], i });
cur = a[i];
}
cout << ans << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |