Submission #843071

# Submission time Handle Problem Language Result Execution time Memory
843071 2023-09-03T15:49:16 Z yahyobekabdunazarov Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
17 / 100
491 ms 39752 KB
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define int long long
#define pii pair<int, int>
#define ff first
#define ss second
//... max1 .... max2
//... max2 .... max1
using namespace std;

const int maxn = 1e6 + 9;
int f[maxn];
void upd(int n){
    while(n < maxn){
        f[n]++;
        n += n & -n;
    }
}
int summa(int n){
    int sm = 0;
    while(n){
        sm += f[n];
        n -= n & -n;
    }
    return sm;
}
int summa(int l, int r){
    return summa(r) - summa(l - 1);
}
void solve(){  
    int n, m;
    cin >> n >> m;
    int a[n + 1];
    a[0] = 1;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        if(a[i] >= a[i - 1]) upd(i);
    }
    while(m--){
        int l, r, k, mx = 0, sum = 0, ok = 1;
        cin >> l >> r >> k;
        if(n <= 5000 && m <= 5000){
            for(int i = l; i <= r; i++){
                sum = max(sum, (a[i] + mx) * (a[i] < mx));
                mx = max(mx, a[i]);
            }
            cout << (sum <= k ? "1\n" : "0\n");
        }
        else{
            cout << (summa(l, r) >= r - l ? "1\n" : "0\n");
        }
    }
}

int32_t main(){
 
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
 
    int t = 1;  
    //cin >> t;
    while(t--){
        solve();
        cout << '\n';
    }

    return 0;
}

Compilation message

sortbooks.cpp: In function 'void solve()':
sortbooks.cpp:40:39: warning: unused variable 'ok' [-Wunused-variable]
   40 |         int l, r, k, mx = 0, sum = 0, ok = 1;
      |                                       ^~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4440 KB Output is correct
8 Correct 1 ms 4440 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4440 KB Output is correct
8 Correct 1 ms 4440 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 5 ms 4440 KB Output is correct
12 Correct 10 ms 4440 KB Output is correct
13 Correct 9 ms 4620 KB Output is correct
14 Correct 15 ms 4444 KB Output is correct
15 Correct 17 ms 4444 KB Output is correct
16 Correct 28 ms 4656 KB Output is correct
17 Correct 24 ms 4444 KB Output is correct
18 Correct 27 ms 4444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 491 ms 39752 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 35 ms 5720 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4440 KB Output is correct
8 Correct 1 ms 4440 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 5 ms 4440 KB Output is correct
12 Correct 10 ms 4440 KB Output is correct
13 Correct 9 ms 4620 KB Output is correct
14 Correct 15 ms 4444 KB Output is correct
15 Correct 17 ms 4444 KB Output is correct
16 Correct 28 ms 4656 KB Output is correct
17 Correct 24 ms 4444 KB Output is correct
18 Correct 27 ms 4444 KB Output is correct
19 Incorrect 76 ms 8940 KB Output isn't correct
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 4444 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 4444 KB Output is correct
4 Correct 1 ms 4444 KB Output is correct
5 Correct 1 ms 4440 KB Output is correct
6 Correct 1 ms 4444 KB Output is correct
7 Correct 1 ms 4440 KB Output is correct
8 Correct 1 ms 4440 KB Output is correct
9 Correct 1 ms 4444 KB Output is correct
10 Correct 1 ms 4444 KB Output is correct
11 Correct 5 ms 4440 KB Output is correct
12 Correct 10 ms 4440 KB Output is correct
13 Correct 9 ms 4620 KB Output is correct
14 Correct 15 ms 4444 KB Output is correct
15 Correct 17 ms 4444 KB Output is correct
16 Correct 28 ms 4656 KB Output is correct
17 Correct 24 ms 4444 KB Output is correct
18 Correct 27 ms 4444 KB Output is correct
19 Incorrect 491 ms 39752 KB Output isn't correct
20 Halted 0 ms 0 KB -