Submission #1073845

# Submission time Handle Problem Language Result Execution time Memory
1073845 2024-08-24T23:55:19 Z vjudge1 Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
0 / 100
50 ms 108880 KB
#include <bits/stdc++.h>
#define int long long
using namespace std;

const int N = 1e6 + 7;
int a[N], lg[N + 1], s[21][N + 1], st[21][N + 1], mx[N], ans[N];
int get(int l, int r) {
    if(l > r)return 0;
    int le = lg[r - l + 1];
    return max(s[l][le], s[r - (1 << le) + 1][le]);
}
struct node {
    int l, k, in;    
};
vector<node> qu[N];
int tr[4 * N];
void upd(int i, int x, int v, int lx, int rx) {
    if(lx == rx) {
        tr[v] = max(tr[v], x);
        return;
    }
    int m = (lx + rx) >> 1;
    if(i <= m)upd(i, x, v + v, lx, m);
    else upd(i, x, v + v + 1, m + 1, rx);
    tr[v] = max(tr[v + v], tr[v + v + 1]);
}
int get(int l, int r, int v, int lx, int rx) {
    if(lx > r || l > rx)return 0;
    if(lx >= l && r >= rx)return tr[v];
    int m = (lx + rx) >> 1;
    return max(get(l, r, v + v, lx, m), get(l, r, v + v + 1, m + 1, rx));
}
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n, m;
    cin>>n>>m;
    for(int i = 1; i <= n; i++) {
        cin>>a[i];
        s[i][0] = a[i];
    }
    lg[1] = 0;
    for (int i = 2; i <= N; i++)lg[i] = lg[i / 2] + 1;
    for(int i = 1; i <= 20; i++){
        for(int x = 1; x + (1 << i) - 1 <= n; x++){
            s[x][i] = max(s[x][i - 1], s[x + (1 << (i - 1))][i - 1]);
        }
    }
    for(int i = 1; i <= n; i++) {
        if(get(1, i - 1) <= a[i]) {
            mx[i] = 0;
            continue;
        }
        int l = 1, r = i - 1, res = 0;
        while(l <= r) {
            int m = (l + r) >> 1;
            if(get(m, i - 1) > a[i])l = m + 1, res = m;
            else r = m - 1;
        }
        mx[i] = res;
    }
    for(int i = 1; i <= m; i++) {
        int l, r, k;
        cin>>l>>r>>k;
        qu[r].push_back({l, k, i});
    }
    //хахахахаха, буквально второй парой каждой позиции, при том что мы хотим увеличить стоимость, это просто ближайший больший слева. Ведь если есть другой больше слева, который мы можем взять, его можно взять в пару вместе с нашим максом и его)
    for(int i = 1; i <= n; i++) {
        if(mx[i])upd(mx[i], a[i] + a[mx[i]], 1, 1, n);
        for(int j = 0; j < qu[i].size(); j++) {
            int l = qu[i][j].l, r = i, k = qu[i][j].k, index = qu[i][j].in;
            int mxx = get(l, r, 1, 1, n);
            if(mxx > k)ans[index] = 0;
            else ans[index] = 1;
        }
    }
    for(int i = 1; i <= m; i++)cout << ans[i] << '\n';
}

Compilation message

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:70:26: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<node>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   70 |         for(int j = 0; j < qu[i].size(); j++) {
      |                        ~~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 7 ms 47448 KB Output is correct
2 Correct 6 ms 39256 KB Output is correct
3 Runtime error 46 ms 104528 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 47448 KB Output is correct
2 Correct 6 ms 39256 KB Output is correct
3 Runtime error 46 ms 104528 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 50 ms 104644 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Runtime error 49 ms 108880 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 47448 KB Output is correct
2 Correct 6 ms 39256 KB Output is correct
3 Runtime error 46 ms 104528 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 47448 KB Output is correct
2 Correct 6 ms 39256 KB Output is correct
3 Runtime error 46 ms 104528 KB Execution killed with signal 11
4 Halted 0 ms 0 KB -