이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include "sequence.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
const int N = (int)5e5 + 5;
int n;
int A[N];
vector<int> P[N];
struct Node{
pii can;
int lazyL;
int lazyR;
};
Node T[N * 4 + 100];
Node unite(Node ai, Node bi){
Node res;
res.can = mp(min(ai.can.fi, bi.can.fi), max(ai.can.se, bi.can.se));
res.lazyL = res.lazyR = 0;
return res;
}
void push(int node, int cl, int cr){
T[node].can.fi += T[node].lazyL;
T[node].can.se += T[node].lazyR;
if(cl != cr){
T[node * 2].lazyL += T[node].lazyL;
T[node * 2].lazyR += T[node].lazyR;
T[node * 2 + 1].lazyL += T[node].lazyL;
T[node * 2 + 1].lazyR += T[node].lazyR;
}
T[node].lazyL = T[node].lazyR = 0;
}
void update(int node, int cl, int cr, int tl, int tr, int vl, int vr){
push(node, cl, cr);
if(cr < tl || cl > tr) return;
if(cl >= tl && cr <= tr){
T[node].lazyL = vl;
T[node].lazyR = vr;
push(node, cl, cr);
return;
}
int mid = (cl + cr) / 2;
update(node * 2, cl, mid, tl, tr, vl, vr);
update(node * 2 + 1, mid + 1, cr, tl, tr, vl, vr);
T[node] = unite(T[node * 2], T[node * 2 + 1]);
}
pii get(int node, int cl, int cr, int tl, int tr){
push(node, cl, cr);
if(cr < tl || cl > tr) return mp((int)1e9, -(int)1e9);
if(cl >= tl && cr <= tr){
return T[node].can;
}
int mid = (cl + cr) / 2;
pii lf = get(node * 2, cl, mid, tl, tr);
pii rf = get(node * 2 + 1, mid + 1, cr, tl, tr);
return mp(min(lf.fi, rf.fi), max(lf.se, rf.se));
}
void build(int node, int cl, int cr){
T[node].can = mp(cl, cl);
if(cl == cr){
T[node].lazyL = T[node].lazyR = 0;
return;
}
int mid = (cl + cr) / 2;
build(node * 2, cl, mid);
build(node * 2 + 1, mid + 1, cr);
}
int sequence(int _n, vector<int> _a) {
n = _n;
for(int i = 1; i <= n; i ++ ){
A[i] = _a[i - 1];
P[A[i]].push_back(i);
}
int soln = 1;
build(1, 0, n);
int l, r;
pii A, B;
for(int id = 1; id <= n; id ++ ){
for(auto x : P[id]){
update(1, 0, n, x, n, -2, 0);
}
for(int j = 0 ; j + soln < P[id].size(); j ++ ){
while(j + soln < P[id].size()){
l = P[id][j];
r = P[id][j + soln];
A = get(1, 0, n, 0, l - 1);
B = get(1, 0, n, r, n);
if(max(A.fi,B.fi) <= min(A.se,B.se)) soln ++ ;
else break;
}
}
for(auto x : P[id]){
update(1, 0, n, x, n, 0, -2);
}
}
return soln;
}
컴파일 시 표준 에러 (stderr) 메시지
sequence.cpp: In function 'int sequence(int, std::vector<int>)':
sequence.cpp:98:34: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
98 | for(int j = 0 ; j + soln < P[id].size(); j ++ ){
| ~~~~~~~~~^~~~~~~~~~~~~~
sequence.cpp:99:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
99 | while(j + soln < P[id].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... |