Submission #931689

#TimeUsernameProblemLanguageResultExecution timeMemory
931689irmuunSequence (APIO23_sequence)C++17
Compilation error
0 ms0 KiB
#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() const ll INF=-1e18; 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) else{ ans=2; } } } return ans; }

Compilation message (stderr)

sequence.cpp:13:14: warning: overflow in conversion from 'double' to 'int' changes value from '-1.0e+18' to '-2147483648' [-Woverflow]
   13 | const ll INF=-1e18;
      |              ^~~~~
sequence.cpp: In function 'int sequence(int, std::vector<int>)':
sequence.cpp:83:13: error: expected primary-expression before 'else'
   83 |             else{
      |             ^~~~