Submission #707135

# Submission time Handle Problem Language Result Execution time Memory
707135 2023-03-08T13:47:33 Z Karuk Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++14
100 / 100
2965 ms 222904 KB
#include<bits/stdc++.h>///3:27- func start///3:41 end
using namespace std;
vector<vector<int>>st;
int score[4000000];
int k=1;
vector<int>ind;
void push(int from,int to,int cur=1,int beg=0,int en=k-1) {
    if(from>en || to<beg)return;
    if(from<=beg && en<=to){ind.push_back(cur);return;}
    int mid=(beg+en)/2;
    push(from,to,cur*2,beg,mid);
    push(from,to,cur*2+1,mid+1,en);
}
int combine(int i,int j) {
    if(st[j].size()==0 || st[i].size()==0)return score[i];
    int mx=st[i].back();
    int ans=max(score[i],score[j]);
    int ind=lower_bound(st[j].begin(),st[j].end(),mx)-st[j].begin();
    ind--;
    if(ind>=0)ans=max(ans,mx+st[j][ind]);
    return ans;
}
int maxw(int l,int r) {
    ind.clear();
    push(l,r);
    int ans=score[ind.back()];
    int maxind=0;
    for(int i=1;i<ind.size();i++) {
        ans=max(ans,combine(ind[maxind],ind[i]));
        if(st[ind[i]].back()>st[ind[maxind]].back())maxind=i;
    }
    return ans;
}
int main() {
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n,m;cin>>n>>m;
    int a[n];
    for(int i=0;i<n;i++)cin>>a[i];
    while(k<n){k<<=1;}
    st.resize(k*2+1);
    for(int i=0;i<n;i++)st[i+k].push_back(a[i]);
    for(int i=k-1;i>0;i--) {
        int p1=0,p2=0;
        while(p1<st[i*2].size() && p2<st[i*2+1].size()) {
            if(st[i*2][p1]<st[i*2+1][p2]) {
                st[i].push_back(st[i*2][p1]);
                p1++;
            } else {
                st[i].push_back(st[i*2+1][p2]);
                p2++;
            }
        }
        while(p1<st[i*2].size()) {
            st[i].push_back(st[i*2][p1]);
            p1++;
        }
        while(p2<st[i*2+1].size()) {
            st[i].push_back(st[i*2+1][p2]);
            p2++;
        }
        score[i]=combine(2*i,2*i+1);
    }
    for(int i=0;i<m;i++) {
        int l,r,w;cin>>l>>r>>w;
        l--;r--;
        int as=maxw(l,r);
        if(as<=w)cout<<1<<'\n';
        else cout<<0<<'\n';
    }
    return 0;
}
/**
5 6
3 2 9 8 1
*/

Compilation message

sortbooks.cpp: In function 'int maxw(int, int)':
sortbooks.cpp:28:18: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   28 |     for(int i=1;i<ind.size();i++) {
      |                 ~^~~~~~~~~~~
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:44:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |         while(p1<st[i*2].size() && p2<st[i*2+1].size()) {
      |               ~~^~~~~~~~~~~~~~~
sortbooks.cpp:44:38: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   44 |         while(p1<st[i*2].size() && p2<st[i*2+1].size()) {
      |                                    ~~^~~~~~~~~~~~~~~~~
sortbooks.cpp:53:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   53 |         while(p1<st[i*2].size()) {
      |               ~~^~~~~~~~~~~~~~~
sortbooks.cpp:57:17: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   57 |         while(p2<st[i*2+1].size()) {
      |               ~~^~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 3 ms 596 KB Output is correct
12 Correct 5 ms 1236 KB Output is correct
13 Correct 5 ms 1364 KB Output is correct
14 Correct 9 ms 1408 KB Output is correct
15 Correct 7 ms 1404 KB Output is correct
16 Correct 5 ms 1364 KB Output is correct
17 Correct 4 ms 980 KB Output is correct
18 Correct 5 ms 1364 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2818 ms 189188 KB Output is correct
2 Correct 2822 ms 191228 KB Output is correct
3 Correct 2965 ms 189156 KB Output is correct
4 Correct 2830 ms 190980 KB Output is correct
5 Correct 2442 ms 189404 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 181 ms 19608 KB Output is correct
2 Correct 159 ms 19712 KB Output is correct
3 Correct 187 ms 19704 KB Output is correct
4 Correct 156 ms 19640 KB Output is correct
5 Correct 161 ms 19888 KB Output is correct
6 Correct 124 ms 19612 KB Output is correct
7 Correct 122 ms 19728 KB Output is correct
8 Correct 133 ms 19636 KB Output is correct
9 Correct 38 ms 656 KB Output is correct
10 Correct 128 ms 19604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 3 ms 596 KB Output is correct
12 Correct 5 ms 1236 KB Output is correct
13 Correct 5 ms 1364 KB Output is correct
14 Correct 9 ms 1408 KB Output is correct
15 Correct 7 ms 1404 KB Output is correct
16 Correct 5 ms 1364 KB Output is correct
17 Correct 4 ms 980 KB Output is correct
18 Correct 5 ms 1364 KB Output is correct
19 Correct 451 ms 39504 KB Output is correct
20 Correct 431 ms 39460 KB Output is correct
21 Correct 344 ms 39492 KB Output is correct
22 Correct 342 ms 39472 KB Output is correct
23 Correct 343 ms 39480 KB Output is correct
24 Correct 279 ms 39584 KB Output is correct
25 Correct 304 ms 39560 KB Output is correct
26 Correct 370 ms 39496 KB Output is correct
27 Correct 357 ms 39492 KB Output is correct
28 Correct 383 ms 39628 KB Output is correct
29 Correct 363 ms 39456 KB Output is correct
30 Correct 397 ms 39404 KB Output is correct
31 Correct 388 ms 39404 KB Output is correct
32 Correct 407 ms 39436 KB Output is correct
33 Correct 403 ms 39552 KB Output is correct
34 Correct 276 ms 39472 KB Output is correct
35 Correct 265 ms 39480 KB Output is correct
36 Correct 262 ms 39500 KB Output is correct
37 Correct 258 ms 39420 KB Output is correct
38 Correct 268 ms 39500 KB Output is correct
39 Correct 330 ms 39472 KB Output is correct
40 Correct 211 ms 23548 KB Output is correct
41 Correct 311 ms 39488 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 340 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 3 ms 596 KB Output is correct
12 Correct 5 ms 1236 KB Output is correct
13 Correct 5 ms 1364 KB Output is correct
14 Correct 9 ms 1408 KB Output is correct
15 Correct 7 ms 1404 KB Output is correct
16 Correct 5 ms 1364 KB Output is correct
17 Correct 4 ms 980 KB Output is correct
18 Correct 5 ms 1364 KB Output is correct
19 Correct 2818 ms 189188 KB Output is correct
20 Correct 2822 ms 191228 KB Output is correct
21 Correct 2965 ms 189156 KB Output is correct
22 Correct 2830 ms 190980 KB Output is correct
23 Correct 2442 ms 189404 KB Output is correct
24 Correct 181 ms 19608 KB Output is correct
25 Correct 159 ms 19712 KB Output is correct
26 Correct 187 ms 19704 KB Output is correct
27 Correct 156 ms 19640 KB Output is correct
28 Correct 161 ms 19888 KB Output is correct
29 Correct 124 ms 19612 KB Output is correct
30 Correct 122 ms 19728 KB Output is correct
31 Correct 133 ms 19636 KB Output is correct
32 Correct 38 ms 656 KB Output is correct
33 Correct 128 ms 19604 KB Output is correct
34 Correct 451 ms 39504 KB Output is correct
35 Correct 431 ms 39460 KB Output is correct
36 Correct 344 ms 39492 KB Output is correct
37 Correct 342 ms 39472 KB Output is correct
38 Correct 343 ms 39480 KB Output is correct
39 Correct 279 ms 39584 KB Output is correct
40 Correct 304 ms 39560 KB Output is correct
41 Correct 370 ms 39496 KB Output is correct
42 Correct 357 ms 39492 KB Output is correct
43 Correct 383 ms 39628 KB Output is correct
44 Correct 363 ms 39456 KB Output is correct
45 Correct 397 ms 39404 KB Output is correct
46 Correct 388 ms 39404 KB Output is correct
47 Correct 407 ms 39436 KB Output is correct
48 Correct 403 ms 39552 KB Output is correct
49 Correct 276 ms 39472 KB Output is correct
50 Correct 265 ms 39480 KB Output is correct
51 Correct 262 ms 39500 KB Output is correct
52 Correct 258 ms 39420 KB Output is correct
53 Correct 268 ms 39500 KB Output is correct
54 Correct 330 ms 39472 KB Output is correct
55 Correct 211 ms 23548 KB Output is correct
56 Correct 311 ms 39488 KB Output is correct
57 Correct 2795 ms 189332 KB Output is correct
58 Correct 2788 ms 222792 KB Output is correct
59 Correct 2845 ms 222848 KB Output is correct
60 Correct 2780 ms 222836 KB Output is correct
61 Correct 2835 ms 222708 KB Output is correct
62 Correct 2791 ms 222832 KB Output is correct
63 Correct 1590 ms 220876 KB Output is correct
64 Correct 1680 ms 220824 KB Output is correct
65 Correct 2649 ms 222588 KB Output is correct
66 Correct 2446 ms 222788 KB Output is correct
67 Correct 2393 ms 222824 KB Output is correct
68 Correct 2416 ms 222904 KB Output is correct
69 Correct 2417 ms 222808 KB Output is correct
70 Correct 2457 ms 222708 KB Output is correct
71 Correct 2487 ms 222636 KB Output is correct
72 Correct 2432 ms 222768 KB Output is correct
73 Correct 1502 ms 219144 KB Output is correct
74 Correct 1542 ms 220108 KB Output is correct
75 Correct 1521 ms 219308 KB Output is correct
76 Correct 1508 ms 219128 KB Output is correct
77 Correct 1522 ms 219128 KB Output is correct
78 Correct 2302 ms 216484 KB Output is correct
79 Correct 1255 ms 119640 KB Output is correct
80 Correct 2012 ms 213784 KB Output is correct