Submission #508333

# Submission time Handle Problem Language Result Execution time Memory
508333 2022-01-13T08:52:50 Z Belgutei Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
30 / 100
1116 ms 59404 KB
#include<bits/stdc++.h>

using namespace std;

#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mk make_pair
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

ll n,m;
ll a[1000005];
ll l,r,k;
vector<ll> v[30];
ll level,zereg[30];
ll cnt;

void dfs(int p, int x){
    int y=zereg[level-p]*x;
    int z=zereg[level-p]*(x+1)-1;
    if(l<=y && z<=r){
        cnt+=v[p][x];
        return;
    }
    if(z<l || y>r || p==level) return;
    dfs(p+1,x*2);
    dfs(p+1,x*2+1);
}

int main(){
    IOS
    cin>>n>>m;
    for(int i=1; i<=n; i++){
        cin>>a[i];
    }
    zereg[0]=1;
    for(int i=0; i<=30; i++){
        if(zereg[i]>=n){
            level=i;
            break;
        }
        zereg[i+1]=zereg[i]*2;
    }
    for(int i=0; i<zereg[level]; i++){
        v[level].pb(0);
    }
    for(int i=2; i<=n; i++){
        if(a[i-1]>a[i]){
            v[level][i-1]=1;
        }
    }
    if(n<=5000){
        while(m--){
            cin>>l>>r>>k;
            ll mx=a[l];
            ll mn=a[l];
            bool ok=1;
            for(int i=l+1; i<=r; i++){
                if(mx>a[i]){
                    if(mx+a[i]>k){
                        ok=0;
                        break;
                    }
                }
                if(mn>a[i]){
                    if(mn+a[i]>k){
                        ok=0;
                        break;
                    }
                }
                mx=max(mx,a[i]);
                mn=min(mn,a[i]);
            }
            cout<<ok<<'\n';
        }
        return 0;
    }
    for(int i=level-1; i>=0; i--){
        for(int j=1; j<v[i+1].size(); j+=2){
            v[i].pb(v[i+1][j]+v[i+1][j-1]);
        }
    }
    while(m--){
        cin>>l>>r>>k;
        if(l==r){
            cout<<"1\n";
            continue;
        }
        r--;
        cnt=0;
        dfs(0,0);
        if(cnt==0) cout<<"1\n";
        else cout<<"0\n";
    }
}

Compilation message

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:80:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   80 |         for(int j=1; j<v[i+1].size(); j+=2){
      |                      ~^~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 2 ms 460 KB Output is correct
13 Correct 2 ms 460 KB Output is correct
14 Correct 3 ms 460 KB Output is correct
15 Correct 3 ms 460 KB Output is correct
16 Correct 16 ms 492 KB Output is correct
17 Correct 19 ms 420 KB Output is correct
18 Correct 13 ms 460 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1035 ms 26492 KB Output is correct
2 Correct 1047 ms 59324 KB Output is correct
3 Correct 1116 ms 59284 KB Output is correct
4 Correct 1064 ms 59404 KB Output is correct
5 Correct 1037 ms 39816 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 69 ms 3248 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 2 ms 460 KB Output is correct
13 Correct 2 ms 460 KB Output is correct
14 Correct 3 ms 460 KB Output is correct
15 Correct 3 ms 460 KB Output is correct
16 Correct 16 ms 492 KB Output is correct
17 Correct 19 ms 420 KB Output is correct
18 Correct 13 ms 460 KB Output is correct
19 Incorrect 190 ms 6488 KB Output isn't correct
20 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 0 ms 332 KB Output is correct
7 Correct 1 ms 332 KB Output is correct
8 Correct 1 ms 332 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 2 ms 332 KB Output is correct
12 Correct 2 ms 460 KB Output is correct
13 Correct 2 ms 460 KB Output is correct
14 Correct 3 ms 460 KB Output is correct
15 Correct 3 ms 460 KB Output is correct
16 Correct 16 ms 492 KB Output is correct
17 Correct 19 ms 420 KB Output is correct
18 Correct 13 ms 460 KB Output is correct
19 Correct 1035 ms 26492 KB Output is correct
20 Correct 1047 ms 59324 KB Output is correct
21 Correct 1116 ms 59284 KB Output is correct
22 Correct 1064 ms 59404 KB Output is correct
23 Correct 1037 ms 39816 KB Output is correct
24 Incorrect 69 ms 3248 KB Output isn't correct
25 Halted 0 ms 0 KB -