답안 #919573

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
919573 2024-02-01T07:18:38 Z manizare Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
2200 ms 240916 KB
#include <bits/stdc++.h>
#pragma GCC optimize ("O3,unroll-loops")
#define pb push_back
#define F first
#define S second 
#define all(a) a.begin(),a.end()
#define pii pair <int,int>
#define PII pair<pii , pii>
#define sz(v) (int)v.size()
#define rep(i , a , b) for(int i=a;i <= (b);i++)
#define per(i , a , b) for(int i=a;i >= (b);i--)
#define deb(x) cout <<#x << " : " << x << "\n" ; 
using namespace std ;   
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int maxn = 1e6+ 10 , maxm = 1e6+10 , lg = 18 , inf= 1e18 , mod = 998244353 ;
int par[maxn] , l[maxn] , ans[maxn ] , a[maxn] , L[maxn] , w[maxn] , mx[4*maxn] ;int n, q ;
vector <int> vec[maxn] , qu[maxn] , up[maxn] ;

int find(int v){
    if(par[v]==0)return v;
    return par[v] = find(par[v]) ;
}
void mrg(int x ,int y){ 
    if(x==y)return ;
    l[y] = l[x] ; 
    par[x] = y ; 
}
void upd(int x ,int w, int p =1 ,int l =1 , int r =n ){
    int mid = (l+r)/2 ,pl = p<< 1, pr =p<<1|1 ;
    if(x > r || l > x){
        return ;
    }
    if(l==r){
        mx[p] = w;
        return ;
    }
    upd(x,w,pl,l,mid);
    upd(x,w,pr,mid+1,r);
    mx[p] = max(mx[pl] , mx[pr]) ;
}
int que(int le, int ri ,int p = 1, int l = 1, int r= n){
    int mid = (l+r)/2 ,pl =p<<1 ,pr = p<<1|1 ;
    if(le > r || l > ri)return -inf;
    if(le <= l && r <= ri){
        return mx[p] ;
    }
    return max(que(le,ri,pl,l,mid),que(le,ri,pr,mid+1,r));
}

signed main(){
	ios_base::sync_with_stdio(false);cin.tie(0);
    cin >> n >> q ;
    vector <int> cm ;
    rep(i , 1, n){
        cin >> a[i] ;
        l[i] = i ;
        cm.pb(a[i]);
    }
    sort(all(cm) );
    cm.resize(unique(all(cm))-cm.begin());
    vector <pii> c ; 
    rep(i , 1, n){
        if(i!=n)c.pb({i,i+1}) ;
        a[i]=lower_bound(all(cm) , a[i]) - cm.begin() ;
        vec[a[i]].pb(i) ;
    }
    a[0] = a[n+1] = inf ;
    rep(i , 0 , sz(cm)-1){
        for(int x : vec[i]){
            if(a[x-1] < a[x]){
                c.pb({l[find(x-1)]-1 , x}) ;
            }
            if(a[x+1] < a[x]){
                c.pb({x,find(x+1)+1}) ;
            }
        }
        for(int x : vec[i]){
            if(a[x-1] <= a[x]){
                mrg(find(x-1) , find(x)) ;
            }
            if(a[x+1] <= a[x]){
                mrg(find(x) , find(x+1)) ;
            }
        }
    }
    vector <pii> c2 ;
    for(pii f : c){
        if(f.F <= 0 || f.S > n || a[f.F] <= a[f.S])continue ;
        up[f.S].pb(f.F) ;
    }
    rep(i , 1, q){
        int r ;
        cin >> L[i] >> r >> w[i]  ; 
        qu[r].pb(i) ;
    }
    rep(i , 1, n){
        for(int x : up[i]){
            upd(x , cm[a[x]] + cm[a[i]]) ;
        }
        for(int id : qu[i]){
            ans[id] = que(L[id] , i) ;
        }
    }
    rep(i ,1 , q){
        if(w[i] >= ans[i]){
            cout << 1 << "\n";
        }else{
            cout << 0 << "\n" ;
        }
    }
}
/*
    
*/

Compilation message

sortbooks.cpp:15:59: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
   15 | const int maxn = 1e6+ 10 , maxm = 1e6+10 , lg = 18 , inf= 1e18 , mod = 998244353 ;
      |                                                           ^~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 82520 KB Output is correct
2 Correct 21 ms 82520 KB Output is correct
3 Correct 21 ms 82520 KB Output is correct
4 Correct 22 ms 82520 KB Output is correct
5 Correct 21 ms 82524 KB Output is correct
6 Correct 23 ms 82520 KB Output is correct
7 Correct 22 ms 82520 KB Output is correct
8 Correct 22 ms 82520 KB Output is correct
9 Correct 21 ms 82524 KB Output is correct
10 Correct 21 ms 82524 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 82520 KB Output is correct
2 Correct 21 ms 82520 KB Output is correct
3 Correct 21 ms 82520 KB Output is correct
4 Correct 22 ms 82520 KB Output is correct
5 Correct 21 ms 82524 KB Output is correct
6 Correct 23 ms 82520 KB Output is correct
7 Correct 22 ms 82520 KB Output is correct
8 Correct 22 ms 82520 KB Output is correct
9 Correct 21 ms 82524 KB Output is correct
10 Correct 21 ms 82524 KB Output is correct
11 Correct 23 ms 82776 KB Output is correct
12 Correct 25 ms 83288 KB Output is correct
13 Correct 27 ms 83032 KB Output is correct
14 Correct 26 ms 83032 KB Output is correct
15 Correct 26 ms 83032 KB Output is correct
16 Correct 26 ms 83032 KB Output is correct
17 Correct 25 ms 83192 KB Output is correct
18 Correct 24 ms 82776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 2135 ms 236676 KB Output is correct
2 Correct 2200 ms 240916 KB Output is correct
3 Correct 2175 ms 239900 KB Output is correct
4 Correct 2170 ms 240728 KB Output is correct
5 Correct 1134 ms 201020 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 112 ms 92356 KB Output is correct
2 Correct 104 ms 91592 KB Output is correct
3 Correct 82 ms 88268 KB Output is correct
4 Correct 84 ms 88420 KB Output is correct
5 Correct 86 ms 88524 KB Output is correct
6 Correct 74 ms 87756 KB Output is correct
7 Correct 66 ms 87552 KB Output is correct
8 Correct 76 ms 89040 KB Output is correct
9 Correct 48 ms 85452 KB Output is correct
10 Correct 75 ms 89032 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 82520 KB Output is correct
2 Correct 21 ms 82520 KB Output is correct
3 Correct 21 ms 82520 KB Output is correct
4 Correct 22 ms 82520 KB Output is correct
5 Correct 21 ms 82524 KB Output is correct
6 Correct 23 ms 82520 KB Output is correct
7 Correct 22 ms 82520 KB Output is correct
8 Correct 22 ms 82520 KB Output is correct
9 Correct 21 ms 82524 KB Output is correct
10 Correct 21 ms 82524 KB Output is correct
11 Correct 23 ms 82776 KB Output is correct
12 Correct 25 ms 83288 KB Output is correct
13 Correct 27 ms 83032 KB Output is correct
14 Correct 26 ms 83032 KB Output is correct
15 Correct 26 ms 83032 KB Output is correct
16 Correct 26 ms 83032 KB Output is correct
17 Correct 25 ms 83192 KB Output is correct
18 Correct 24 ms 82776 KB Output is correct
19 Correct 279 ms 110536 KB Output is correct
20 Correct 278 ms 110372 KB Output is correct
21 Correct 249 ms 109960 KB Output is correct
22 Correct 244 ms 110040 KB Output is correct
23 Correct 257 ms 110532 KB Output is correct
24 Correct 146 ms 101572 KB Output is correct
25 Correct 146 ms 101572 KB Output is correct
26 Correct 168 ms 102300 KB Output is correct
27 Correct 161 ms 102080 KB Output is correct
28 Correct 172 ms 102980 KB Output is correct
29 Correct 195 ms 103360 KB Output is correct
30 Correct 188 ms 104160 KB Output is correct
31 Correct 180 ms 103736 KB Output is correct
32 Correct 178 ms 103876 KB Output is correct
33 Correct 187 ms 104004 KB Output is correct
34 Correct 140 ms 101824 KB Output is correct
35 Correct 137 ms 101720 KB Output is correct
36 Correct 141 ms 101828 KB Output is correct
37 Correct 142 ms 102080 KB Output is correct
38 Correct 139 ms 101308 KB Output is correct
39 Correct 186 ms 105152 KB Output is correct
40 Correct 132 ms 98320 KB Output is correct
41 Correct 142 ms 97084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 27 ms 82520 KB Output is correct
2 Correct 21 ms 82520 KB Output is correct
3 Correct 21 ms 82520 KB Output is correct
4 Correct 22 ms 82520 KB Output is correct
5 Correct 21 ms 82524 KB Output is correct
6 Correct 23 ms 82520 KB Output is correct
7 Correct 22 ms 82520 KB Output is correct
8 Correct 22 ms 82520 KB Output is correct
9 Correct 21 ms 82524 KB Output is correct
10 Correct 21 ms 82524 KB Output is correct
11 Correct 23 ms 82776 KB Output is correct
12 Correct 25 ms 83288 KB Output is correct
13 Correct 27 ms 83032 KB Output is correct
14 Correct 26 ms 83032 KB Output is correct
15 Correct 26 ms 83032 KB Output is correct
16 Correct 26 ms 83032 KB Output is correct
17 Correct 25 ms 83192 KB Output is correct
18 Correct 24 ms 82776 KB Output is correct
19 Correct 2135 ms 236676 KB Output is correct
20 Correct 2200 ms 240916 KB Output is correct
21 Correct 2175 ms 239900 KB Output is correct
22 Correct 2170 ms 240728 KB Output is correct
23 Correct 1134 ms 201020 KB Output is correct
24 Correct 112 ms 92356 KB Output is correct
25 Correct 104 ms 91592 KB Output is correct
26 Correct 82 ms 88268 KB Output is correct
27 Correct 84 ms 88420 KB Output is correct
28 Correct 86 ms 88524 KB Output is correct
29 Correct 74 ms 87756 KB Output is correct
30 Correct 66 ms 87552 KB Output is correct
31 Correct 76 ms 89040 KB Output is correct
32 Correct 48 ms 85452 KB Output is correct
33 Correct 75 ms 89032 KB Output is correct
34 Correct 279 ms 110536 KB Output is correct
35 Correct 278 ms 110372 KB Output is correct
36 Correct 249 ms 109960 KB Output is correct
37 Correct 244 ms 110040 KB Output is correct
38 Correct 257 ms 110532 KB Output is correct
39 Correct 146 ms 101572 KB Output is correct
40 Correct 146 ms 101572 KB Output is correct
41 Correct 168 ms 102300 KB Output is correct
42 Correct 161 ms 102080 KB Output is correct
43 Correct 172 ms 102980 KB Output is correct
44 Correct 195 ms 103360 KB Output is correct
45 Correct 188 ms 104160 KB Output is correct
46 Correct 180 ms 103736 KB Output is correct
47 Correct 178 ms 103876 KB Output is correct
48 Correct 187 ms 104004 KB Output is correct
49 Correct 140 ms 101824 KB Output is correct
50 Correct 137 ms 101720 KB Output is correct
51 Correct 141 ms 101828 KB Output is correct
52 Correct 142 ms 102080 KB Output is correct
53 Correct 139 ms 101308 KB Output is correct
54 Correct 186 ms 105152 KB Output is correct
55 Correct 132 ms 98320 KB Output is correct
56 Correct 142 ms 97084 KB Output is correct
57 Correct 2101 ms 238924 KB Output is correct
58 Correct 2132 ms 238388 KB Output is correct
59 Correct 1829 ms 234156 KB Output is correct
60 Correct 1854 ms 234156 KB Output is correct
61 Correct 1920 ms 234540 KB Output is correct
62 Correct 1971 ms 234208 KB Output is correct
63 Correct 664 ms 188860 KB Output is correct
64 Correct 673 ms 188292 KB Output is correct
65 Correct 1027 ms 195592 KB Output is correct
66 Correct 965 ms 196156 KB Output is correct
67 Correct 990 ms 195760 KB Output is correct
68 Correct 1213 ms 200736 KB Output is correct
69 Correct 1206 ms 200624 KB Output is correct
70 Correct 1141 ms 199448 KB Output is correct
71 Correct 1102 ms 200248 KB Output is correct
72 Correct 1176 ms 200372 KB Output is correct
73 Correct 658 ms 188524 KB Output is correct
74 Correct 650 ms 189284 KB Output is correct
75 Correct 658 ms 188304 KB Output is correct
76 Correct 654 ms 189104 KB Output is correct
77 Correct 660 ms 188696 KB Output is correct
78 Correct 1224 ms 206224 KB Output is correct
79 Correct 759 ms 164024 KB Output is correct
80 Correct 907 ms 161720 KB Output is correct