이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "sequence.h"
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define f first
#define s second
vector<int> ct[500005];
int N;
struct segTree {
pii seg[4*500005];
int lazy[4*500005];
void laze2(int i, int add) {
seg[i] = {seg[i].f+add, seg[i].s+add};
lazy[i] += add;
}
void laze(int i, int l, int r) {
if(l!=r) {
laze2(i*2+1, lazy[i]);
laze2(i*2+2, lazy[i]);
}
lazy[i] = 0;
}
void build(int i, int l, int r) {
lazy[i] = 0;
if(l==r) {
seg[i].f = seg[i].s = l;
return;
}
int m = (l+r)/2;
build(i*2+1, l, m);
build(i*2+2, m+1, r);
seg[i].f = min(seg[i*2+1].f, seg[i*2+2].f);
seg[i].s = max(seg[i*2+1].s, seg[i*2+2].s);
}
void build() {
build(0, 0, N);
}
void update(int i, int l, int r, int wl, int wr, int val) {
if(wl<=l && wr>=r) {
laze2(i, val);
return;
}
laze(i, l, r);
if(wl>r || wr<l) return;
int m = (l+r)/2;
update(i*2+1, l, m, wl, wr, val);
update(i*2+2, m+1, r, wl, wr, val);
seg[i].f = min(seg[i*2+1].f, seg[i*2+2].f);
seg[i].s = max(seg[i*2+1].s, seg[i*2+2].s);
}
void update(int wl, int wr, int val) {
update(0, 0, N, wl, wr, val);
}
pii query(int i, int l, int r, int wl, int wr) {
laze(i, l, r);
if(wl>r || wr<l) return {(int)1e9, (int)-1e9};
if(wl<=l && wr>=r) return seg[i];
int m = (l+r)/2;
pii q1 = query(i*2+1, l, m, wl, wr);
pii q2 = query(i*2+2, m+1, r, wl, wr);
return {min(q1.f, q2.f), max(q1.s, q2.s)};
}
pii query(int wl, int wr) {
return query(0, 0, N, wl, wr);
}
} les, mor;
int sequence(int n, std::vector<int> A) {
N = n;
for(int i=0;i<N;i++) {
ct[A[i]].push_back(i+1);
}
les.build();
mor.build();
int ans = 1;
for(int i=1;i<=N;i++) {
for(int j:ct[i]) {
les.update(j, N, -2);
}
for(int j=0;j+ans<ct[i].size();j++) {
while(j+ans<ct[i].size()) {
int st = ct[i][j];
int en = ct[i][j+ans];
int qles = les.query(en, N).f - les.query(0, st-1).s;
int qmor = mor.query(en, N).s - les.query(0, st-1).f;
if(qles<=0 && qmor>=0) ans++;
else break;
}
}
for(int j:ct[i]) {
mor.update(j, N, -2);
}
}
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
sequence.cpp: In function 'int sequence(int, std::vector<int>)':
sequence.cpp:86:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
86 | for(int j=0;j+ans<ct[i].size();j++) {
| ~~~~~^~~~~~~~~~~~~
sequence.cpp:87:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
87 | while(j+ans<ct[i].size()) {
| ~~~~~^~~~~~~~~~~~~
# | 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... |