답안 #158390

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
158390 2019-10-16T21:25:16 Z nickmet2004 Arranging Shoes (IOI19_shoes) C++14
0 / 100
162 ms 135160 KB
#include<bits/stdc++.h>
//#include<shoes.h>

using namespace std;

const int NAX = 1e5 + 5;
const int l = 1e5 + 5;

int N;
// fenwick tree to count range sums (+0 , +1 , +2)

int f[2 * NAX + 1];

void update(int idx , int u){
    ++idx;
    while(idx <= N){
        f[idx] += u;
        idx += idx & (-idx);
    }
}
long long sum(int idx){
    long long sum = 0;
    ++idx;
    while(idx){
        sum += f[idx];
        idx -= idx & (-idx);
    }
    return sum;
}
queue<int> q[2 * NAX + 200];

long long count_swaps(vector<int> S){
    N = S.size();
    long long ans = 0;
    // update BIT
    for(int i = 0; i < N; ++i){
        update(i , 1);
    }
    for(int i = 0; i < N; ++i){
        int x = abs(S[i]);
        int k = S[i];
        if(!q[i + l].empty()){
            ans += (sum(i) - (q[i + l].front() - 1) - 1);
            if(k > 0){
                --ans;
            }
            update(i , -1);
            update(q[i + l].front() , 1);
        } else {
            // q[i * -1 + l] because its opposite is the same as the next x
            // i * -1 + l == next_x(i + l)
            q[i * -1 + l].push(i);
        }
    }
    return ans;
}

Compilation message

shoes.cpp: In function 'long long int count_swaps(std::vector<int>)':
shoes.cpp:40:13: warning: unused variable 'x' [-Wunused-variable]
         int x = abs(S[i]);
             ^
# 결과 실행 시간 메모리 Grader output
1 Correct 157 ms 135056 KB Output is correct
2 Incorrect 162 ms 135004 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 157 ms 135056 KB Output is correct
2 Incorrect 162 ms 135004 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 157 ms 135056 KB Output is correct
2 Incorrect 162 ms 135004 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 155 ms 135036 KB Output is correct
2 Incorrect 150 ms 135160 KB Output isn't correct
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 157 ms 135056 KB Output is correct
2 Incorrect 162 ms 135004 KB Output isn't correct
# 결과 실행 시간 메모리 Grader output
1 Correct 157 ms 135056 KB Output is correct
2 Incorrect 162 ms 135004 KB Output isn't correct