Submission #589685

# Submission time Handle Problem Language Result Execution time Memory
589685 2022-07-05T06:24:55 Z 이동현(#8410) Gorgeous Pill (FXCUP3_gorgeous) C++14
51 / 100
1500 ms 8252 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int NS = (int)3e5 + 4;
int tr[NS * 4];

void push(int x, int s, int e, int pos, int val){
    if(pos < s || pos > e) return;
    if(s == e){
        tr[x] = max(tr[x], val);
        return;
    }
    int m = s + e >> 1;
    push(x * 2, s, m, pos, val);
    push(x * 2 + 1, m + 1, e, pos, val);
    tr[x] = max(tr[x * 2], tr[x * 2 + 1]);
}

int get(int x, int s, int e, int fs, int fe){
    if(fe < s || fs > e) return 0;
    if(fs <= s && fe >= e) return tr[x];
    int m = s + e >> 1;
    return max(get(x * 2, s, m, fs, fe), get(x * 2 + 1, m + 1, e, fs, fe));
}

signed main(){
    int n; cin >> n;
    vector<int> a(n), b(n);
    for(int i = 0; i < n; ++i){
        cin >> a[i];
    }
    for(int i = 0; i < n; ++i){
        cin >> b[i];
    }
    vector<pair<int, int>> ij;
    for(int i = 0; i < n; ++i){
        if(a[i] > 1 && i + a[i] - 1 < n) ij.push_back({i, i + a[i] - 1});
        if(a[i] > 1 && i - a[i] + 1 >= 0) ij.push_back({i - a[i] + 1, i});
    }
    sort(ij.begin(), ij.end(), [&](pair<int, int>&x, pair<int, int>&y){return x.first < y.first || (x.first == y.first && x.second > y.second);});
    int j = 0;
    vector<int> ans(n);
    for(int i = 0; i < n; ++i){
        int k = j;
        vector<int> val(n);
        vector<vector<int>> plazy;
        while(k < (int)ij.size() && ij[k].first == i){
            val[ij[k].second] = get(1, 0, n - 1, ij[k].second, n - 1);
            if(ij[k].second - ij[k].first + 1 == a[ij[k].first]){
                plazy.push_back({ij[k].second, val[ij[k].second] + b[ij[k].first]});
            }
            if(ij[k].second - ij[k].first + 1 == a[ij[k].second]){
                push(1, 0, n - 1, ij[k].second - 1, val[ij[k].second] + b[ij[k].second]);
            }
            ++k;
        }
        j = k;
        ans[i] = get(1, 0, n - 1, i, n - 1) + (a[i] == 1) * b[i];
        for(auto&x:plazy){
            push(1, 0, n - 1, x[0], x[1]);
        }
    }
    for(int i = 0; i < n; ++i){
        cout << ans[i] << ' ';
    }
    return 0;
}

Compilation message

gorgeous.cpp: In function 'void push(long long int, long long int, long long int, long long int, long long int)':
gorgeous.cpp:14:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   14 |     int m = s + e >> 1;
      |             ~~^~~
gorgeous.cpp: In function 'long long int get(long long int, long long int, long long int, long long int, long long int)':
gorgeous.cpp:23:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   23 |     int m = s + e >> 1;
      |             ~~^~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 260 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 2 ms 316 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 212 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 7 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 260 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 2 ms 340 KB Output is correct
12 Correct 2 ms 340 KB Output is correct
13 Correct 2 ms 316 KB Output is correct
14 Correct 2 ms 340 KB Output is correct
15 Correct 2 ms 340 KB Output is correct
16 Correct 11 ms 828 KB Output is correct
17 Correct 129 ms 2524 KB Output is correct
18 Execution timed out 1595 ms 8252 KB Time limit exceeded
19 Halted 0 ms 0 KB -