제출 #77085

#제출 시각아이디문제언어결과실행 시간메모리
77085dualityBubble Sort 2 (JOI18_bubblesort2)C++11
100 / 100
3562 ms309832 KiB
#define DEBUG 0

#include <bits/stdc++.h>
using namespace std;

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------
#include "bubblesort2.h"

vpii sorted,sorted2;
int tree[1 << 21],lazy[1 << 21];
int prop(int s,int e,int i) {
    tree[i] += lazy[i];
    if (s != e) lazy[2*i+1] += lazy[i],lazy[2*i+2] += lazy[i];
    lazy[i] = 0;
    return 0;
}
int update(int s,int e,int as,int ae,int i,int num,int f) {
    prop(s,e,i);
    if ((s > ae) || (e < as)) return tree[i];
    else if ((s >= as) && (e <= ae)) {
        if (f) tree[i] = num;
        else lazy[i] = num;
        prop(s,e,i);
        return tree[i];
    }

    int mid = (s+e) / 2;
    tree[i] = max(update(s,mid,as,ae,2*i+1,num,f),update(mid+1,e,as,ae,2*i+2,num,f));
    return tree[i];
}
int bit[1000001];
vector<int> countScans(vector<int> A,vector<int> X,vector<int> V) {
    int i,j;
    vi ans;
    for (i = 0; i < A.size(); i++) sorted.pb(mp(A[i],i)),sorted2.pb(mp(A[i],i));
    for (i = 0; i < X.size(); i++) sorted.pb(mp(V[i],X[i]));
    sort(sorted.begin(),sorted.end());
    sorted.resize(unique(sorted.begin(),sorted.end())-sorted.begin());
    sort(sorted2.begin(),sorted2.end());
    for (i = 0; i < A.size(); i++) {
        int p = lower_bound(sorted2.begin(),sorted2.end(),mp(A[i],i))-sorted2.begin();
        int q = lower_bound(sorted.begin(),sorted.end(),mp(A[i],i))-sorted.begin();
        update(0,sorted.size()-1,q,q,0,i-p,1);
        for (j = q+1; j <= sorted.size(); j += j & (-j)) bit[j]++;
    }
    for (i = 0; i < X.size(); i++) {
        int p = lower_bound(sorted.begin(),sorted.end(),mp(A[X[i]],X[i]))-sorted.begin();
        update(0,sorted.size()-1,p,p,0,-MAX_VAL,1);
        update(0,sorted.size()-1,p+1,sorted.size()-1,0,1,0);
        for (j = p+1; j <= sorted.size(); j += j & (-j)) bit[j]--;
        A[X[i]] = V[i];
        p = lower_bound(sorted.begin(),sorted.end(),mp(V[i],X[i]))-sorted.begin();
        int x = 0;
        for (j = p+1; j > 0; j -= j & (-j)) x += bit[j];
        update(0,sorted.size()-1,p,p,0,X[i]-x,1);
        update(0,sorted.size()-1,p+1,sorted.size()-1,0,-1,0);
        for (j = p+1; j <= sorted.size(); j += j & (-j)) bit[j]++;
        ans.pb(tree[0]+lazy[0]);
    }
    return ans;
}

컴파일 시 표준 에러 (stderr) 메시지

bubblesort2.cpp: In function 'std::vector<int> countScans(std::vector<int>, std::vector<int>, std::vector<int>)':
bubblesort2.cpp:85:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i = 0; i < A.size(); i++) sorted.pb(mp(A[i],i)),sorted2.pb(mp(A[i],i));
                 ~~^~~~~~~~~~
bubblesort2.cpp:86:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i = 0; i < X.size(); i++) sorted.pb(mp(V[i],X[i]));
                 ~~^~~~~~~~~~
bubblesort2.cpp:90:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i = 0; i < A.size(); i++) {
                 ~~^~~~~~~~~~
bubblesort2.cpp:94:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (j = q+1; j <= sorted.size(); j += j & (-j)) bit[j]++;
                       ~~^~~~~~~~~~~~~~~~
bubblesort2.cpp:96:19: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
     for (i = 0; i < X.size(); i++) {
                 ~~^~~~~~~~~~
bubblesort2.cpp:100:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (j = p+1; j <= sorted.size(); j += j & (-j)) bit[j]--;
                       ~~^~~~~~~~~~~~~~~~
bubblesort2.cpp:107:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         for (j = p+1; j <= sorted.size(); j += j & (-j)) bit[j]++;
                       ~~^~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...