이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include "sequence.h"
#include<bits/stdc++.h>
using namespace std;
vector<int> haha[500001];
vector<pair<int,int>> seg(2500001);
vector<int> wow(2500001);
void upd(int l, int r, int ql, int qr, int x, int br) {
if(l == ql && r == qr) {
wow[x]+=br;
seg[x] = {seg[x].first+br,seg[x].second+br};
return;
}
int mid = (l+r)/2;
if(qr <= mid) {
upd(l,mid,ql,qr,x*2,br);
}
else if(ql > mid) {
upd(mid+1,r,ql,qr,x*2+1,br);
}
else {
upd(l,mid,ql,mid,x*2,br);
upd(mid+1,r,mid+1,qr,x*2+1,br);
}
seg[x] = {max(seg[x*2].first,seg[x*2+1].first)+wow[x],min(seg[x*2].second,seg[x*2+1].second)+wow[x]};
}
pair<int,int> calc(int l, int r, int ql, int qr, int x) {
if(ql == l && qr == r) {
return seg[x];
}
int mid = (l+r)/2;
pair<int,int> a,b;
if(qr <= mid) {
a = calc(l,mid,ql,qr,x*2);
return {a.first+wow[x],a.second+wow[x]};
}
else if(ql > mid) {
a = calc(mid+1,r,ql,qr,x*2+1);
return {a.first+wow[x],a.second+wow[x]};
}
else {
a = calc(l,mid,ql,mid,x*2);
b = calc(mid+1,r,mid+1,qr,x*2+1);
return {max(a.first,b.first),min(a.second,b.second)};
}
}
int sequence(int n, std::vector<int> a) {
for(int i = 0; i < a.size(); i++) {
haha[a[i]].push_back(i+1);
}
for(int i = 1; i <= n; i++) {
upd(0,n,i,n,1,-1);
}
int ans = 1;
for(int i = 1; i <= n; i++) {
for(int v: haha[i]) {
upd(0,n,v,n,1,1);
}
for(int j = 0; j < haha[i].size(); j++) {
for(int k = j+1; k < haha[i].size(); k++) {
int l = haha[i][j],r = haha[i][k];
pair<int,int> a = calc(0,n,0,l-1,1),b = calc(0,n,r,n,1);
int big = b.first-a.second,sm = b.second-a.first;
if(sm <= k-j+1 && big >= -(k-j+1)) {
ans = max(ans,k-j+1);
}
}
}
for(int v: haha[i]) {
upd(0,n,v,n,1,1);
}
}
return ans;
}
컴파일 시 표준 에러 (stderr) 메시지
sequence.cpp: In function 'int sequence(int, std::vector<int>)':
sequence.cpp:51:22: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
51 | for(int i = 0; i < a.size(); i++) {
| ~~^~~~~~~~~~
sequence.cpp:62:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
62 | for(int j = 0; j < haha[i].size(); j++) {
| ~~^~~~~~~~~~~~~~~~
sequence.cpp:63:32: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
63 | for(int k = j+1; k < haha[i].size(); k++) {
| ~~^~~~~~~~~~~~~~~~
# | 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... |