답안 #532397

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
532397 2022-03-02T20:31:23 Z Vladth11 Vudu (COCI15_vudu) C++14
140 / 140
911 ms 65536 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];
unordered_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 >> s[i];
    }
    int p;
    cin >> p;
    vector <ll> a;
    for(i = 1; i <= n; i++){
        s[i] = s[i] - p;
        s[i] = s[i - 1] + 1LL * s[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);
    for(i = 1; i <= n; i++){
        s[i] = mp[s[i]]; /// 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:55:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   55 |     for(int i = 0; i < a.size(); i++){
      |                    ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 716 KB Output is correct
2 Correct 2 ms 716 KB Output is correct
3 Correct 2 ms 588 KB Output is correct
4 Correct 828 ms 65536 KB Output is correct
5 Correct 412 ms 33788 KB Output is correct
6 Correct 750 ms 56500 KB Output is correct
7 Correct 781 ms 60460 KB Output is correct
8 Correct 660 ms 51636 KB Output is correct
9 Correct 911 ms 65536 KB Output is correct
10 Correct 758 ms 57600 KB Output is correct