제출 #984015

#제출 시각아이디문제언어결과실행 시간메모리
984015Kenjikrab서열 (APIO23_sequence)C++17
32 / 100
750 ms67748 KiB
#include "sequence.h" #include<bits/stdc++.h> #define pii pair<int,int> #define fi first #define se second using namespace std; int const n_max=5e5+10; struct Node{ int sum; int mn; int mx; Node():sum(0),mn(0),mx(0){} Node(int a):sum(a),mn(min(0,a)),mx(max(0,a)){} Node operator +(Node a) { Node ret; ret.sum=sum+a.sum; ret.mn=min(mn,sum+a.mn); ret.mx=max(mx,sum+a.mx); return ret; } }; Node tree[4*n_max]; void upd(int idx,int l,int r,int p,int v) { if(p<l||r<p)return; if(l==r) { tree[idx]=Node(v); return; } int mid=(l+r)>>1; if(p<=mid)upd(idx<<1,l,mid,p,v); else upd(idx<<1^1,mid+1,r,p,v); tree[idx]=tree[idx<<1]+tree[idx<<1^1]; } Node qr(int idx,int l,int r,int ll,int rr) { if(rr<l||r<ll)return Node(); if(ll<=l&&r<=rr)return tree[idx]; int mid=(l+r)>>1; return qr(idx<<1,l,mid,ll,rr)+qr(idx<<1^1,mid+1,r,ll,rr); } vector<int> A; vector<int> pos[n_max]; int sequence(int N, vector<int> _A) { A.push_back(0); for(int i=0;i<N;i++)A.push_back(_A[i]); for(int i=1;i<=N;i++)pos[i].push_back(0); for(int i=1;i<=N;i++)pos[A[i]].push_back(i),upd(1,1,N,i,1); for(int i=1;i<=N;i++)pos[i].push_back(N+1); int ans=1; for(int i=1;i<=N;i++) { for(auto it:pos[i])upd(1,1,N,it,0); for(auto it:pos[i-1])upd(1,1,N,it,-1); vector<pii> keep; int time=0; for(int j=1;j<pos[i].size();j++) { Node temp=qr(1,1,N,pos[i][j-1]+1,pos[i][j]-1); keep.push_back({time+temp.mn,time+temp.mx}); time+=temp.sum; } for(int j=1;j<keep.size();j++) { int l=0,r=j; while(l<r) { int mid=(l+r)>>1; if(-(j-mid)>keep[j].se-keep[mid].fi||keep[j].fi-keep[mid].se>j-mid)l=mid+1; else r=mid; } ans=max(ans,j-l); keep[j]={min(keep[j].fi,keep[j-1].fi),max(keep[j].se,keep[j-1].se)}; } } return ans; }

컴파일 시 표준 에러 (stderr) 메시지

sequence.cpp: In function 'int sequence(int, std::vector<int>)':
sequence.cpp:61:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   61 |     for(int j=1;j<pos[i].size();j++)
      |                 ~^~~~~~~~~~~~~~
sequence.cpp:67:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   67 |     for(int j=1;j<keep.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...