답안 #542480

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
542480 2022-03-26T18:55:00 Z Olympia Vudu (COCI15_vudu) C++17
42 / 140
418 ms 65536 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{
    vector<int> bit; //1-indexed
    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 < bit.size()){
            bit[ind] += val;
            ind += ind & (-ind);
        }
    }
    void construct(int x){
        bit.resize(x+ 1);
    }
};
int main() {
    //freopen("balancing.in", "r", stdin);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int N; cin >> N;
    vector<int64_t> pref = {0};
    for (int i = 0; i < N; i++) {
        int64_t x; cin >> x; pref.push_back(pref.back() + x);
    }
    set<int64_t> s;
    int64_t P; cin >> P;
    for (int i = 0; i <= N; i++) {
        s.insert(pref[i] - P * i);
    }
    BIT b; b.construct(N + 1);
    map<int64_t,int> myMap; int cntr = 0;
    for (int64_t i: s) {
        myMap[i] = cntr++;
    }
    int64_t c = 0;
    for (int r = 0; r < N; r++) {
        b.update(myMap[pref[r] - P * r], 1);
        c += (int64_t)b.sum(0, myMap[pref[r + 1] - P * (r + 1)]);
    }
    cout << c;
}

Compilation message

vudu.cpp: In member function 'void BIT::update(int, int)':
vudu.cpp:34:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   34 |         while(ind < bit.size()){
      |               ~~~~^~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 7 ms 1108 KB Output is correct
2 Correct 5 ms 852 KB Output is correct
3 Correct 4 ms 852 KB Output is correct
4 Runtime error 418 ms 65536 KB Execution killed with signal 9
5 Runtime error 322 ms 65536 KB Execution killed with signal 9
6 Runtime error 350 ms 65536 KB Execution killed with signal 9
7 Runtime error 363 ms 65536 KB Execution killed with signal 9
8 Runtime error 325 ms 65536 KB Execution killed with signal 9
9 Runtime error 358 ms 65536 KB Execution killed with signal 9
10 Runtime error 401 ms 65536 KB Execution killed with signal 9