답안 #757588

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
757588 2023-06-13T11:55:37 Z doowey 서열 (APIO23_sequence) C++17
69 / 100
666 ms 64872 KB
#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(int j = (int)P[id].size() - 1 ; j >= 0; j -- ){
            update(1, 0, n, P[id][j], n, -2, 0);
            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;
}

Compilation message

sequence.cpp: In function 'int sequence(int, std::vector<int>)':
sequence.cpp:97:28: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   97 |             while(j + soln < P[id].size()){
      |                   ~~~~~~~~~^~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 43316 KB Output is correct
2 Correct 19 ms 43312 KB Output is correct
3 Correct 23 ms 43320 KB Output is correct
4 Correct 19 ms 43348 KB Output is correct
5 Correct 19 ms 43300 KB Output is correct
6 Correct 19 ms 43348 KB Output is correct
7 Correct 19 ms 43348 KB Output is correct
8 Correct 20 ms 43348 KB Output is correct
9 Correct 20 ms 43316 KB Output is correct
10 Correct 19 ms 43260 KB Output is correct
11 Correct 19 ms 43332 KB Output is correct
12 Correct 21 ms 43264 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 43316 KB Output is correct
2 Correct 19 ms 43312 KB Output is correct
3 Correct 23 ms 43320 KB Output is correct
4 Correct 19 ms 43348 KB Output is correct
5 Correct 19 ms 43300 KB Output is correct
6 Correct 19 ms 43348 KB Output is correct
7 Correct 19 ms 43348 KB Output is correct
8 Correct 20 ms 43348 KB Output is correct
9 Correct 20 ms 43316 KB Output is correct
10 Correct 19 ms 43260 KB Output is correct
11 Correct 19 ms 43332 KB Output is correct
12 Correct 21 ms 43264 KB Output is correct
13 Correct 23 ms 43384 KB Output is correct
14 Correct 20 ms 43332 KB Output is correct
15 Correct 21 ms 43304 KB Output is correct
16 Correct 22 ms 43392 KB Output is correct
17 Correct 20 ms 43404 KB Output is correct
18 Correct 21 ms 43336 KB Output is correct
19 Correct 20 ms 43388 KB Output is correct
20 Correct 20 ms 43404 KB Output is correct
21 Correct 20 ms 43416 KB Output is correct
22 Correct 19 ms 43352 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 43316 KB Output is correct
2 Correct 443 ms 59260 KB Output is correct
3 Correct 416 ms 59144 KB Output is correct
4 Correct 491 ms 51284 KB Output is correct
5 Correct 438 ms 58248 KB Output is correct
6 Correct 404 ms 58092 KB Output is correct
7 Correct 385 ms 51660 KB Output is correct
8 Correct 422 ms 51788 KB Output is correct
9 Correct 478 ms 51732 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 43312 KB Output is correct
2 Correct 534 ms 52200 KB Output is correct
3 Correct 552 ms 51324 KB Output is correct
4 Correct 555 ms 51400 KB Output is correct
5 Correct 666 ms 52236 KB Output is correct
6 Correct 583 ms 51408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 513 ms 64872 KB Output is correct
2 Correct 524 ms 64832 KB Output is correct
3 Correct 536 ms 64332 KB Output is correct
4 Correct 530 ms 64264 KB Output is correct
5 Correct 530 ms 61052 KB Output is correct
6 Correct 525 ms 60964 KB Output is correct
7 Correct 484 ms 59724 KB Output is correct
8 Incorrect 502 ms 59500 KB Output isn't correct
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 43316 KB Output is correct
2 Correct 19 ms 43312 KB Output is correct
3 Correct 23 ms 43320 KB Output is correct
4 Correct 19 ms 43348 KB Output is correct
5 Correct 19 ms 43300 KB Output is correct
6 Correct 19 ms 43348 KB Output is correct
7 Correct 19 ms 43348 KB Output is correct
8 Correct 20 ms 43348 KB Output is correct
9 Correct 20 ms 43316 KB Output is correct
10 Correct 19 ms 43260 KB Output is correct
11 Correct 19 ms 43332 KB Output is correct
12 Correct 21 ms 43264 KB Output is correct
13 Correct 23 ms 43384 KB Output is correct
14 Correct 20 ms 43332 KB Output is correct
15 Correct 21 ms 43304 KB Output is correct
16 Correct 22 ms 43392 KB Output is correct
17 Correct 20 ms 43404 KB Output is correct
18 Correct 21 ms 43336 KB Output is correct
19 Correct 20 ms 43388 KB Output is correct
20 Correct 20 ms 43404 KB Output is correct
21 Correct 20 ms 43416 KB Output is correct
22 Correct 19 ms 43352 KB Output is correct
23 Correct 105 ms 45772 KB Output is correct
24 Correct 107 ms 45884 KB Output is correct
25 Correct 95 ms 45884 KB Output is correct
26 Correct 105 ms 45004 KB Output is correct
27 Correct 97 ms 44968 KB Output is correct
28 Correct 95 ms 44872 KB Output is correct
29 Correct 91 ms 44580 KB Output is correct
30 Correct 94 ms 44744 KB Output is correct
31 Correct 108 ms 44788 KB Output is correct
32 Correct 73 ms 46752 KB Output is correct
33 Correct 96 ms 45696 KB Output is correct
34 Correct 92 ms 45636 KB Output is correct
35 Correct 102 ms 45516 KB Output is correct
36 Correct 101 ms 45652 KB Output is correct
37 Correct 96 ms 45652 KB Output is correct
38 Correct 94 ms 45676 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 43316 KB Output is correct
2 Correct 19 ms 43312 KB Output is correct
3 Correct 23 ms 43320 KB Output is correct
4 Correct 19 ms 43348 KB Output is correct
5 Correct 19 ms 43300 KB Output is correct
6 Correct 19 ms 43348 KB Output is correct
7 Correct 19 ms 43348 KB Output is correct
8 Correct 20 ms 43348 KB Output is correct
9 Correct 20 ms 43316 KB Output is correct
10 Correct 19 ms 43260 KB Output is correct
11 Correct 19 ms 43332 KB Output is correct
12 Correct 21 ms 43264 KB Output is correct
13 Correct 23 ms 43384 KB Output is correct
14 Correct 20 ms 43332 KB Output is correct
15 Correct 21 ms 43304 KB Output is correct
16 Correct 22 ms 43392 KB Output is correct
17 Correct 20 ms 43404 KB Output is correct
18 Correct 21 ms 43336 KB Output is correct
19 Correct 20 ms 43388 KB Output is correct
20 Correct 20 ms 43404 KB Output is correct
21 Correct 20 ms 43416 KB Output is correct
22 Correct 19 ms 43352 KB Output is correct
23 Correct 443 ms 59260 KB Output is correct
24 Correct 416 ms 59144 KB Output is correct
25 Correct 491 ms 51284 KB Output is correct
26 Correct 438 ms 58248 KB Output is correct
27 Correct 404 ms 58092 KB Output is correct
28 Correct 385 ms 51660 KB Output is correct
29 Correct 422 ms 51788 KB Output is correct
30 Correct 478 ms 51732 KB Output is correct
31 Correct 534 ms 52200 KB Output is correct
32 Correct 552 ms 51324 KB Output is correct
33 Correct 555 ms 51400 KB Output is correct
34 Correct 666 ms 52236 KB Output is correct
35 Correct 583 ms 51408 KB Output is correct
36 Correct 513 ms 64872 KB Output is correct
37 Correct 524 ms 64832 KB Output is correct
38 Correct 536 ms 64332 KB Output is correct
39 Correct 530 ms 64264 KB Output is correct
40 Correct 530 ms 61052 KB Output is correct
41 Correct 525 ms 60964 KB Output is correct
42 Correct 484 ms 59724 KB Output is correct
43 Incorrect 502 ms 59500 KB Output isn't correct
44 Halted 0 ms 0 KB -