답안 #889468

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
889468 2023-12-19T19:15:37 Z ace5 Fire (JOI20_ho_t5) C++17
1 / 100
227 ms 53692 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 <= 2*i;++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 9780 KB Output is correct
3 Correct 2 ms 9780 KB Output is correct
4 Correct 2 ms 9564 KB Output is correct
5 Correct 2 ms 9564 KB Output is correct
6 Correct 2 ms 9560 KB Output is correct
7 Correct 2 ms 9564 KB Output is correct
8 Correct 2 ms 9564 KB Output is correct
9 Correct 2 ms 9564 KB Output is correct
10 Correct 2 ms 9564 KB Output is correct
11 Correct 3 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 9564 KB Output is correct
18 Correct 2 ms 9564 KB Output is correct
19 Correct 2 ms 9564 KB Output is correct
20 Correct 2 ms 9564 KB Output is correct
21 Correct 3 ms 9564 KB Output is correct
22 Correct 2 ms 9780 KB Output is correct
23 Correct 3 ms 9564 KB Output is correct
24 Correct 2 ms 9564 KB Output is correct
25 Correct 2 ms 9564 KB Output is correct
26 Correct 2 ms 9564 KB Output is correct
27 Correct 2 ms 9780 KB Output is correct
28 Correct 2 ms 9564 KB Output is correct
29 Correct 3 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 9560 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 9564 KB Output is correct
2 Runtime error 185 ms 49120 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 9564 KB Output is correct
2 Runtime error 227 ms 53692 KB Execution killed with signal 11
3 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 196 ms 50264 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 9564 KB Output is correct
2 Correct 2 ms 9780 KB Output is correct
3 Correct 2 ms 9780 KB Output is correct
4 Correct 2 ms 9564 KB Output is correct
5 Correct 2 ms 9564 KB Output is correct
6 Correct 2 ms 9560 KB Output is correct
7 Correct 2 ms 9564 KB Output is correct
8 Correct 2 ms 9564 KB Output is correct
9 Correct 2 ms 9564 KB Output is correct
10 Correct 2 ms 9564 KB Output is correct
11 Correct 3 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 9564 KB Output is correct
18 Correct 2 ms 9564 KB Output is correct
19 Correct 2 ms 9564 KB Output is correct
20 Correct 2 ms 9564 KB Output is correct
21 Correct 3 ms 9564 KB Output is correct
22 Correct 2 ms 9780 KB Output is correct
23 Correct 3 ms 9564 KB Output is correct
24 Correct 2 ms 9564 KB Output is correct
25 Correct 2 ms 9564 KB Output is correct
26 Correct 2 ms 9564 KB Output is correct
27 Correct 2 ms 9780 KB Output is correct
28 Correct 2 ms 9564 KB Output is correct
29 Correct 3 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 9560 KB Output is correct
33 Runtime error 185 ms 49120 KB Execution killed with signal 11
34 Halted 0 ms 0 KB -