Submission #253633

# Submission time Handle Problem Language Result Execution time Memory
253633 2020-07-28T13:21:45 Z Vimmer Vudu (COCI15_vudu) C++14
140 / 140
482 ms 16212 KB
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>

//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("-O3")
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize("fast-math")
//#pragma GCC optimize("no-stack-protector")

#define F first
#define S second
#define sz(x) int(x.size())
#define pb push_back
#define pf push_front
#define N 1000050
#define M ll(998244353)
#define inf 1e9 + 1e9

using namespace std;
//using namespace __gnu_pbds;

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef short int si;
typedef array <ll, 3> a3;
typedef array <ll, 4> a4;

//typedef tree <ll, null_type, less_equal<ll>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;


int t[N];

void upd(int v)
{
    for (; v >= 0; v = (v & (v + 1)) - 1) t[v]++;
}

int sm(int v)
{
    int ans = 0;

    for (; v < N; v = (v | (v + 1))) ans += t[v];

    return ans;
}

int main()
{
    //freopen("input.txt", "r", stdin); //freopen("output4.txt", "w", stdout);

    ios_base::sync_with_stdio(0); istream::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    int n;

    cin >> n;

    int a[n];

    vector <ll> gr; gr.clear();

    for (int i = 0; i < n; i++) cin >> a[i];

    ll sum = 0;

    int p;

    cin >> p;

    for (int i = 0; i < n; i++)
    {
        a[i] -= p;

        sum += ll(a[i]);

        gr.pb(sum);
    }

    sort(gr.begin(), gr.end());

    sum = 0;

    ll ans = 0;

    for (int i = 0; i < n; i++)
    {
        ll need = -a[i];

        sum += a[i];

        need += sum;

        int ind = lower_bound(gr.begin(), gr.end(), need) - gr.begin();

        ans += sz(gr) - ind;

        ans -= sm(ind);

        upd(lower_bound(gr.begin(), gr.end(), sum) - gr.begin());
    }

    cout << ans << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 5 ms 512 KB Output is correct
2 Correct 3 ms 512 KB Output is correct
3 Correct 3 ms 512 KB Output is correct
4 Correct 482 ms 15716 KB Output is correct
5 Correct 254 ms 10856 KB Output is correct
6 Correct 404 ms 13912 KB Output is correct
7 Correct 426 ms 14548 KB Output is correct
8 Correct 359 ms 12500 KB Output is correct
9 Correct 463 ms 16212 KB Output is correct
10 Correct 407 ms 14164 KB Output is correct