답안 #532390

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
532390 2022-03-02T20:18:36 Z Vladth11 Vudu (COCI15_vudu) C++14
42 / 140
366 ms 65540 KB
#include <bits/stdc++.h>
#define debug(x) cerr << #x << " " << x << "\n"
#define debugs(x) cerr << #x << " " << x << " "

using namespace std;
typedef long long ll;
typedef pair <ll, ll> pii;
typedef pair <long double, pii> muchie;

const ll NMAX = 1000001;
const ll VMAX = 1000001;
const ll INF = (1LL << 60);
const ll MOD = 1000000007;
const ll BLOCK = 447;
const ll nr_of_bits = 21;

ll s[NMAX];
int v[NMAX];
map <ll, ll> mp;
int aib[NMAX + 1];

void update(int node, int x){
    for(; node <= NMAX; node += node&(-node))
        aib[node] += x;
}

int query(int node){
    int x = 0;
    if(node > NMAX)
        return 0;
    for(; node > 0; node -= node&(-node))
        x += aib[node];
    return x;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, i;
    cin >> n;
    for(i = 1; i <= n; i++){
        cin >> v[i];
    }
    int p;
    cin >> p;
    vector <int> a;
    for(i = 1; i <= n; i++){
        v[i] = v[i] - p;
        s[i] = s[i - 1] + 1LL * v[i];
        a.push_back(s[i]);
    }
    a.push_back(0);
    sort(a.begin(), a.end());
    int cnt = 0;
    for(int i = 0; i < a.size(); i++){
        if(i == 0 || a[i] != a[i - 1])
            cnt++;
        mp[a[i]] = cnt;
    }
    ll sol = 0;
    update(mp[0] + 1, 1);
    for(i = 1; i <= n; i++){
        s[i] = mp[s[i]] +  1; /// sa devina si 0 -> 1
        sol += 1LL * query(s[i]);
        update(s[i], 1);
    }
    cout << sol;
    return 0;
}

Compilation message

vudu.cpp: In function 'int main()':
vudu.cpp:56:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   56 |     for(int i = 0; i < a.size(); i++){
      |                    ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 844 KB Output is correct
2 Correct 3 ms 716 KB Output is correct
3 Correct 3 ms 716 KB Output is correct
4 Runtime error 342 ms 65540 KB Execution killed with signal 9
5 Runtime error 365 ms 65540 KB Execution killed with signal 9
6 Runtime error 340 ms 65540 KB Execution killed with signal 9
7 Runtime error 353 ms 65540 KB Execution killed with signal 9
8 Runtime error 318 ms 65540 KB Execution killed with signal 9
9 Runtime error 366 ms 65540 KB Execution killed with signal 9
10 Runtime error 355 ms 65540 KB Execution killed with signal 9