답안 #1110118

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1110118 2024-11-08T18:43:33 Z SSKMF Peru (RMI20_peru) C++17
100 / 100
117 ms 56824 KB
#include <bits/stdc++.h>
using namespace std;

const int mod(1000000007);
deque < pair <int , int> > candidati;

class Stiva {
private:
    stack < pair <int64_t , int64_t> > minim;
public:
    bool empty () { return minim.empty(); }
    int size () { return (int)minim.size(); }
    void push (int64_t valoare) { minim.push({valoare , (minim.empty() ? valoare : min(valoare , minim.top().second))}); }
    pair <int64_t , int64_t>& top () { return minim.top(); }
    void swap (Stiva &alta) { minim.swap(alta.minim); }
    void pop () { minim.pop(); }
};

class Deque {
private:
    Stiva stanga , dreapta;
    void Rebalance ()
    {
        bool schimbat = false;
        if (schimbat |= dreapta.empty())
            { dreapta.swap(stanga); }

        stack <int64_t> temporar;
        for (int copie = dreapta.size() / 2 ; copie ; copie--)
            { temporar.push(dreapta.top().first); dreapta.pop(); }

        for (int copie = dreapta.size() ; copie ; copie--)
            { stanga.push(dreapta.top().first); dreapta.pop(); }
            
        for (int copie = temporar.size() ; copie ; copie--)
            { dreapta.push(temporar.top()); temporar.pop(); }

        if (schimbat)
            { dreapta.swap(stanga); }
    }
public:
    void pop_front () { if (stanga.empty()) { Rebalance(); } stanga.pop(); }
    void pop_back () { if (dreapta.empty()) { Rebalance(); } dreapta.pop(); }
    void push_back (int64_t valoare) { dreapta.push(valoare); }
    void push_front (int64_t valoare) { stanga.push(valoare); }
    int64_t query () { return min((stanga.empty() ? INT64_MAX : stanga.top().second) , (dreapta.empty() ? INT64_MAX : dreapta.top().second)); }
} __minim;

int64_t minim[2500001];

int solve (int lungime , int limita , int *sir)
{
    int rezultat = 0;
    for (int indice = 1 ; indice <= lungime ; indice++)
    {
        pair <int , int> actual = {sir[indice - 1] , indice};
        while (!candidati.empty() && candidati.back() <= actual)
            { candidati.pop_back(); __minim.pop_back(); }

        __minim.push_back(actual.first + minim[candidati.empty() ? max(0 , indice - limita) : candidati.back().second]);
        candidati.push_back(actual);

        if (candidati.front().second == indice - limita)
            { candidati.pop_front(); __minim.pop_front(); }
        else
        {
            __minim.pop_front();
            __minim.push_front(candidati.front().first + minim[max(0 , indice - limita)]);
        }

        minim[indice] = __minim.query();
        rezultat = (23LL * rezultat + minim[indice]) % mod;
    }

    return rezultat;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 1 ms 2552 KB Output is correct
10 Correct 1 ms 2384 KB Output is correct
11 Correct 1 ms 2552 KB Output is correct
12 Correct 1 ms 2384 KB Output is correct
13 Correct 1 ms 2384 KB Output is correct
14 Correct 1 ms 2384 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 2384 KB Output is correct
2 Correct 1 ms 2384 KB Output is correct
3 Correct 1 ms 2384 KB Output is correct
4 Correct 1 ms 2384 KB Output is correct
5 Correct 1 ms 2384 KB Output is correct
6 Correct 1 ms 2384 KB Output is correct
7 Correct 1 ms 2384 KB Output is correct
8 Correct 1 ms 2384 KB Output is correct
9 Correct 1 ms 2552 KB Output is correct
10 Correct 1 ms 2384 KB Output is correct
11 Correct 1 ms 2552 KB Output is correct
12 Correct 1 ms 2384 KB Output is correct
13 Correct 1 ms 2384 KB Output is correct
14 Correct 1 ms 2384 KB Output is correct
15 Correct 14 ms 8784 KB Output is correct
16 Correct 14 ms 8784 KB Output is correct
17 Correct 15 ms 8784 KB Output is correct
18 Correct 16 ms 8784 KB Output is correct
19 Correct 16 ms 8784 KB Output is correct
20 Correct 15 ms 8964 KB Output is correct
21 Correct 13 ms 8784 KB Output is correct
22 Correct 13 ms 8796 KB Output is correct
23 Correct 17 ms 12880 KB Output is correct
24 Correct 24 ms 13384 KB Output is correct
25 Correct 18 ms 12880 KB Output is correct
26 Correct 17 ms 13048 KB Output is correct
27 Correct 20 ms 12988 KB Output is correct
28 Correct 19 ms 12872 KB Output is correct
29 Correct 15 ms 13128 KB Output is correct
30 Correct 17 ms 12992 KB Output is correct
31 Correct 18 ms 12872 KB Output is correct
32 Correct 21 ms 13112 KB Output is correct
33 Correct 23 ms 12988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 14 ms 8784 KB Output is correct
2 Correct 14 ms 8784 KB Output is correct
3 Correct 15 ms 8784 KB Output is correct
4 Correct 16 ms 8784 KB Output is correct
5 Correct 16 ms 8784 KB Output is correct
6 Correct 15 ms 8964 KB Output is correct
7 Correct 13 ms 8784 KB Output is correct
8 Correct 13 ms 8796 KB Output is correct
9 Correct 17 ms 12880 KB Output is correct
10 Correct 24 ms 13384 KB Output is correct
11 Correct 18 ms 12880 KB Output is correct
12 Correct 17 ms 13048 KB Output is correct
13 Correct 20 ms 12988 KB Output is correct
14 Correct 19 ms 12872 KB Output is correct
15 Correct 15 ms 13128 KB Output is correct
16 Correct 17 ms 12992 KB Output is correct
17 Correct 18 ms 12872 KB Output is correct
18 Correct 21 ms 13112 KB Output is correct
19 Correct 23 ms 12988 KB Output is correct
20 Correct 1 ms 2384 KB Output is correct
21 Correct 1 ms 2384 KB Output is correct
22 Correct 1 ms 2384 KB Output is correct
23 Correct 1 ms 2384 KB Output is correct
24 Correct 1 ms 2384 KB Output is correct
25 Correct 1 ms 2384 KB Output is correct
26 Correct 1 ms 2384 KB Output is correct
27 Correct 1 ms 2384 KB Output is correct
28 Correct 1 ms 2552 KB Output is correct
29 Correct 1 ms 2384 KB Output is correct
30 Correct 1 ms 2552 KB Output is correct
31 Correct 1 ms 2384 KB Output is correct
32 Correct 1 ms 2384 KB Output is correct
33 Correct 1 ms 2384 KB Output is correct
34 Correct 93 ms 53320 KB Output is correct
35 Correct 89 ms 53740 KB Output is correct
36 Correct 102 ms 53608 KB Output is correct
37 Correct 101 ms 53720 KB Output is correct
38 Correct 98 ms 53576 KB Output is correct
39 Correct 102 ms 53448 KB Output is correct
40 Correct 95 ms 53576 KB Output is correct
41 Correct 98 ms 53588 KB Output is correct
42 Correct 100 ms 53320 KB Output is correct
43 Correct 36 ms 24528 KB Output is correct
44 Correct 68 ms 36424 KB Output is correct
45 Correct 75 ms 36420 KB Output is correct
46 Correct 68 ms 36412 KB Output is correct
47 Correct 94 ms 55620 KB Output is correct
48 Correct 99 ms 55616 KB Output is correct
49 Correct 103 ms 55744 KB Output is correct
50 Correct 95 ms 56408 KB Output is correct
51 Correct 96 ms 56144 KB Output is correct
52 Correct 100 ms 56824 KB Output is correct
53 Correct 98 ms 56676 KB Output is correct
54 Correct 93 ms 53576 KB Output is correct
55 Correct 86 ms 53588 KB Output is correct
56 Correct 87 ms 53324 KB Output is correct
57 Correct 93 ms 53620 KB Output is correct
58 Correct 91 ms 53580 KB Output is correct
59 Correct 90 ms 53592 KB Output is correct
60 Correct 91 ms 53580 KB Output is correct
61 Correct 103 ms 55772 KB Output is correct
62 Correct 104 ms 55880 KB Output is correct
63 Correct 117 ms 55624 KB Output is correct