Submission #1058836

#TimeUsernameProblemLanguageResultExecution timeMemory
1058836alexddSequence (APIO23_sequence)C++17
13 / 100
461 ms52816 KiB
#include "sequence.h" #include <bits/stdc++.h> using namespace std; const int INF = 1e9; pair<int,int> combine(pair<int,int> x, pair<int,int> y) { return {min(x.first,y.first),max(x.second,y.second)}; } pair<int,int> aint[1100000][2]; int lazy[1100000]; void build(int nod, int st, int dr) { if(st==dr) { if(st%2==0) { aint[nod][0]={0,0}; aint[nod][1]={INF,-INF}; } else { aint[nod][1]={0,0}; aint[nod][0]={INF,-INF}; } return; } } void propagate(int nod) { if(!lazy[nod]) return; lazy[nod*2]+=lazy[nod]; lazy[nod*2+1]+=lazy[nod]; aint[nod*2][0].first+=lazy[nod]; aint[nod*2][0].second+=lazy[nod]; aint[nod*2+1][0].first+=lazy[nod]; aint[nod*2+1][0].second+=lazy[nod]; aint[nod*2][1].first+=lazy[nod]; aint[nod*2][1].second+=lazy[nod]; aint[nod*2+1][1].first+=lazy[nod]; aint[nod*2+1][1].second+=lazy[nod]; lazy[nod]=0; } void upd(int nod, int st, int dr, int le, int ri, int newv) { if(le>ri) return; if(le==st && dr==ri) { lazy[nod]+=newv; aint[nod][0].first+=newv; aint[nod][0].second+=newv; aint[nod][1].first+=newv; aint[nod][1].second+=newv; return; } propagate(nod); int mij=(st+dr)/2; upd(nod*2,st,mij,le,min(mij,ri),newv); upd(nod*2+1,mij+1,dr,max(mij+1,le),ri,newv); aint[nod][0] = combine(aint[nod*2][0], aint[nod*2+1][0]); aint[nod][1] = combine(aint[nod*2][1], aint[nod*2+1][1]); } pair<int,int> qry(int nod, int st, int dr, int le, int ri, int c) { if(le>ri) return {INF,-INF}; if(le==st && dr==ri) return aint[nod][c]; propagate(nod); int mij=(st+dr)/2; return combine(qry(nod*2,st,mij,le,min(mij,ri),c), qry(nod*2+1,mij+1,dr,max(mij+1,le),ri,c)); } bool verif(int le1, int ri1, int le2, int ri2, int cnt0, int N) { pair<int,int> x[2] = {qry(1,0,N,le1,ri1,0), qry(1,0,N,le1,ri1,1)}; pair<int,int> y[2] = {qry(1,0,N,le2,ri2,0), qry(1,0,N,le2,ri2,1)}; for(int p=0;p<2;p++) { for(int q=0;q<2;q++) { pair<int,int> a = x[p], b = y[q]; if(a.first > b.first) swap(a,b); if(p==q) { if(a.second + cnt0 - 1 >= b.first) return 1; } else { if(a.second + cnt0 >= b.first) return 1; } } } return 0; } vector<int> pozs[500005]; int sequence(int N, std::vector<int> A) { build(1,0,N); for(int i=1;i<=N;i++) { upd(1,0,N,i,N,+1); pozs[A[i-1]].push_back(i); } int mxm=1; for(int val=1;val<=N;val++) { for(auto x:pozs[val]) upd(1,0,N,x,N,-1); vector<int> aux; aux.push_back(0); for(auto x:pozs[val]) aux.push_back(x); aux.push_back(N+1); for(int i=1;i+1<aux.size();i++) { for(int j=i+mxm;j+1<aux.size();j++) { if(verif(aux[i-1],aux[i]-1,aux[j],aux[j+1]-1,j-i+1,N)) { mxm = max(mxm, j-i+1); } else break; } } for(auto x:pozs[val]) upd(1,0,N,x,N,-1); } return mxm; }

Compilation message (stderr)

sequence.cpp: In function 'int sequence(int, std::vector<int>)':
sequence.cpp:121:24: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  121 |         for(int i=1;i+1<aux.size();i++)
      |                     ~~~^~~~~~~~~~~
sequence.cpp:123:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  123 |             for(int j=i+mxm;j+1<aux.size();j++)
      |                             ~~~^~~~~~~~~~~
#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...