Submission #758536

# Submission time Handle Problem Language Result Execution time Memory
758536 2023-06-14T19:10:21 Z Hanksburger Bubble Sort 2 (JOI18_bubblesort2) C++17
0 / 100
27 ms 1452 KB
#include "bubblesort2.h"
#include <bits/stdc++.h>
using namespace std;
int seg[1000005], lazy[1000005];
vector<pair<int, int> > vec;
vector<int> ans;
void push(int i, int l, int r)
{
    if (l==r)
    {
        seg[i]+=lazy[i];
//        cout << "seg[" << i << "] = " << seg[i] << '\n';
        lazy[i]=0;
        return;
    }
    seg[i]+=lazy[i];
//    cout << "seg[" << i << "] = " << seg[i] << '\n';
//    cout << "push to make children both lazy " << lazy[i] << '\n';
    lazy[i*2]+=lazy[i];
    lazy[i*2+1]+=lazy[i];
//    cout << "lazy[i*2] is " << lazy[i*2] << " and lazy[i*2+1] is " << lazy[i*2+1] << '\n';
    lazy[i]=0;
}
void upd(int i, int l, int r, int ql, int qr, int val)
{
//    cout << "update " << l << ' ' << r << ' ' << ql << ' ' << qr << ' ' << val << '\n';
    push(i, l, r);
    if (ql<=l && r<=qr)
    {
        lazy[i]+=val;
        push(i, l, r);
        return;
    }
    int mid=(l+r)/2;
    if (ql<=mid && l<=qr)
        upd(i*2, l, mid, ql, qr, val);
    if (ql<=r && mid+1<=qr)
        upd(i*2+1, mid+1, r, ql, qr, val);
    seg[i]=max(seg[i], max(seg[i*2], seg[i*2+1]));
//    cout << "seg[" << i << "] = " << seg[i] << " after considering " << seg[i*2] << " and " << seg[i*2+1] << '\n';
}
vector<int> countScans(vector<int> a, vector<int> x, vector<int> y)
{
    int n=a.size(), m=x.size();
    for (int i=0; i<n; i++)
        vec.push_back({a[i], i});
    for (int i=0; i<m; i++)
        vec.push_back({y[i], x[i]});
    sort(vec.begin(), vec.end());
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    int sz=vec.size();
//    for (int i=0; i<sz; i++)
//        cout << vec[i].first << ' ' << vec[i].second << '\n';
    for (int i=0; i<n; i++)
    {
        int ind=lower_bound(vec.begin(), vec.end(), make_pair(a[i], i))-vec.begin();
        int ind2=lower_bound(vec.begin(), vec.end(), make_pair(a[i]+1, 0))-vec.begin();
        upd(1, 0, sz-1, ind, ind, i);
        upd(1, 0, sz-1, ind2+1, sz-1, -1);
    }
//    cout << "seg: " << '\n';
//    for (int i=8; i<=15; i++)
//        cout << seg[i] << ' ';
//    cout << '\n';
//    for (int j=1; j<=15; j++)
//            cout << j << ' ' << seg[j] << ' ' << lazy[j] << '\n';
    for (int i=0; i<m; i++)
    {
//        cout << "i=" << i << '\n';
        int ind=lower_bound(vec.begin(), vec.end(), make_pair(a[x[i]], x[i]))-vec.begin();
        int ind2=lower_bound(vec.begin(), vec.end(), make_pair(a[x[i]]+1, 0))-vec.begin();
        upd(1, 0, sz-1, ind, ind, -x[i]);
        upd(1, 0, sz-1, ind2+1, sz-1, 1);
        a[x[i]]=y[i];
        ind=lower_bound(vec.begin(), vec.end(), make_pair(a[x[i]], x[i]))-vec.begin();
        ind2=lower_bound(vec.begin(), vec.end(), make_pair(a[x[i]]+1, 0))-vec.begin();
        upd(1, 0, sz-1, ind, ind, x[i]);
        upd(1, 0, sz-1, ind2+1, sz-1, -1);
        ans.push_back(seg[1]);
//        for (int j=1; j<=15; j++)
//            cout << j << ' ' << seg[j] << ' ' << lazy[j] << '\n';
    }
    return ans;
}
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 27 ms 1452 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 340 KB Output isn't correct
2 Halted 0 ms 0 KB -