제출 #915064

#제출 시각아이디문제언어결과실행 시간메모리
915064manizareBubble Sort 2 (JOI18_bubblesort2)C++14
38 / 100
9023 ms1884 KiB
#include<bits/stdc++.h>
#pragma GCC optimize("O3,unroll-loops")
#define pb push_back
#define F first
#define S second 
#define all(a) a.begin(),a.end()
#define pii pair <int,int>
#define PII pair<pii , pii>
#define ld long double
#define sz(v) (int)v.size()
#define rep(i , a , b) for(int i=a;i <= (b);i++)
#define per(i , a , b) for(int i=a;i >= (b);i--)
using namespace std ;   
const int maxn = 1e6 + 10 , inf= 2e9 , mod = 1e9 + 7 , sq = 360 ,MX = 20000 ;
struct fenwick{
    int fen[2*MX] ;
    void upd(int x ,int w){
        x++;
        while(x <= MX){
            fen[x]+=w;
            x+=x&-x; 
        }
    }
    int que(int x){
        x++;int ans =0 ;
        while(x){   
            ans+=fen[x];
            x-=x&-x;
        }
        return ans ;
    }
}f;
 
vector<int> countScans(vector<int> A, vector<int> X, vector<int> V) {
    int n = sz(A) , q =sz(X) ;     
    vector <int> res(q) , cm;
    rep(i , 0 , n-1)cm.pb(A[i]);
    rep(i , 0 ,q-1)cm.pb(V[i]) ;
    sort(all(cm)) ;
    cm.resize(unique(all(cm))-cm.begin()) ;
    rep(i , 0 , n-1){
        A[i] = lower_bound(all(cm) , A[i]) -cm.begin() ;
    }
    rep(i , 0 , q-1){
        A[X[i]] = lower_bound(all(cm),V[i])-cm.begin() ;
        int ans =0 ;
        rep(j , 0 , n-1){
            ans = max(ans , j-f.que(A[j])) ;
            f.upd(A[j] , 1);
        }
        rep(i , 0 , sz(cm))f.fen[i]=0;
        res[i]=ans;
    }
    return res; 
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...