Submission #990215

# Submission time Handle Problem Language Result Execution time Memory
990215 2024-05-29T21:58:03 Z Mihailo Sequence (APIO23_sequence) C++17
0 / 100
75 ms 40532 KB
#include "sequence.h"
#include <cassert>
#include <cstdio>
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define xx first
#define yy second
typedef long long ll;
using namespace std;
 
ll n, g, tree[1000100], a[500100], m[500100], p1, p2;
vector<ll> app[500100], v1, v2;
 
void update(ll i, ll x) {
    i+=g;
    tree[i]=x;
    i/=2;
    while(i>0) {
        tree[i]=tree[2*i]+tree[2*i+1];
        i/=2;
    }
}
 
ll sum(ll l, ll r) {
    if(l>r) return 0;
    l+=g;
    r+=g;
    ll rez=0;
    while(l<=r) {
        if(l%2) {
            rez+=tree[l];
            l++;
        }
        if(r%2==0) {
            rez+=tree[r];
            r--;
        }
        l/=2;
        r/=2;
    }
    return rez;
}
 
ll solve() {
    g=1;
    while(g<n) g*=2;
    g--;
    for(ll i=1; i<=n; i++) {
        app[a[i]].pb(i);
        m[i]=app[a[i]].size();
    }
    ll rez=0;
    //for(ll i=1; i<=n; i++) update(i, 1);
    /*for(ll i=1; i<=n; i++) {
        if(app[i].empty()) continue;
        for(ll j=0; j<app[i].size(); j++) {
            update(app[i][j], 0);
        }
        if(sum(1, n)<0) return rez;
        for(ll j=0; j<app[i].size(); j++) {
            update(app[i][j], -1);
        }
        for(ll j=0; j<app[i].size(); j++) {
            if(v1.empty()||sum(1, v1.back()-1)<sum(1, app[i][j]-1)) v1.pb(app[i][j]);
        }
        for(ll j=app[i].size()-1; j>=0; j--) {
            if(v2.empty()||sum(1, v2.back()-1)<sum(1, app[i][j]-1)) v2.pb(app[i][j]);
        }
        p1=0;
        p2=v2.size()-1;
        while(p2>=0) {
            if(p1>=v1.size()||v1[p1]>v2[p2]) {
                p2--;
                continue;
            }
            if(sum(v1[p1], v2[p2])<=0) {
                rez=max(rez, m[v2[p2]]-m[v1[p1]]+1);
                p2--;
            }
            else p1++;
        }
        v1.clear();
        v2.clear();
    }*/
    return rez;
}
 
int sequence(int N, vector<int> A) {
    ll rez=0;
    n=N;
    for(ll i=0; i<N; i++) a[i+1]=A[i];
    rez=solve();
    for(ll i=1; i<=n; i++) {
        app[i].clear();
    }
    for(ll i=0; i<N; i++) a[i+1]=N+1-A[i];
    rez=max(rez, solve());
    for(ll i=1; i<=n; i++) {
        app[i].clear();
    }
    return rez;
}
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 14936 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 14936 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 14936 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 14940 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 75 ms 40532 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 14936 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 14936 KB Output isn't correct
2 Halted 0 ms 0 KB -