Submission #859778

# Submission time Handle Problem Language Result Execution time Memory
859778 2023-10-10T15:44:44 Z Alfraganus Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
0 / 100
3000 ms 10292 KB
#include <bits/stdc++.h>
using namespace std;

#define endl '\n'
#define ll long long
#define all(a) a.begin(), a.end()
#define fastio ios::sync_with_stdio(0), cin.tie(0);
#define fs first
#define ss second

#define print(a)          \
    for (auto x : a)      \
        cout << x << ' '; \
    cout << endl;

#define printmp(a)   \
    for (auto x : a) \
        cout << x.fs << ' ' << x.ss << endl;

void solve()
{
    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    for (int i = 0; i < n; i++)
        cin >> a[i];
    vector<int> dp(n);
    for(int i = 0; i < n - 1; i ++)
        dp[i + 1] = a[i + 1] <= a[i];
    for(int i = 1; i < n; i ++)
        dp[i] += dp[i - 1];
    while (q--)
    {
        int l, r, k;
        cin >> l >> r >> k;
        bool flag = 1;
        l--;
        r--;
        if(a[l] > k and a[r] > k){
            if(dp[l] == dp[r])
                cout << 1 << endl;
            else
                cout << 0 << endl;
            continue;
        }
        int mx = 0;
        for (int i = l; i <= r; i++)
        {
            if(mx > a[i] and mx + a[i] > k){
                flag = 0;
                break;
            }
            mx = max(mx, a[i]);
        }
        if (flag)
            cout << 1 << endl;
        else
            cout << 0 << endl;
    }
}

signed main()
{
    fastio int t = 1;
    // cin >> t;
    while (t--)
    {
        solve();
        cout << endl;
    }
}
# 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 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Incorrect 0 ms 348 KB Output isn't correct
11 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 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Incorrect 0 ms 348 KB Output isn't correct
11 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 336 ms 10068 KB Output is correct
2 Correct 338 ms 10292 KB Output is correct
3 Correct 343 ms 10064 KB Output is correct
4 Correct 336 ms 10252 KB Output is correct
5 Incorrect 340 ms 10252 KB Output isn't correct
6 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 348 ms 1580 KB Output is correct
2 Correct 1140 ms 1540 KB Output is correct
3 Execution timed out 3054 ms 1560 KB Time limit exceeded
4 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 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Incorrect 0 ms 348 KB Output isn't correct
11 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 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Incorrect 0 ms 348 KB Output isn't correct
11 Halted 0 ms 0 KB -