답안 #889469

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
889469 2023-12-19T19:20:10 Z ace5 Fire (JOI20_ho_t5) C++17
100 / 100
247 ms 30356 KB
#include <bits/stdc++.h>

using namespace std;

#define int int64_t

const int maxn = 200001;
const int sqr = 450;

vector<int> que[maxn];
int pr[maxn];
vector<pair<int,int>> otr;
int co[maxn];
int s[maxn];
int ans[maxn];
int bl[maxn];
pair<int,int> z[maxn];

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n,q;
    cin >> n >> q;
    for(int i = 0;i < n;++i)
    {
        cin >> s[i];
    }
    for(int i = 0;i < q;++i)
    {
        int t,l,r;
        cin >> t >> l >> r;
        l--;
        r--;
        z[i] = {l,r};
        que[t].push_back(i);
    }
    for(int i = 1;i <= sqr;++i)
    {
        for(int j = n-1;j >= 1;--j)
        {
            s[j] = max(s[j],s[j-1]);
        }
        pr[0] = 0;
        for(int j = 0;j < n;++j)
        {
            pr[j+1] = pr[j] + s[j];
        }
        for(auto j : que[i])
        {
            ans[j] = pr[z[j].second+1]-pr[z[j].first];
        }
    }
    for(int i = sqr;i <= n;i *= 2)
    {
        otr.clear();
        int bnr = -1;
        int yk = -1;
        vector<int> st;
        int tl =  -1;
        vector<vector<int>> m(i+1);
        for(int j = 0;j < n;++j)
        {
            if(j != 0 && s[j] != s[j-1])
            {
                bnr = j-1;
            }
            while(st.size() && s[st.back()] <= s[j])
            {
                st.pop_back();
            }
            if(st.size() == 0 || st.back() != bnr)
            {
                if(tl == -1)
                {
                    tl = j;
                    co[j] = yk++;
                }
                else
                    co[j] = yk;
                if(st.size() != 0 && j-st.back() < i+1)
                {
                    m[j-st.back()].push_back(yk);
                }
            }
            else
            {
                if(tl != -1)
                {
                    otr.push_back({tl,j-1});
                    tl = -1;
                }
            }
            st.push_back(j);
        }
        if(tl != -1)
        {
            otr.push_back({tl,n-1});
        }
        for(int k = i+1;k <= min(2*i,n);++k)
        {
            for(int u = 0;u < m[k-i].size();++u)
            {
                otr[m[k-i][u]].first++;
            }
            for(auto j : que[k])
            {
                int l = z[j].first;
                int r = z[j].second;
                int res = pr[max(int64_t(0),r+1-(k-i))]-pr[max(int64_t(0),l-(k-i))];
                for(auto [ll,rr] : otr)
                {
                    ll = max(ll,l);
                    rr = min(rr,r);
                    if(ll <= rr)
                    {
                        res -= pr[max(int64_t(0),rr+1-(k-i))]-pr[max(int64_t(0),ll-(k-i))];
                        res += pr[rr+1] - pr[ll];
                    }
                }
                ans[j] = res;
            }
        }
        for(int j = n-1;j >= i;--j)
        {
            s[j] = max(s[j],s[j-i]);
        }
        for(int j = 0;j < n;++j)
        {
            pr[j+1] = pr[j] + s[j];
        }
    }
    for(int j = 0;j < q;++j)
    {
        cout << ans[j] << "\n";
    }
    return 0;
}

Compilation message

ho_t5.cpp: In function 'int main()':
ho_t5.cpp:102:29: warning: comparison of integer expressions of different signedness: 'int64_t' {aka 'long int'} and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
  102 |             for(int u = 0;u < m[k-i].size();++u)
      |                           ~~^~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 9564 KB Output is correct
2 Correct 2 ms 9560 KB Output is correct
3 Correct 2 ms 9564 KB Output is correct
4 Correct 3 ms 9564 KB Output is correct
5 Correct 2 ms 9564 KB Output is correct
6 Correct 3 ms 9564 KB Output is correct
7 Correct 3 ms 9564 KB Output is correct
8 Correct 2 ms 9560 KB Output is correct
9 Correct 2 ms 9564 KB Output is correct
10 Correct 3 ms 9564 KB Output is correct
11 Correct 2 ms 9564 KB Output is correct
12 Correct 2 ms 9564 KB Output is correct
13 Correct 3 ms 9564 KB Output is correct
14 Correct 2 ms 9564 KB Output is correct
15 Correct 2 ms 9564 KB Output is correct
16 Correct 2 ms 9564 KB Output is correct
17 Correct 2 ms 9664 KB Output is correct
18 Correct 2 ms 9560 KB Output is correct
19 Correct 2 ms 9560 KB Output is correct
20 Correct 2 ms 9564 KB Output is correct
21 Correct 2 ms 9816 KB Output is correct
22 Correct 2 ms 9564 KB Output is correct
23 Correct 2 ms 9564 KB Output is correct
24 Correct 3 ms 9564 KB Output is correct
25 Correct 2 ms 9768 KB Output is correct
26 Correct 3 ms 9564 KB Output is correct
27 Correct 2 ms 9564 KB Output is correct
28 Correct 2 ms 9564 KB Output is correct
29 Correct 2 ms 9564 KB Output is correct
30 Correct 2 ms 9564 KB Output is correct
31 Correct 2 ms 9564 KB Output is correct
32 Correct 2 ms 9564 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 9564 KB Output is correct
2 Correct 181 ms 21676 KB Output is correct
3 Correct 185 ms 27944 KB Output is correct
4 Correct 200 ms 27628 KB Output is correct
5 Correct 190 ms 27344 KB Output is correct
6 Correct 186 ms 27356 KB Output is correct
7 Correct 188 ms 27660 KB Output is correct
8 Correct 187 ms 27120 KB Output is correct
9 Correct 189 ms 27440 KB Output is correct
10 Correct 191 ms 27680 KB Output is correct
11 Correct 182 ms 27632 KB Output is correct
12 Correct 196 ms 27520 KB Output is correct
13 Correct 185 ms 27156 KB Output is correct
14 Correct 187 ms 27208 KB Output is correct
15 Correct 191 ms 27632 KB Output is correct
16 Correct 194 ms 27408 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 9564 KB Output is correct
2 Correct 210 ms 23656 KB Output is correct
3 Correct 204 ms 29380 KB Output is correct
4 Correct 247 ms 30048 KB Output is correct
5 Correct 203 ms 29068 KB Output is correct
6 Correct 218 ms 29020 KB Output is correct
7 Correct 213 ms 29548 KB Output is correct
8 Correct 211 ms 29344 KB Output is correct
9 Correct 219 ms 29284 KB Output is correct
10 Correct 207 ms 29024 KB Output is correct
11 Correct 219 ms 29284 KB Output is correct
12 Correct 220 ms 28992 KB Output is correct
13 Correct 225 ms 29904 KB Output is correct
14 Correct 209 ms 29028 KB Output is correct
15 Correct 216 ms 30040 KB Output is correct
16 Correct 230 ms 29724 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 197 ms 23116 KB Output is correct
2 Correct 236 ms 26984 KB Output is correct
3 Correct 198 ms 27240 KB Output is correct
4 Correct 228 ms 27240 KB Output is correct
5 Correct 201 ms 27232 KB Output is correct
6 Correct 229 ms 26984 KB Output is correct
7 Correct 204 ms 26984 KB Output is correct
8 Correct 200 ms 26984 KB Output is correct
9 Correct 188 ms 27220 KB Output is correct
10 Correct 207 ms 27276 KB Output is correct
11 Correct 192 ms 27324 KB Output is correct
12 Correct 195 ms 27240 KB Output is correct
13 Correct 194 ms 27188 KB Output is correct
14 Correct 192 ms 27200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 9564 KB Output is correct
2 Correct 2 ms 9560 KB Output is correct
3 Correct 2 ms 9564 KB Output is correct
4 Correct 3 ms 9564 KB Output is correct
5 Correct 2 ms 9564 KB Output is correct
6 Correct 3 ms 9564 KB Output is correct
7 Correct 3 ms 9564 KB Output is correct
8 Correct 2 ms 9560 KB Output is correct
9 Correct 2 ms 9564 KB Output is correct
10 Correct 3 ms 9564 KB Output is correct
11 Correct 2 ms 9564 KB Output is correct
12 Correct 2 ms 9564 KB Output is correct
13 Correct 3 ms 9564 KB Output is correct
14 Correct 2 ms 9564 KB Output is correct
15 Correct 2 ms 9564 KB Output is correct
16 Correct 2 ms 9564 KB Output is correct
17 Correct 2 ms 9664 KB Output is correct
18 Correct 2 ms 9560 KB Output is correct
19 Correct 2 ms 9560 KB Output is correct
20 Correct 2 ms 9564 KB Output is correct
21 Correct 2 ms 9816 KB Output is correct
22 Correct 2 ms 9564 KB Output is correct
23 Correct 2 ms 9564 KB Output is correct
24 Correct 3 ms 9564 KB Output is correct
25 Correct 2 ms 9768 KB Output is correct
26 Correct 3 ms 9564 KB Output is correct
27 Correct 2 ms 9564 KB Output is correct
28 Correct 2 ms 9564 KB Output is correct
29 Correct 2 ms 9564 KB Output is correct
30 Correct 2 ms 9564 KB Output is correct
31 Correct 2 ms 9564 KB Output is correct
32 Correct 2 ms 9564 KB Output is correct
33 Correct 181 ms 21676 KB Output is correct
34 Correct 185 ms 27944 KB Output is correct
35 Correct 200 ms 27628 KB Output is correct
36 Correct 190 ms 27344 KB Output is correct
37 Correct 186 ms 27356 KB Output is correct
38 Correct 188 ms 27660 KB Output is correct
39 Correct 187 ms 27120 KB Output is correct
40 Correct 189 ms 27440 KB Output is correct
41 Correct 191 ms 27680 KB Output is correct
42 Correct 182 ms 27632 KB Output is correct
43 Correct 196 ms 27520 KB Output is correct
44 Correct 185 ms 27156 KB Output is correct
45 Correct 187 ms 27208 KB Output is correct
46 Correct 191 ms 27632 KB Output is correct
47 Correct 194 ms 27408 KB Output is correct
48 Correct 210 ms 23656 KB Output is correct
49 Correct 204 ms 29380 KB Output is correct
50 Correct 247 ms 30048 KB Output is correct
51 Correct 203 ms 29068 KB Output is correct
52 Correct 218 ms 29020 KB Output is correct
53 Correct 213 ms 29548 KB Output is correct
54 Correct 211 ms 29344 KB Output is correct
55 Correct 219 ms 29284 KB Output is correct
56 Correct 207 ms 29024 KB Output is correct
57 Correct 219 ms 29284 KB Output is correct
58 Correct 220 ms 28992 KB Output is correct
59 Correct 225 ms 29904 KB Output is correct
60 Correct 209 ms 29028 KB Output is correct
61 Correct 216 ms 30040 KB Output is correct
62 Correct 230 ms 29724 KB Output is correct
63 Correct 197 ms 23116 KB Output is correct
64 Correct 236 ms 26984 KB Output is correct
65 Correct 198 ms 27240 KB Output is correct
66 Correct 228 ms 27240 KB Output is correct
67 Correct 201 ms 27232 KB Output is correct
68 Correct 229 ms 26984 KB Output is correct
69 Correct 204 ms 26984 KB Output is correct
70 Correct 200 ms 26984 KB Output is correct
71 Correct 188 ms 27220 KB Output is correct
72 Correct 207 ms 27276 KB Output is correct
73 Correct 192 ms 27324 KB Output is correct
74 Correct 195 ms 27240 KB Output is correct
75 Correct 194 ms 27188 KB Output is correct
76 Correct 192 ms 27200 KB Output is correct
77 Correct 247 ms 30356 KB Output is correct
78 Correct 222 ms 29720 KB Output is correct
79 Correct 225 ms 29712 KB Output is correct
80 Correct 214 ms 29512 KB Output is correct
81 Correct 222 ms 29704 KB Output is correct
82 Correct 235 ms 29624 KB Output is correct
83 Correct 209 ms 29916 KB Output is correct
84 Correct 226 ms 29532 KB Output is correct
85 Correct 234 ms 29864 KB Output is correct
86 Correct 218 ms 30272 KB Output is correct
87 Correct 203 ms 28292 KB Output is correct
88 Correct 201 ms 27952 KB Output is correct
89 Correct 223 ms 27800 KB Output is correct
90 Correct 199 ms 28056 KB Output is correct
91 Correct 199 ms 27852 KB Output is correct
92 Correct 196 ms 27776 KB Output is correct
93 Correct 207 ms 28812 KB Output is correct
94 Correct 208 ms 28548 KB Output is correct
95 Correct 204 ms 28036 KB Output is correct
96 Correct 206 ms 28908 KB Output is correct
97 Correct 201 ms 28092 KB Output is correct
98 Correct 203 ms 27568 KB Output is correct
99 Correct 208 ms 27788 KB Output is correct
100 Correct 227 ms 28388 KB Output is correct
101 Correct 209 ms 27572 KB Output is correct
102 Correct 224 ms 28108 KB Output is correct