이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "sequence.h"
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
using namespace std;
using ll = int;
const ll mod = 998244353;
#define fi first
#define se second
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define faster ios::sync_with_stdio(false);cin.tie(nullptr)
pair<int,int> f(pair<int,int> a,pair<int,int> b){
return {min(a.fi,b.fi),max(a.se,b.se)};
}
template <typename T>
struct RMQ{
const T INF={0,0};
ll N;
vector<T> dat;
vector<int> lazy;
RMQ(ll N_):N(),dat(N_*4,INF),lazy(N_*4,0){
ll x=1;
while(N_>x) x*=2;
N=x;
}
void eval(ll k,ll l,ll r){
if(lazy[k]==0) return;
if(k<N-1){
lazy[k*2+1]+=lazy[k];
lazy[k*2+2]+=lazy[k];
}
dat[k]={dat[k].fi+lazy[k],dat[k].se+lazy[k]};
lazy[k]=0;
}
void update(ll a,ll b,int x,ll k,ll l,ll r){
eval(k,l,r);
if(a<=l&&r<=b){
lazy[k]+=x;
eval(k,l,r);
}else if(a<r&&l<b){
update(a,b,x,k*2+1,l,(l+r)/2);
update(a,b,x,k*2+2,(l+r)/2,r);
dat[k]=f(dat[k*2+1],dat[k*2+2]);
}
}
void update(ll a,ll b,int x){update(a,b,x,0,0,N);}
T query_sub(ll a,ll b,ll k,ll l,ll r){
eval(k,l,r);
if(r<=a||b<=l){
return {1LL<<30,-1LL<<30};
}else if(a<=l&&r<=b){
return dat[k];
}else{
T vl=query_sub(a,b,k*2+1,l,(l+r)/2);
T vr=query_sub(a,b,k*2+2,(l+r)/2,r);
return f(vl,vr);
}
}
T query(ll a,ll b){return query_sub(a,b,0,0,N);}
};
int f(int N,vector<int> A){
vector<int> B=A;
sort(all(B));
B.erase(unique(all(B)),B.end());
vector<vector<int>> G(N+1);
rep(i,N) G[A[i]].push_back(i);
int ans=0;
RMQ<pair<int,int>> seg(N+1);
rep(j,N+1) seg.update(j,j+1,j);
rep(i,B.size()){
int l=0,r=0;
while(1){
if(r+1==G[B[i]].size()) break;
auto e1=seg.query(0,G[B[i]][l]+1);
auto e2=seg.query(G[B[i]][r+1]+1,N+1);
if(e1.fi<=e2.se&&e2.fi<=e1.se){
r++;
}else{
l++;
}
if(r<l) r++;
ans=max(ans,r-l+1);
}
for(int j:G[B[i]]){
seg.update(j+1,N+1,-2);
}
}
return ans;
}
int sequence(int N, std::vector<int> A) {
int ans=0;
vector<int> B=A;
sort(all(B));
rep(j,2){
int cnt=0;
rep(i,N) if(A[i]==B[(N-1+j)/2]) cnt++;
ans=max(ans,cnt);
}
ans=max(ans,f(N,A));
rep(i,N) A[i]=N+1-A[i];
ans=max(ans,f(N,A));
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
sequence.cpp: In function 'int f(int, std::vector<int>)':
sequence.cpp:11:30: warning: comparison of integer expressions of different signedness: 'll' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
11 | #define rep(i,n) for(ll i=0;i<n;i++)
......
75 | rep(i,B.size()){
| ~~~~~~~~~~
sequence.cpp:75:5: note: in expansion of macro 'rep'
75 | rep(i,B.size()){
| ^~~
sequence.cpp:78:19: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
78 | if(r+1==G[B[i]].size()) break;
| ~~~^~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |