답안 #542487

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
542487 2022-03-26T19:01:30 Z Olympia Vudu (COCI15_vudu) C++17
42 / 140
371 ms 15956 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:
    int pref, 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);
    }
    int 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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 4308 KB Output is correct
2 Correct 3 ms 4308 KB Output is correct
3 Correct 3 ms 4180 KB Output is correct
4 Incorrect 366 ms 15536 KB Output isn't correct
5 Incorrect 202 ms 10628 KB Output isn't correct
6 Incorrect 339 ms 14252 KB Output isn't correct
7 Incorrect 332 ms 14676 KB Output isn't correct
8 Incorrect 288 ms 13268 KB Output isn't correct
9 Incorrect 371 ms 15956 KB Output isn't correct
10 Incorrect 330 ms 14392 KB Output isn't correct