Submission #1103945

# Submission time Handle Problem Language Result Execution time Memory
1103945 2024-10-22T10:45:46 Z vladilius Bubble Sort 2 (JOI18_bubblesort2) C++17
0 / 100
234 ms 1272 KB
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
const int inf = 1e9;

struct ST{
    vector<int> a;
    int n;
    ST(int ns){
        n = ns;
        a.resize(n + 1);
    }
    void add(int l, int r, int x){
        for (int i = l; i <= r; i++){
            a[i] += x;
        }
    }
    int get(){
        int mx = 0;
        for (int i = 1; i <= n; i++){
            mx = max(mx, a[i]);
        }
        return mx;
    }
};

vector<int> countScans(vector<int> a, vector<int> p, vector<int> x){
    a.insert(a.begin(), 0);
    p.insert(p.begin(), 0);
    x.insert(x.begin(), 0);

    int n = (int) a.size() - 1;
    vector<int> all = {0};
    for (int i = 1; i <= n; i++) all.pb(a[i]);
    int q = (int) p.size() - 1;
    for (int i = 1; i <= q; i++) all.pb(x[i]);

    sort(all.begin(), all.end());
    vector<int> :: iterator it;
    vector<int> y(n + 1);
    map<int, int> mp;
    for (int i = 1; i < all.size(); i++){
        if (all[i] != all[i - 1]){
            mp[all[i]] = i;
        }
    }

    int m = (int) all.size() - 1;
    ST T(m); 
    T.add(1, m, -inf);
    auto rem = [&](int x){
        it = lower_bound(all.begin(), all.end(), all[x]);
        int j = (int) (it - all.begin());
        T.add(1, j - 1, -1);
        T.add(x, x, -inf);
    };
    
    auto add = [&](int x, int i){
        it = lower_bound(all.begin(), all.end(), all[x]);
        int j = (int) (it - all.begin());
        T.add(1, j - 1, 1);
        T.add(x, x, inf + i);
    };

    for (int i = 1; i <= n; i++){
        y[i] = mp[a[i]]++;
        add(y[i], i);
    }

    vector<int> out;
    for (int i = 1; i <= q; i++){
        rem(y[p[i]]);
        y[p[i]] = mp[x[i]]++;
        add(y[p[i]], p[i]);

        out.pb(T.get() - n);
    }
    return out;
}

Compilation message

bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:42:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |     for (int i = 1; i < all.size(); i++){
      |                     ~~^~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 234 ms 1272 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 336 KB Output isn't correct
2 Halted 0 ms 0 KB -