답안 #650063

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
650063 2022-10-12T08:19:59 Z boris_mihov Bubble Sort 2 (JOI18_bubblesort2) C++17
0 / 100
267 ms 676 KB
#include "bubblesort2.h"
#include <algorithm>
#include <iostream>
#include <numeric>
#include <vector>

typedef long long llong;
const int MAXN = 500000 + 10;
const int INF  = 1e9;

int a[MAXN], n;
int smaller[MAXN];
std::vector <int> ans;
int cnt;

void add(int idx)
{
    smaller[idx] = 0;
    for (int i = idx - 1 ; i >= 1 ; --i)
    {
        smaller[i] += (a[i] > a[idx]);
        cnt += (smaller[i] == 1 && (a[i] > a[idx]));
    }

    for (int i = idx + 1 ; i <= n ; ++i)
    {
        smaller[idx] += (a[idx] > a[i]);
    }

    cnt += (smaller[idx] == 0);
}

void remove(int idx)
{
    for (int i = idx - 1 ; i >= 1 ; --i)
    {
        smaller[i] -= (a[i] > a[idx]);
        cnt -= (smaller[i] == 0 && a[i] > a[idx]);
    }
}

std::vector<int> countScans(std::vector<int> A,std::vector<int> X,std::vector<int> V)
{
    n = A.size();
    for (int i = 1 ; i <= n ; ++i) a[i] = A[i-1];

    cnt = n;
    for (int i = 1 ; i <= n ; ++i)
    {
        for (int j = i + 1 ; j <= n ; ++j)
        {
            smaller[i] += (a[i] > a[j]);
        }

        cnt -= (smaller[i] == 0);
    }

    ans.resize(X.size());
    for (int i = 0 ; i < X.size() ; --i)
    {
        remove(X[i] + 1);   
        a[X[i] + 1] = V[i];
        add(X[i] + 1);   
        ans[i] = cnt;
    }

    return ans;
}

Compilation message

bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:59:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   59 |     for (int i = 0 ; i < X.size() ; --i)
      |                      ~~^~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 267 ms 676 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -