답안 #876684

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
876684 2023-11-22T08:25:03 Z Irate Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
17 / 100
3000 ms 10760 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 = 1;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 1 ms 604 KB Output is correct
6 Correct 1 ms 344 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 1 ms 604 KB Output is correct
6 Correct 1 ms 344 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 604 KB Output is correct
12 Correct 5 ms 876 KB Output is correct
13 Correct 6 ms 860 KB Output is correct
14 Correct 10 ms 860 KB Output is correct
15 Correct 10 ms 860 KB Output is correct
16 Correct 17 ms 920 KB Output is correct
17 Correct 14 ms 860 KB Output is correct
18 Correct 17 ms 860 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 Execution timed out 3057 ms 10760 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 1 ms 604 KB Output is correct
6 Correct 1 ms 344 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 604 KB Output is correct
12 Correct 5 ms 876 KB Output is correct
13 Correct 6 ms 860 KB Output is correct
14 Correct 10 ms 860 KB Output is correct
15 Correct 10 ms 860 KB Output is correct
16 Correct 17 ms 920 KB Output is correct
17 Correct 14 ms 860 KB Output is correct
18 Correct 17 ms 860 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 1 ms 604 KB Output is correct
6 Correct 1 ms 344 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 604 KB Output is correct
12 Correct 5 ms 876 KB Output is correct
13 Correct 6 ms 860 KB Output is correct
14 Correct 10 ms 860 KB Output is correct
15 Correct 10 ms 860 KB Output is correct
16 Correct 17 ms 920 KB Output is correct
17 Correct 14 ms 860 KB Output is correct
18 Correct 17 ms 860 KB Output is correct
19 Runtime error 5 ms 9308 KB Execution killed with signal 11
20 Halted 0 ms 0 KB -