이 제출은 이전 버전의 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)+wow[x],min(a.second,b.second)+wow[x]};
}
}
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);
}
vector<pair<int,int>> big(1,{(int)(-1e9),69});
vector<pair<int,int>> sm(1,{(int)(1e9),69});
for(int j = 0; j < haha[i].size(); j++) {
int p = haha[i][j];
pair<int,int> c = calc(0,n,p,n,1);
if(c.second > 0) {
if(c.second-(big[big.size()-1].first+j+1) <= 0) {
int l = 0,r = big.size()-1;
while(l < r) {
int m = (l+r)/2;
if(c.second-(big[m].first+j+1) <= 0) {
r = m;
}
else {
l = m+1;
}
}
ans = max(ans,j+1-big[l].second);
}
}
else if(c.first < 0) {
if(c.first-(sm[sm.size()-1].first-j-1) >= 0) {
int l = 0,r = sm.size()-1;
while(l < r) {
int m = (l+r)/2;
if(c.first-(sm[m].first-j-1) >= 0) {
r = m;
}
else {
l = m+1;
}
}
ans = max(ans,j+1-sm[l].second);
}
}
else {
ans = max(ans,j+1);
}
c = calc(0,n,0,p,1);
if(c.first-j > big[big.size()-1].first) {
big.push_back({c.first-j,j});
}
if(c.second+j < sm[sm.size()-1].first) {
sm.push_back({c.second+j,j});
}
}
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:64:26: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
64 | for(int j = 0; j < haha[i].size(); j++) {
| ~~^~~~~~~~~~~~~~~~
# | 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... |