답안 #876685

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
876685 2023-11-22T08:27:08 Z Irate Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
34 / 100
2971 ms 11024 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;
    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);
    }
    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{
            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';
        }
    }
}
# 결과 실행 시간 메모리 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 0 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 0 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 772 KB Output is correct
14 Correct 10 ms 604 KB Output is correct
15 Correct 10 ms 604 KB Output is correct
16 Correct 17 ms 604 KB Output is correct
17 Correct 14 ms 772 KB Output is correct
18 Correct 16 ms 828 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 5 ms 9308 KB Execution killed with signal 11
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 2971 ms 9072 KB Output is correct
2 Correct 2426 ms 11024 KB Output is correct
3 Correct 1295 ms 10648 KB Output is correct
4 Correct 1070 ms 10576 KB Output is correct
5 Correct 974 ms 10756 KB Output is correct
6 Correct 1831 ms 10356 KB Output is correct
7 Correct 1837 ms 10596 KB Output is correct
8 Correct 109 ms 10332 KB Output is correct
9 Correct 248 ms 1872 KB Output is correct
10 Correct 121 ms 10224 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 0 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 772 KB Output is correct
14 Correct 10 ms 604 KB Output is correct
15 Correct 10 ms 604 KB Output is correct
16 Correct 17 ms 604 KB Output is correct
17 Correct 14 ms 772 KB Output is correct
18 Correct 16 ms 828 KB Output is correct
19 Runtime error 2 ms 2904 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 0 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 772 KB Output is correct
14 Correct 10 ms 604 KB Output is correct
15 Correct 10 ms 604 KB Output is correct
16 Correct 17 ms 604 KB Output is correct
17 Correct 14 ms 772 KB Output is correct
18 Correct 16 ms 828 KB Output is correct
19 Runtime error 5 ms 9308 KB Execution killed with signal 11
20 Halted 0 ms 0 KB -