Submission #261731

# Submission time Handle Problem Language Result Execution time Memory
261731 2020-08-12T03:20:40 Z HynDuf Vudu (COCI15_vudu) C++14
140 / 140
406 ms 33620 KB
#include <bits/stdc++.h>

#define task "V"
#define all(v) (v).begin(), (v).end()
#define rep(i, l, r) for (int i = (l); i <= (r); ++i)
#define Rep(i, r, l) for (int i = (r); i >= (l); --i)
#define DB(X) { cerr << #X << " = " << (X) << '\n'; }
#define DB1(A, _) { cerr << #A << "[" << _ << "] = " << (A[_]) << '\n'; }
#define DB2(A, _, __) { cerr << #A << "[" << _ << "][" << __ << "] = " << (A[_][__]) << '\n'; }
#define DB3(A, _, __, ___) { cerr << #A << "[" << _ << "][" << __ << "][" << ___ << "] = " << (A[_][__][___]) << '\n'; }
#define PR(A, l, r) { cerr << '\n'; rep(_, l, r) DB1(A, _); cerr << '\n';}
#define SZ(x) ((int)(x).size())
#define pb push_back
#define eb emplace_back
#define pf push_front
#define F first
#define S second
#define by(x) [](const auto& a, const auto& b) { return a.x < b.x; } // sort(arr, arr + N, by(a));
#define next ___next
#define prev ___prev
#define y1 ___y1
#define left ___left
#define right ___right
#define y0 ___y0
#define div ___div
#define j0 ___j0
#define jn ___jn

using ll = long long;
using ld = long double;
using ull = unsigned long long;
using namespace std;
typedef pair<int, int> ii;
typedef pair<ii, int> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<ll> vl;
const int N = 1e6 + 2;
int n, a[N], P, bit[N];
ll s[N], ans;
vector<ll> com;
void upd(int p)
{
    for (; p <= n + 1; p += p & (-p)) bit[p]++;
}
int query(int p)
{
    int res = 0;
    for (; p; p -= p & (-p)) res += bit[p];
    return res;
}
int main()
{
#ifdef HynDuf
    freopen(task".in", "r", stdin);
    //freopen(task".out", "w", stdout);
#else
    ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif
    cin >> n;
    rep(i, 1, n) cin >> a[i];
    cin >> P;
    com.eb(0);
    rep(i, 1, n) s[i] = s[i - 1] + a[i] - P, com.eb(s[i]);
    sort(all(com));
    com.erase(unique(all(com)), com.end());
    rep(i, 0, n) s[i] = lower_bound(all(com), s[i]) - com.begin() + 1;
    upd(s[0]);
    rep(i, 1, n)
    {
        ans += query(s[i]);
        upd(s[i]);
    }
    cout << ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 672 KB Output is correct
2 Correct 2 ms 640 KB Output is correct
3 Correct 2 ms 512 KB Output is correct
4 Correct 406 ms 32484 KB Output is correct
5 Correct 218 ms 20200 KB Output is correct
6 Correct 350 ms 29012 KB Output is correct
7 Correct 352 ms 30036 KB Output is correct
8 Correct 314 ms 26068 KB Output is correct
9 Correct 400 ms 33620 KB Output is correct
10 Correct 350 ms 29320 KB Output is correct