Submission #428548

# Submission time Handle Problem Language Result Execution time Memory
428548 2021-06-15T12:49:10 Z FEDIKUS Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1945 ms 96688 KB
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define xx first
#define yy second
#define srt(a) sort(a.begin(),a.end());
#define srtg(a,int) sort(a.begin(),a.end(),greater<int>())
#define lb(a,x) lower_bound(a.begin(),a.end(),x)
#define up(a,x) upper_bound(a.begin(),a.end(),x)
#define fnd(a,x) find(a.begin(),a.end(),x)
#define vstart auto startt=chrono::system_clock::now()
#define vend auto endd=chrono::system_clock::now()
#define vvreme chrono::duration<double> vremee=endd-startt
#define ios ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef string str;

const int maxn=1e6+10;
int niz[maxn];
int res[maxn];
int n,m;

vector<pair<pii,int> > query[maxn];

int segt[4*maxn];

void update(int t,int v,int ind=1,int l=0,int r=n-1){
    if(l==r){
        segt[ind]=v;
        return;
    }
    int mid=l+(r-l)/2;
    if(t<=mid) update(t,v,2*ind,l,mid);
    else update(t,v,2*ind+1,mid+1,r);
    segt[ind]=max(segt[2*ind],segt[2*ind+1]);
}

int upit(int tl,int tr,int ind=1,int l=0,int r=n-1){
    if(tl<=l && r<=tr) return segt[ind];
    int mid=l+(r-l)/2;
    int ret=0;
    if(tl<=mid) ret=max(ret,upit(tl,tr,2*ind,l,mid));
    if(tr>mid) ret=max(ret,upit(tl,tr,2*ind+1,mid+1,r));
    return ret;
}

void solve(){
    cin>>n>>m;
    for(int i=0;i<n;i++) cin>>niz[i];
    for(int i=0;i<m;i++){
        int l,r,a;
        cin>>l>>r>>a;
        query[r-1].pb(mp(mp(l-1,a),i));
    }
    stack<pii> nesto;
    for(int i=0;i<n;i++){
        while(!nesto.empty() && nesto.top().xx<=niz[i])
            nesto.pop();
        if(!nesto.empty()) update(nesto.top().yy,nesto.top().xx+niz[i]);
        for(auto j:query[i]){
            if(upit(j.xx.xx,i)>j.xx.yy){
                res[j.yy]=0;
            }else res[j.yy]=1;
        }
        nesto.push(mp(niz[i],i));
    }
    for(int i=0;i<m;i++) cout<<res[i]<<"\n";
}

int main(){
    ios;
    int t=1;
    //cin>>t;
    while(t--) solve();
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23756 KB Output is correct
2 Correct 14 ms 23756 KB Output is correct
3 Correct 17 ms 23732 KB Output is correct
4 Correct 14 ms 23756 KB Output is correct
5 Correct 14 ms 23756 KB Output is correct
6 Correct 16 ms 23756 KB Output is correct
7 Correct 14 ms 23756 KB Output is correct
8 Correct 14 ms 23840 KB Output is correct
9 Correct 14 ms 23756 KB Output is correct
10 Correct 14 ms 23756 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23756 KB Output is correct
2 Correct 14 ms 23756 KB Output is correct
3 Correct 17 ms 23732 KB Output is correct
4 Correct 14 ms 23756 KB Output is correct
5 Correct 14 ms 23756 KB Output is correct
6 Correct 16 ms 23756 KB Output is correct
7 Correct 14 ms 23756 KB Output is correct
8 Correct 14 ms 23840 KB Output is correct
9 Correct 14 ms 23756 KB Output is correct
10 Correct 14 ms 23756 KB Output is correct
11 Correct 16 ms 23952 KB Output is correct
12 Correct 18 ms 24088 KB Output is correct
13 Correct 18 ms 24012 KB Output is correct
14 Correct 20 ms 24104 KB Output is correct
15 Correct 19 ms 24080 KB Output is correct
16 Correct 19 ms 24108 KB Output is correct
17 Correct 18 ms 24016 KB Output is correct
18 Correct 19 ms 23952 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1876 ms 63592 KB Output is correct
2 Correct 1850 ms 63488 KB Output is correct
3 Correct 1912 ms 63608 KB Output is correct
4 Correct 1812 ms 63596 KB Output is correct
5 Correct 1456 ms 55416 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 135 ms 27900 KB Output is correct
2 Correct 137 ms 29548 KB Output is correct
3 Correct 118 ms 28868 KB Output is correct
4 Correct 116 ms 28828 KB Output is correct
5 Correct 124 ms 28840 KB Output is correct
6 Correct 100 ms 28356 KB Output is correct
7 Correct 100 ms 28340 KB Output is correct
8 Correct 113 ms 28480 KB Output is correct
9 Correct 73 ms 27132 KB Output is correct
10 Correct 114 ms 28424 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23756 KB Output is correct
2 Correct 14 ms 23756 KB Output is correct
3 Correct 17 ms 23732 KB Output is correct
4 Correct 14 ms 23756 KB Output is correct
5 Correct 14 ms 23756 KB Output is correct
6 Correct 16 ms 23756 KB Output is correct
7 Correct 14 ms 23756 KB Output is correct
8 Correct 14 ms 23840 KB Output is correct
9 Correct 14 ms 23756 KB Output is correct
10 Correct 14 ms 23756 KB Output is correct
11 Correct 16 ms 23952 KB Output is correct
12 Correct 18 ms 24088 KB Output is correct
13 Correct 18 ms 24012 KB Output is correct
14 Correct 20 ms 24104 KB Output is correct
15 Correct 19 ms 24080 KB Output is correct
16 Correct 19 ms 24108 KB Output is correct
17 Correct 18 ms 24016 KB Output is correct
18 Correct 19 ms 23952 KB Output is correct
19 Correct 300 ms 38760 KB Output is correct
20 Correct 301 ms 38668 KB Output is correct
21 Correct 260 ms 37956 KB Output is correct
22 Correct 261 ms 38044 KB Output is correct
23 Correct 260 ms 38032 KB Output is correct
24 Correct 219 ms 35704 KB Output is correct
25 Correct 218 ms 35708 KB Output is correct
26 Correct 241 ms 36064 KB Output is correct
27 Correct 255 ms 36132 KB Output is correct
28 Correct 283 ms 36224 KB Output is correct
29 Correct 283 ms 36508 KB Output is correct
30 Correct 265 ms 36588 KB Output is correct
31 Correct 296 ms 36532 KB Output is correct
32 Correct 332 ms 36580 KB Output is correct
33 Correct 269 ms 36464 KB Output is correct
34 Correct 215 ms 35396 KB Output is correct
35 Correct 230 ms 35328 KB Output is correct
36 Correct 221 ms 35200 KB Output is correct
37 Correct 208 ms 35176 KB Output is correct
38 Correct 255 ms 35328 KB Output is correct
39 Correct 277 ms 35548 KB Output is correct
40 Correct 180 ms 33480 KB Output is correct
41 Correct 250 ms 34360 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 14 ms 23756 KB Output is correct
2 Correct 14 ms 23756 KB Output is correct
3 Correct 17 ms 23732 KB Output is correct
4 Correct 14 ms 23756 KB Output is correct
5 Correct 14 ms 23756 KB Output is correct
6 Correct 16 ms 23756 KB Output is correct
7 Correct 14 ms 23756 KB Output is correct
8 Correct 14 ms 23840 KB Output is correct
9 Correct 14 ms 23756 KB Output is correct
10 Correct 14 ms 23756 KB Output is correct
11 Correct 16 ms 23952 KB Output is correct
12 Correct 18 ms 24088 KB Output is correct
13 Correct 18 ms 24012 KB Output is correct
14 Correct 20 ms 24104 KB Output is correct
15 Correct 19 ms 24080 KB Output is correct
16 Correct 19 ms 24108 KB Output is correct
17 Correct 18 ms 24016 KB Output is correct
18 Correct 19 ms 23952 KB Output is correct
19 Correct 1876 ms 63592 KB Output is correct
20 Correct 1850 ms 63488 KB Output is correct
21 Correct 1912 ms 63608 KB Output is correct
22 Correct 1812 ms 63596 KB Output is correct
23 Correct 1456 ms 55416 KB Output is correct
24 Correct 135 ms 27900 KB Output is correct
25 Correct 137 ms 29548 KB Output is correct
26 Correct 118 ms 28868 KB Output is correct
27 Correct 116 ms 28828 KB Output is correct
28 Correct 124 ms 28840 KB Output is correct
29 Correct 100 ms 28356 KB Output is correct
30 Correct 100 ms 28340 KB Output is correct
31 Correct 113 ms 28480 KB Output is correct
32 Correct 73 ms 27132 KB Output is correct
33 Correct 114 ms 28424 KB Output is correct
34 Correct 300 ms 38760 KB Output is correct
35 Correct 301 ms 38668 KB Output is correct
36 Correct 260 ms 37956 KB Output is correct
37 Correct 261 ms 38044 KB Output is correct
38 Correct 260 ms 38032 KB Output is correct
39 Correct 219 ms 35704 KB Output is correct
40 Correct 218 ms 35708 KB Output is correct
41 Correct 241 ms 36064 KB Output is correct
42 Correct 255 ms 36132 KB Output is correct
43 Correct 283 ms 36224 KB Output is correct
44 Correct 283 ms 36508 KB Output is correct
45 Correct 265 ms 36588 KB Output is correct
46 Correct 296 ms 36532 KB Output is correct
47 Correct 332 ms 36580 KB Output is correct
48 Correct 269 ms 36464 KB Output is correct
49 Correct 215 ms 35396 KB Output is correct
50 Correct 230 ms 35328 KB Output is correct
51 Correct 221 ms 35200 KB Output is correct
52 Correct 208 ms 35176 KB Output is correct
53 Correct 255 ms 35328 KB Output is correct
54 Correct 277 ms 35548 KB Output is correct
55 Correct 180 ms 33480 KB Output is correct
56 Correct 250 ms 34360 KB Output is correct
57 Correct 1899 ms 96688 KB Output is correct
58 Correct 1945 ms 96588 KB Output is correct
59 Correct 1763 ms 95280 KB Output is correct
60 Correct 1727 ms 95144 KB Output is correct
61 Correct 1812 ms 95044 KB Output is correct
62 Correct 1872 ms 95036 KB Output is correct
63 Correct 1176 ms 83612 KB Output is correct
64 Correct 1108 ms 83568 KB Output is correct
65 Correct 1429 ms 86676 KB Output is correct
66 Correct 1434 ms 86828 KB Output is correct
67 Correct 1480 ms 86884 KB Output is correct
68 Correct 1579 ms 88504 KB Output is correct
69 Correct 1586 ms 88500 KB Output is correct
70 Correct 1537 ms 88300 KB Output is correct
71 Correct 1491 ms 88148 KB Output is correct
72 Correct 1480 ms 88184 KB Output is correct
73 Correct 1028 ms 79452 KB Output is correct
74 Correct 1057 ms 80644 KB Output is correct
75 Correct 1038 ms 79544 KB Output is correct
76 Correct 1022 ms 79852 KB Output is correct
77 Correct 1029 ms 79316 KB Output is correct
78 Correct 1439 ms 83192 KB Output is correct
79 Correct 1045 ms 71552 KB Output is correct
80 Correct 1466 ms 77684 KB Output is correct