답안 #683381

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
683381 2023-01-18T09:49:51 Z FatihSolak Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
64 / 100
1961 ms 262144 KB
    #include <bits/stdc++.h>
    #define N 1000005
    using namespace std;
    int a[N];
    int ans[N];
    struct node{
        int val = 0,maxi = -1;
    };
    struct event{
        int type,l,r,val,k;
        bool operator <(event &other){
            if(val == other.val){
                return type < other.type;
            }
            return val > other.val;
        }
    };
    vector<event> events;
    struct SegTree{
        vector<node> t;
        int n;
        int idx,k;
        SegTree(int sz){
            n = sz;
            t.assign(4*n,{0,-1});
            build(1,1,n);
        }
        node merge(node a,node b){
            node ret;
            ret.val = max(a.val,b.val);
            ret.maxi = max(a.maxi,b.maxi);
            return ret;
        }
        void build(int v,int tl,int tr){
            if(tl == tr){
                t[v].maxi = a[tl];
                return;
            }
            int tm = (tl + tr)/2;
            build(v*2,tl,tm);
            build(v*2+1,tm+1,tr);
            t[v] = merge(t[v*2],t[v*2+1]);
            for(int i = tm+1;i<=tr;i++){
                if(a[i] < t[v*2].maxi){
                    t[v].val = max(t[v].val,t[v*2].maxi + a[i]);
                }
            }
        }
        node get(int v,int tl,int tr,int l,int r){
            if(tr < l || r < tl){
                return {0,-1};
            }
            if(l <= tl && tr <= r){
                return t[v];
            }
            int tm = (tl + tr)/2;
            node a = get(v*2,tl,tm,l,r);
            node b = get(v*2+1,tm+1,tr,l,r);
            events.push_back({idx,max(l,tm+1),min(r,tr),k + 1 - a.maxi,a.maxi});
            return merge(a,b);
        }
        node get(int l,int r,int id,int kk){
            idx = id;
            k = kk;
            return get(1,1,n,l,r);
        }
    };
    struct SegTree2{
        vector<int> t;
        int n;
        SegTree2(int sz){
            n = sz;
            t.assign(4*n,1e9);
        }
        void upd(int v,int tl,int tr,int pos,int val){
            if(tl == tr){
                t[v] = min(t[v],val);
                return;
            }
            int tm = (tl + tr)/2;
            if(pos <= tm){
                upd(v*2,tl,tm,pos,val);
            }
            else upd(v*2+1,tm+1,tr,pos,val);
            t[v] = min(t[v*2],t[v*2+1]);
        }
        int get(int v,int tl,int tr,int l,int r){
            if(tr < l || r < tl){
                return 1e9;
            }
            if(l <= tl && tr <= r){
                return t[v];
            }
            int tm = (tl + tr)/2;
            return min(get(v*2,tl,tm,l,r),get(v*2+1,tm+1,tr,l,r));
        }
        void upd(int pos,int val){
            upd(1,1,n,pos,val);
        }
        int get(int l,int r){
            return get(1,1,n,l,r);
        }
    };
    void solve(){
        int n,m;
        cin >> n >> m;
        for(int i = 1;i<=n;i++){
            cin >> a[i];
            events.push_back({0,i,i,a[i]});
        }
        SegTree t(n);
        for(int i = 1;i<=m;i++){
            int l,r,k;
            cin >> l >> r >> k;
            ans[i] = t.get(l,r,i,k).val <= k;
        }
        sort(events.begin(),events.end());
        SegTree2 tt(n);
        for(auto u:events){
            if(u.type){
                ans[u.type] &= tt.get(u.l,u.r) >= u.k;
            }
            else tt.upd(u.l,u.val);
        }
        for(int i = 1;i<=m;i++){
            cout << ans[i] << '\n';
        }
    }
        
    int main(){
        ios_base::sync_with_stdio(false);
        cin.tie(nullptr);
        #ifdef Local
        freopen("in.txt","r",stdin);
        freopen("out.txt","w",stdout);
        #endif
        int t=1;
        //cin>>t;
        while(t--){
            solve();
        }
        #ifdef Local
        cout<<endl<<fixed<<setprecision(2)<<1000.0 * clock() / CLOCKS_PER_SEC<< " milliseconds ";
        #endif
    }
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 2 ms 576 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 ms 592 KB Output is correct
7 Correct 3 ms 596 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 2 ms 592 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 2 ms 576 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 ms 592 KB Output is correct
7 Correct 3 ms 596 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 2 ms 592 KB Output is correct
11 Correct 12 ms 1884 KB Output is correct
12 Correct 14 ms 2000 KB Output is correct
13 Correct 15 ms 3268 KB Output is correct
14 Correct 24 ms 3272 KB Output is correct
15 Correct 23 ms 3272 KB Output is correct
16 Correct 18 ms 3268 KB Output is correct
17 Correct 11 ms 2028 KB Output is correct
18 Correct 16 ms 3272 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Runtime error 578 ms 262144 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 824 ms 86236 KB Output is correct
2 Correct 797 ms 87880 KB Output is correct
3 Correct 777 ms 87908 KB Output is correct
4 Correct 799 ms 87876 KB Output is correct
5 Correct 758 ms 87996 KB Output is correct
6 Correct 702 ms 87816 KB Output is correct
7 Correct 724 ms 87780 KB Output is correct
8 Correct 477 ms 48276 KB Output is correct
9 Correct 163 ms 22584 KB Output is correct
10 Correct 471 ms 48256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 2 ms 576 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 ms 592 KB Output is correct
7 Correct 3 ms 596 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 2 ms 592 KB Output is correct
11 Correct 12 ms 1884 KB Output is correct
12 Correct 14 ms 2000 KB Output is correct
13 Correct 15 ms 3268 KB Output is correct
14 Correct 24 ms 3272 KB Output is correct
15 Correct 23 ms 3272 KB Output is correct
16 Correct 18 ms 3268 KB Output is correct
17 Correct 11 ms 2028 KB Output is correct
18 Correct 16 ms 3272 KB Output is correct
19 Correct 1733 ms 177244 KB Output is correct
20 Correct 1813 ms 177280 KB Output is correct
21 Correct 1757 ms 176944 KB Output is correct
22 Correct 1957 ms 176908 KB Output is correct
23 Correct 1868 ms 177000 KB Output is correct
24 Correct 1830 ms 176944 KB Output is correct
25 Correct 1783 ms 176932 KB Output is correct
26 Correct 1900 ms 177108 KB Output is correct
27 Correct 1924 ms 177132 KB Output is correct
28 Correct 1862 ms 177032 KB Output is correct
29 Correct 1961 ms 177212 KB Output is correct
30 Correct 1796 ms 177264 KB Output is correct
31 Correct 1718 ms 177196 KB Output is correct
32 Correct 1680 ms 177280 KB Output is correct
33 Correct 1687 ms 177164 KB Output is correct
34 Correct 1524 ms 176860 KB Output is correct
35 Correct 1546 ms 176840 KB Output is correct
36 Correct 1573 ms 176656 KB Output is correct
37 Correct 1535 ms 176760 KB Output is correct
38 Correct 1549 ms 176968 KB Output is correct
39 Correct 1282 ms 177036 KB Output is correct
40 Correct 714 ms 91112 KB Output is correct
41 Correct 1065 ms 177036 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 2 ms 576 KB Output is correct
4 Correct 1 ms 468 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 2 ms 592 KB Output is correct
7 Correct 3 ms 596 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 1 ms 468 KB Output is correct
10 Correct 2 ms 592 KB Output is correct
11 Correct 12 ms 1884 KB Output is correct
12 Correct 14 ms 2000 KB Output is correct
13 Correct 15 ms 3268 KB Output is correct
14 Correct 24 ms 3272 KB Output is correct
15 Correct 23 ms 3272 KB Output is correct
16 Correct 18 ms 3268 KB Output is correct
17 Correct 11 ms 2028 KB Output is correct
18 Correct 16 ms 3272 KB Output is correct
19 Runtime error 578 ms 262144 KB Execution killed with signal 9
20 Halted 0 ms 0 KB -