Submission #741187

# Submission time Handle Problem Language Result Execution time Memory
741187 2023-05-13T19:16:19 Z AmirElarbi Bubble Sort 2 (JOI18_bubblesort2) C++14
Compilation error
0 ms 0 KB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define vi vector<int>
#define ve vector
#define ll long long
#define vl vector<ll>
#define vll vector<pair<ll,ll>>
#define onbit __builtin_popcount
#define ii pair<int,int>
#define vvi vector<vi>
#define vii vector<ii>
#define gii greater<ii>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF 1e18
#define eps 1e-7
#define eps1 1e-2
#define optimise ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MAX_A 1e5+5
using namespace std;
using namespace __gnu_pbds;
#include "bubblesort2.h"

template <class T>
using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const ll MOD = 1e9+7;
const int nax = 5e5+5;
const int MAX_VAL = 1e6;
double PI=3.14159265359;
int arx[8]={1,1,0,-1,-1,-1, 0, 1};
int ary[8]={0,1,1, 1, 0,-1,-1,-1};
typedef complex<int> Point;
#define X real()
#define Y imag()
void setIO(string s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}
vii tab(nax);
Tree<ii> segtree[nax*4];
void build(int pos,int l,int r)
{
    if (l==r)
    {
        segtree[pos].insert(tab[l]);
        return;
    }
    int mid=(r+l)/2;
    build(pos*2+1,l,mid);
    build(pos*2+2,mid+1,r);
    for (auto u: segtree[pos*2+1])
    {
        segtree[pos].insert(u);
    }
    for (auto u: segtree[pos*2+2])
    {
        segtree[pos].insert(u);
    }
    return;
}
void update(int pos,int l,int r,int index,ii newvalue)
{
    if (l>r) return;
    segtree[pos].erase(tab[index]);
    if (l==r&&r==index)
    {
        segtree[pos].insert(newvalue);
        return;
    }
    int mid=(r+l)/2;
    if (index<=mid) update(pos*2+1,l,mid,index,newvalue);
    else update(pos*2+2,mid+1,r,index,newvalue);
    segtree[pos].insert(newvalue);
}
int query(int pos,int l,int r,int left,int right)
{
    if (l>r||r<left||l>right) return 0;
    else if (l>=left&&r<=right)
    {
        int sum=segtree[pos].order_of_key({tab[right]});
        return sum;
    }
    int mid=(r+l)/2;
    return query(pos*2+1,l,mid,left,right)+query(pos*2+2,mid+1,r,left,right);
}
std::vector<int> countScans(std::vector<int> A, std::vector<int> X, std::vector<int> V){
    int n,q;
    n=A.size();
    q=X.size();
    map<int,int> cur;
    Tree<ii> s;
    for (int i = 0; i < n; ++i)
    {
        tab[i].fi=A[i];
        tab[i].se=i;
        s.insert(tab[i]);
    }
    ll res=0;
    build(0,0,n-1);
    vector<bool> test(n);
    for (int i = 0; i < n; ++i)
    {
        int p=s.order_of_key(tab[i]);
        int k=query(0,0,n-1,0,i);
        if (k<p) {
            test[i]=true;
            res++;
        }else test[i]=false;
    }
    ll curr=nax+1;
    vi nabba;
    for (int i = 0; i < q; ++i)
    {
        int x,y;
        x=X[i];
        y=V[i];
        s.erase(tab[x]);
        int p=s.order_of_key({y,x});
        update(0,0,n-1,x,{y,x});
        int k=query(0,0,n-1,0,x);
        //cout <<x<<" "<<y<<" "<< p<<" "<<k<<endl;
        bool test1= !(p==k);
        //cout << test1<<" "<<test[x]<<endl;
        res+= test1;
        res-= test[x];
        test[x]=test1;
        tab[x]={y,x};
        s.insert(tab[x]);
        curr++;
        nabba.pb(res);        
    }
    return nabba;
}

Compilation message

bubblesort2.cpp: In function 'void setIO(std::string)':
bubblesort2.cpp:38:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
bubblesort2.cpp:39:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
/usr/bin/ld: /tmp/ccsOHhFJ.o: in function `main':
grader.cpp:(.text.startup+0x19f): undefined reference to `countScans(std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >, std::vector<int, std::allocator<int> >)'
collect2: error: ld returned 1 exit status