Submission #542489

# Submission time Handle Problem Language Result Execution time Memory
542489 2022-03-26T19:02:07 Z Olympia Vudu (COCI15_vudu) C++17
42 / 140
254 ms 19856 KB
#include <vector>
#include <algorithm>
#include <iostream>
#include <set>
#include <cmath>
#include <map>
#include <random>
#include <cassert>
#include <ctime>
#include <cstdlib>
#include <queue>
#include <limits.h>
using namespace std;
struct BIT{
    int bit[(int)1e6 + 5];
    int pref(long long ind){
        int ans = 0;
        ind++;
        while(ind > 0){
            //cout << ind << " ";
            ans += bit[ind];
            ind -= (ind & (-ind));
        }
        return ans;
    }
    int sum(long long l, long long r){
        if(l == 0){
            return pref(r);
        }
        return pref(r) - pref(l - 1);
    }
    void update(int ind, int val){
        ind++;
        while(ind < (int)1e6 + 5){
            bit[ind] += val;
            ind += ind & (-ind);
        }
    }
};
struct Triple {
public:
    int64_t pref;
    int ind;
    int place = 0;
    Triple () {

    }
    Triple (int pref, int ind) {
        this->pref = pref, this->ind = ind;
    }
};
bool cmp1 (Triple t1, Triple t2) {
    if (t1.pref == t2.pref) return (t1.ind < t2.ind);
    return (t1.pref < t2.pref);
}
bool cmp2 (Triple t1, Triple t2) {
    return (t1.ind < t2.ind);
}
int main() {
    //freopen("balancing.in", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N; cin >> N;
    Triple pref[N + 1];
    pref[0] = Triple(0, 0);
    for (int i = 0; i < N; i++) {
        int64_t x; cin >> x;
        pref[i + 1] = Triple(pref[i].pref + x, i + 1);
    }
    int64_t P; cin >> P;
    for (int i = 0; i <= N; i++) {
        pref[i].pref = pref[i].pref - P * i;
    }
    sort(pref, pref + N + 1, cmp1);
    for (int i = 0; i <= N; i++) {
        pref[i].place = i;
    }
    sort(pref, pref + N + 1, cmp2);
    BIT b;
    int64_t c = 0;
    for (int r = 0; r < N; r++) {
        b.update(pref[r].place, 1);
        c += (int64_t)b.sum(0, pref[r + 1].place);
    }
    cout << c;
}
# Verdict Execution time Memory Grader output
1 Correct 4 ms 4308 KB Output is correct
2 Correct 4 ms 4308 KB Output is correct
3 Correct 4 ms 4308 KB Output is correct
4 Incorrect 236 ms 19328 KB Output isn't correct
5 Incorrect 133 ms 12768 KB Output isn't correct
6 Incorrect 222 ms 17492 KB Output isn't correct
7 Incorrect 224 ms 18132 KB Output isn't correct
8 Incorrect 184 ms 16232 KB Output isn't correct
9 Incorrect 254 ms 19856 KB Output isn't correct
10 Incorrect 207 ms 17788 KB Output isn't correct