제출 #679048

#제출 시각아이디문제언어결과실행 시간메모리
679048kussssoArranging Shoes (IOI19_shoes)C++17
0 / 100
26 ms47316 KiB
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 1e6 + 5;

int n;
int a[N], bit[N];
ll ans;
vector<int> pos[N][2];

void Update (int p, int v) {
    for (int i = p; i < N; i += i & -i) bit[i] += v;
}

int Get (int p) {
    int ret = 0;
    for (int i = p; i >= 1; i -= i & -i) ret += bit[i];
    return ret;
}

int Get (int l, int r) {
    return Get(r) - Get(l - 1);
}

ll count_swaps (vector<int> S) {
    n = S.size();
    int j;
    for (int i = 0, j = 3; i < n; i++, j += 3) {
        a[j] = S[i];
        Update(j, 1);
        pos[abs(a[j])][a[j] < 0].push_back(j);
    }
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j < 2; j++) {
            reverse(pos[i][j].begin(), pos[i][j].end());
        }
    }
    n = j;
    for (int i = 3; i <= n; i += 3) {
        if (!a[i]) 
            continue;
        
        int t = (a[i] < 0);
        int j = pos[abs(a[i])][t ^ 1].back();
        pos[abs(a[i])][t ^ 1].pop_back();
        pos[abs(a[i])][t].pop_back();
        Update(j, -1);
        a[j] = 0;
        ans += (a[i] < 0 ? Get(i + 1, j) : Get(i, j));
    }   
    return ans;
}

// signed main() {
    // ios_base::sync_with_stdio(0);
    // cin.tie(0);
//     
    // vector<int> S = {2, 1, -1, -2};
    // cout << count_swaps(S);
//     
    // return 0;
// }

컴파일 시 표준 에러 (stderr) 메시지

shoes.cpp: In function 'll count_swaps(std::vector<int>)':
shoes.cpp:38:7: warning: 'j' is used uninitialized in this function [-Wuninitialized]
   38 |     n = j;
      |     ~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...