Submission #877348

# Submission time Handle Problem Language Result Execution time Memory
877348 2023-11-23T07:34:16 Z Irate Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
47 / 100
2950 ms 125608 KB
#include<bits/stdc++.h>
using namespace std;
const int mxN = 1e6 + 5;
int LOG[mxN];
struct SparseTable{
    vector<vector<int>>sTable;
    SparseTable(int n, vector<int>&v){
        sTable.resize(LOG[n] + 1);
        for(int i = 0;i <= LOG[n];++i){
            sTable[i].resize(n + 1);
        }
        for(int i = 1;i <= n;++i){
            sTable[0][i] = v[i];
        }
        for(int i = 1;i <= LOG[n];++i){
            for(int j = 1;j + (1 << (i - 1)) <= n;++j){
                sTable[i][j] = max(sTable[i - 1][j], sTable[i - 1][j + (1 << (i - 1))]);
            }
        }
    }
    int Query(int l, int r){
        int lg = LOG[r - l + 1];
        return max(sTable[lg][l], sTable[lg][r - (1 << lg) + 1]);
    }
};
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n, q, MAX = 0;
    cin >> n >> q;
    vector<int>v(n + 1);
    vector<vector<int>>pos(1001);
    LOG[1] = 0;
    for(int i = 2;i <= n;++i)LOG[i] = LOG[i >> 1] + 1;
    for(int i = 1;i <= n;++i){
        cin >> v[i];
        if(v[i] <= 1000)pos[v[i]].push_back(i);
        MAX = max(MAX, v[i]);
    }
    vector<int>pref(n + 1);
    for(int i = 1;i < n;++i){
        pref[i] = (v[i] > v[i + 1]);
    }
    for(int i = 1;i < n;++i){
        pref[i] += pref[i - 1];
    }
    SparseTable table(n, v);
    while(q--){
        int l, r, k;
        cin >> l >> r >> k;
        if(n <= 5000 && q <= 5000){
            int mx = v[l], res = 0;
            for(int i = l + 1;i <= r;++i){
                if(mx > v[i]){
                    res = max(res, mx + v[i]);
                }
                mx = max(mx, v[i]);
            }
            cout << (res <= k) << '\n';
        }
        else if(n <= 1e5 && MAX <= 1000){
            int mx = 0;
            for(int i = 0;i <= 1000;++i){
                if(pos[i].size() != 0){
                    auto itr = upper_bound(pos[i].begin(), pos[i].end(), r);
                    if(itr == pos[i].begin())continue;
                    itr--;
                    if(*itr >= l){
                        int R = *itr, MX = table.Query(l, R);
                        mx = max(mx, (MX > i) * (MX + i));
                    }
                }
            }
            cout << (mx <= k) << '\n';
        }
        else{
            int cnt = pref[r - 1] - pref[l - 1];
            if(cnt){
                cout << 0 << '\n';
            }
            else{
                cout << 1 << '\n';
            }
        }
    }
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 508 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 508 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 6 ms 860 KB Output is correct
13 Correct 7 ms 860 KB Output is correct
14 Correct 10 ms 736 KB Output is correct
15 Correct 10 ms 856 KB Output is correct
16 Correct 17 ms 944 KB Output is correct
17 Correct 14 ms 864 KB Output is correct
18 Correct 17 ms 860 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 363 ms 124376 KB Output is correct
2 Correct 366 ms 125412 KB Output is correct
3 Correct 360 ms 125272 KB Output is correct
4 Correct 376 ms 125608 KB Output is correct
5 Correct 384 ms 125520 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2950 ms 13080 KB Output is correct
2 Correct 2420 ms 12916 KB Output is correct
3 Correct 1303 ms 12756 KB Output is correct
4 Correct 1218 ms 12864 KB Output is correct
5 Correct 1042 ms 12852 KB Output is correct
6 Correct 1741 ms 12880 KB Output is correct
7 Correct 1843 ms 12708 KB Output is correct
8 Correct 116 ms 12488 KB Output is correct
9 Correct 247 ms 1896 KB Output is correct
10 Correct 110 ms 12344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 508 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 6 ms 860 KB Output is correct
13 Correct 7 ms 860 KB Output is correct
14 Correct 10 ms 736 KB Output is correct
15 Correct 10 ms 856 KB Output is correct
16 Correct 17 ms 944 KB Output is correct
17 Correct 14 ms 864 KB Output is correct
18 Correct 17 ms 860 KB Output is correct
19 Incorrect 77 ms 25384 KB Output isn't correct
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 508 KB Output is correct
8 Correct 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 6 ms 860 KB Output is correct
13 Correct 7 ms 860 KB Output is correct
14 Correct 10 ms 736 KB Output is correct
15 Correct 10 ms 856 KB Output is correct
16 Correct 17 ms 944 KB Output is correct
17 Correct 14 ms 864 KB Output is correct
18 Correct 17 ms 860 KB Output is correct
19 Correct 363 ms 124376 KB Output is correct
20 Correct 366 ms 125412 KB Output is correct
21 Correct 360 ms 125272 KB Output is correct
22 Correct 376 ms 125608 KB Output is correct
23 Correct 384 ms 125520 KB Output is correct
24 Correct 2950 ms 13080 KB Output is correct
25 Correct 2420 ms 12916 KB Output is correct
26 Correct 1303 ms 12756 KB Output is correct
27 Correct 1218 ms 12864 KB Output is correct
28 Correct 1042 ms 12852 KB Output is correct
29 Correct 1741 ms 12880 KB Output is correct
30 Correct 1843 ms 12708 KB Output is correct
31 Correct 116 ms 12488 KB Output is correct
32 Correct 247 ms 1896 KB Output is correct
33 Correct 110 ms 12344 KB Output is correct
34 Incorrect 77 ms 25384 KB Output isn't correct
35 Halted 0 ms 0 KB -