Submission #204725

# Submission time Handle Problem Language Result Execution time Memory
204725 2020-02-26T18:47:33 Z Kastanda Bubble Sort 2 (JOI18_bubblesort2) C++11
0 / 100
33 ms 1524 KB
// In The Name Of The Queen
#include<bits/stdc++.h>
#include "bubblesort2.h"
#define lc (id << 1)
#define rc (lc ^ 1)
#define md (l + r >> 1)
using namespace std;
const int N = 500005, MXS = N * 2 * 4;
int n, q, MX[MXS], LZ[MXS];
vector < pair < int , int > > U;
void Add(int le, int ri, int val, int id = 1, int l = 0, int r = (int)U.size())
{
    if (ri <= l || r <= le)
        return ;
    if (le <= l && r <= ri)
    {
        MX[id] += val;
        LZ[id] += val;
        return ;
    }
    Add(le, ri, val, lc, l, md);
    Add(le, ri, val, rc, md, r);
    MX[id] = max(MX[lc], MX[rc]) + LZ[id];
}
vector < int > countScans(vector < int > A, vector < int > X, vector < int > V)
{
    n = (int)A.size();
    q = (int)X.size();
    for (int i = 0; i < n; i ++)
        U.push_back({A[i], i});
    for (int i = 0; i < q; i ++)
        U.push_back({V[i], X[i]});
    sort(U.begin(), U.end());
    U.resize(unique(U.begin(), U.end()) - U.begin());

    auto GetId = [&] (pair < int , int > val) {
        return (int)(lower_bound(U.begin(), U.end(), val) - U.begin());
    };

    auto Apply = [&] (int i, int val) {
        int p = GetId({A[i], i});
        Add(p, p + 1, i * val);
        int l = GetId({A[i], -1});
        Add(l, (int)U.size(), val);
    };

    for (int i = 0; i < n; i ++)
        Apply(i, 1);
    vector < int > R;
    for (int i = 0; i < q; i ++)
    {
        Apply(X[i], -1);
        A[X[i]] = V[i];
        Apply(X[i], 1);
        R.push_back(MX[1]);
    }
    return (R);
}

Compilation message

bubblesort2.cpp: In function 'void Add(int, int, int, int, int, int)':
bubblesort2.cpp:6:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
 #define md (l + r >> 1)
             ~~^~~
bubblesort2.cpp:21:29: note: in expansion of macro 'md'
     Add(le, ri, val, lc, l, md);
                             ^~
bubblesort2.cpp:6:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
 #define md (l + r >> 1)
             ~~^~~
bubblesort2.cpp:22:26: note: in expansion of macro 'md'
     Add(le, ri, val, rc, md, r);
                          ^~
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 33 ms 1524 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 6 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -