답안 #876704

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
876704 2023-11-22T08:44:08 Z Irate Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
17 / 100
3000 ms 9588 KB
#include<bits/stdc++.h>
using namespace std;
const int mxN = 1e5 + 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';
            }
        }
    }
}
# 결과 실행 시간 메모리 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 348 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
# 결과 실행 시간 메모리 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 348 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 3 ms 344 KB Output is correct
12 Correct 5 ms 604 KB Output is correct
13 Correct 6 ms 604 KB Output is correct
14 Correct 10 ms 604 KB Output is correct
15 Correct 10 ms 868 KB Output is correct
16 Correct 17 ms 604 KB Output is correct
17 Correct 14 ms 604 KB Output is correct
18 Correct 17 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 9304 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3012 ms 9588 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 348 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 3 ms 344 KB Output is correct
12 Correct 5 ms 604 KB Output is correct
13 Correct 6 ms 604 KB Output is correct
14 Correct 10 ms 604 KB Output is correct
15 Correct 10 ms 868 KB Output is correct
16 Correct 17 ms 604 KB Output is correct
17 Correct 14 ms 604 KB Output is correct
18 Correct 17 ms 604 KB Output is correct
19 Runtime error 2 ms 2908 KB Execution killed with signal 11
20 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 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 348 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 3 ms 344 KB Output is correct
12 Correct 5 ms 604 KB Output is correct
13 Correct 6 ms 604 KB Output is correct
14 Correct 10 ms 604 KB Output is correct
15 Correct 10 ms 868 KB Output is correct
16 Correct 17 ms 604 KB Output is correct
17 Correct 14 ms 604 KB Output is correct
18 Correct 17 ms 604 KB Output is correct
19 Runtime error 5 ms 9304 KB Execution killed with signal 11
20 Halted 0 ms 0 KB -