Submission #931691

# Submission time Handle Problem Language Result Execution time Memory
931691 2024-02-22T09:27:01 Z irmuun Sequence (APIO23_sequence) C++17
Compilation error
0 ms 0 KB
#include<bits/stdc++.h>
#include "sequence.h"
 
using namespace std;
 
#define ll int
#define pb push_back
#define ff first
#define ss second
#define all(s) s.begin(),s.end()
#define rall(s) s.rbegin(),s.rend()

struct lazySegtree{
    ll n;
    vector<ll>t,lazy;
    lazySegtree(ll n) : n(n) {
        t.resize(4*n,0);
        lazy.resize(4*n,0);
        build(1,0,n);
    }
    void push(ll node){
        t[node*2]+=lazy[node];
        lazy[node*2]+=lazy[node];
        t[node*2+1]+=lazy[node];
        lazy[node*2+1]+=lazy[node];
        lazy[node]=0;
    }
    void build(ll node,ll l,ll r){
        if(l==r){
            t[node]=0;
            return;
        }
        ll mid=(l+r)/2;
        build(node*2,l,mid);
        build(node*2+1,mid+1,r);
    }
    void update(ll node,ll l,ll r,ll L,ll R,ll val){
        if(L>R) return;
        if(L==l&&R==r){
            t[node]+=val;
            lazy[node]+=val;
        }
        else{
            push(node);
            ll mid=(l+r)/2;
            update(node*2,l,mid,L,min(R,mid),val);
            update(node*2+1,mid+1,r,max(L,mid+1),R,val);
            t[node]=max(t[node*2],t[node*2+1]);
        }
    }
    ll query(ll node,ll l,ll r,ll L,ll R){
        if(L>R) return -INF;
        if(L==l&&R==r) return t[node];
        push(node);
        ll mid=(l+r)/2;
        return max(query(node*2,l,mid,L,min(R,mid)),query(node*2+1,mid+1,r,max(L,mid+1),R));
    }
};
 
int sequence(int N,vector<int>A){//sub5
    vector<int>pos[N+5];
    for(int i=0;i<N;i++){
        pos[A[i]].pb(i+1);
    }
    lazySegtree sg(N);
    for(int i=1;i<=N;i++){
        sg.update(1,0,N,i,N,1);
    }
    int ans=1;
    for(int i=1;i<=N;i++){
        for(int j:pos[i]){
            sg.update(1,0,N,j,N,-1);
        }
        for(int j:pos[i]){
            sg.update(1,0,N,j,N,-1);
        }
        if(pos[i].size()==2){
            int l=pos[i][0],r=pos[i][1];
            int mn=sg.query(1,0,N,0,l-1),mx=sg.query(1,0,N,r,N);
            if(mx<-2||mn>2){
                ans=max(ans,1);
            }
            else{
                ans=max(ans,2);
            }
        }
    }
    return ans;
}

Compilation message

sequence.cpp: In member function 'int lazySegtree::query(int, int, int, int, int)':
sequence.cpp:52:25: error: 'INF' was not declared in this scope
   52 |         if(L>R) return -INF;
      |                         ^~~