QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#332085#1363. Bitonic Orderingishmeal#WA 0ms3644kbC++142.5kb2024-02-19 08:17:012024-02-19 08:17:02

Judging History

你现在查看的是最新测评结果

  • [2024-02-19 08:17:02]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3644kb
  • [2024-02-19 08:17:01]
  • 提交

answer

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

#define pb push_back
#define f first
#define s second

const int inf = 1e9;
struct Node{
    Node* l = 0, *r = 0;
    int lo, hi, mset = inf, madd = 0, val = -inf;
    Node(int lo, int hi):lo(lo), hi(hi) {}
    Node(vector<int>& v, int lo, int hi) : lo(lo), hi(hi){
        if(lo + 1 < hi){
            int mid = lo + (hi - lo)/2;
            l = new Node(v, lo, mid); r = new Node(v, mid, hi);
            val = max(l->val, r->val);
        }
        else val = v[lo];
    }

    int query(int L, int R){
        if(R <= lo || hi <= L) return -inf;
        if(L <= lo && hi <= R) return val;
        push();
        return max(l->query(L, R), r->query(L, R));
    }

    void set(int L, int R, int x){
        if(R <= lo || hi <= L) return;
        if(L <= lo && hi <= R) mset= val = x, madd = 0;
        else{
            push(), l->set(L, R, x), r->set(L, R, x);
            val = max(l->val, r->val);
        }
    }

    void add(int L, int R, int x){
        if(R <= lo || hi <= L)return;
        if(L <= lo && hi <= R){
            if(mset != inf) mset += x;
            else madd += x;
            val += x;
        }
        else{
            push(), l->add(L, R, x), r->add(L, R, x);
            val = max(l->val, r->val);
        }
    }

    void push(){
        if(!l){
            int mid = lo + (hi - lo)/2;
            l = new Node(lo, mid); r = new Node(mid, hi);
        }
        if(mset != inf) l->set(lo, hi, mset), r->set(lo, hi, mset), mset = inf;
        else if(madd){
            l->add(lo,hi,madd), r->add(lo, hi, madd), madd = 0;
        }
    }

};

int main() {
    cin.tie(0)->ios_base::sync_with_stdio(0);
    //cout << fixed << setprecision(6);
    int n;
    cin >> n;
    vector<int> vec;
    map<int, int> omap;
    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        omap[a] = i;
        vec.pb(i);
    }
    int left = 0;
    int right = n-1;
    ll total = 0;
    Node* tr = new Node(vec, 0, vec.size());
    for(auto p : omap){

        int ind = tr->query(p.s, p.s+1);
        if(abs(left - ind) < abs(right - ind)){
            total += ind-left;
            left++;
            tr->add(0, ind, 1);
        }else{
            total += right - ind;
            right--;
            tr->add(ind, n, -1);
        }
        /*
        cout << p.f << " " << p.s << endl;
        cout << left << " " << right << " " << ind << endl;
        cout << total << endl;
        */
    }
    cout << total << endl;

	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3644kb

input:

13
39
40
32
100
13
16
15
28
27
26
25
24
23

output:

12

result:

wrong answer 1st lines differ - expected: '14', found: '12'