제출 #756947

#제출 시각아이디문제언어결과실행 시간메모리
756947doowey서열 (APIO23_sequence)C++17
28 / 100
237 ms8400 KiB
#include "sequence.h"
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;

#define fi first
#define se second
#define mp make_pair

const int N = 2050;
int cnt[N];
int tree[N * 4 + 512];

void add(int node, int cl, int cr, int id){
    tree[node] ++ ;
    if(cl == cr){
        return;
    }
    int mid = (cl + cr) / 2;
    if(mid >= id)
        add(node * 2, cl, mid, id);
    else
        add(node * 2 + 1, mid + 1, cr, id);
}

int find_idx(int node, int cl, int cr, int lim){
    if(cl == cr) {
        return tree[node];
    }
    int mid = (cl + cr) / 2;
    if(tree[node * 2] >= lim){
        return find_idx(node * 2, cl, mid, lim);
    }
    else{
        return find_idx(node * 2 + 1, mid + 1, cr, lim - tree[node * 2]);
    }
}

void init(int node, int cl, int cr){
    tree[node] = 0;
    if(cl == cr) return;
    int mid = (cl + cr) / 2;
    init(node * 2, cl, mid);
    init(node * 2 + 1, mid + 1, cr);
}

int sequence(int n, vector<int> a) {
    int ans = 0;
    int sz;
    int me;
    for(int i = 0 ; i < n; i ++) {
        init(1, 1, n);
        for(int j = i ; j < n; j ++) {
            add(1, 1, n, a[j]);
            sz = j - i + 1;
            if(sz % 2 == 1){
                me = (sz + 1) / 2;
                ans = max(ans, find_idx(1, 1, n, me));
            }
            else{
                me = (sz + 1) / 2;
                ans = max(ans, find_idx(1, 1, n, me));
                ans = max(ans, find_idx(1, 1, n, me + 1));
            }
        }
    }
    return ans;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...