Submission #951284

#TimeUsernameProblemLanguageResultExecution timeMemory
951284steveonalexSequence (APIO23_sequence)C++17
28 / 100
2052 ms11992 KiB
#include <bits/stdc++.h>
#include "sequence.h"

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define MASK(i) (1LL << (i))
#define GETBIT(mask, i) (((mask) >> (i)) & 1)
#define ALL(v) (v).begin(), (v).end()

ll max(ll a, ll b){return (a > b) ? a : b;}
ll min(ll a, ll b){return (a < b) ? a : b;}

ll LASTBIT(ll mask){return (mask) & (-mask);}
int pop_cnt(ll mask){return __builtin_popcountll(mask);}
int ctz(ll mask){return __builtin_ctzll(mask);}
int logOf(ll mask){return __lg(mask);}

mt19937_64 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
ll rngesus(ll l, ll r){return l + (ull) rng() % (r - l + 1);}

template <class T1, class T2>
    bool maximize(T1 &a, T2 b){
        if (a < b) {a = b; return true;}
        return false;
    }

template <class T1, class T2>
    bool minimize(T1 &a, T2 b){
        if (a > b) {a = b; return true;}
        return false;
    }

template <class T>
    void printArr(T& container, char separator = ' ', char finish = '\n'){
        for(auto item: container) cout << item << separator;
        cout << finish;
    }


template <class T>
    void remove_dup(vector<T> &a){
        sort(ALL(a));
        a.resize(unique(ALL(a)) - a.begin());
    }

struct FenwickTree{
    int n;
    vector<int> a;

    FenwickTree(int _n){
        n = _n;
        a.resize(n+1);
    }

    void update(int i, int v){
        while(i <= n){
            a[i] += v;
            i += LASTBIT(i);
        }
    }

    int get(int i){
        int ans = 0;
        while(i > 0){
            ans += a[i];
            i -= LASTBIT(i);
        }
        return ans;
    }

    int binaryLift(int v){
        int idx = 0, p = MASK(logOf(n));
        while(p > 0){
            if (idx + p <= n && v - a[idx + p] > 0){
                idx += p;
                v -= a[idx];
            }
            p >>= 1;
        }
        return idx + 1;
    }
};

int sequence(int n, vector<int> a) {
    int ans = 0;
    for(int i = 0; i<n; ++i){
        FenwickTree bit(n);
        vector<int> cnt(n+1);
        for(int j = i; j<n; ++j){
            bit.update(a[j], 1);
            cnt[a[j]]++;
            int mid = (j - i) / 2 + 1;
            maximize(ans, cnt[bit.binaryLift(mid)]);
            if (mid * 2 == (j - i + 1)){
                maximize(ans, cnt[bit.binaryLift(mid + 1)]);
            }
        }
    }

    return ans;
}


// int main(void){
//     ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

//     int n; cin >> n;
//     vector<int> a(n);
//     for(int i = 0; i<n; ++i) cin >> a[i];

//     cout << sequence(n, a) << "\n";

//     return 0;
// }
#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...