답안 #152628

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
152628 2019-09-08T16:00:02 Z andrew Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1744 ms 151064 KB
		
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
 
#pragma GCC optimize("-O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
 
#define fi first
#define se second
#define p_b push_back
#define pll pair<ll,ll>
#define pii pair<int,int>
#define m_p make_pair
#define all(x) x.begin(),x.end()
#define sset ordered_set
#define sqr(x) (x)*(x)
#define pw(x) (1ll << x)
 
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef long double ld;
const ll MAXN = 1123456;
const ll N = 2e5;
mt19937_64 rnd(chrono::system_clock::now().time_since_epoch().count());
 
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
template <typename T> void vout(T s){cout << s << endl;exit(0);}
 
ll ans[MAXN];
 
vector <ll> v[MAXN];
 
struct qry{
    ll l, r, idx, k;
};
 
bool cmp(qry a, qry b){
    if(a.l > b.l)return 1;
    if(a.l < b.l)return 0;
    return (a.idx < b.idx);
}
 
ll t[4 * MAXN];
 
void modify(ll v, ll tl, ll tr, ll pos, ll val){
    if(tl == tr)t[v] = val; else{
        ll tm = (tl + tr) >> 1;
        if(pos <= tm)modify(v << 1, tl, tm, pos, val);
        else modify((v << 1) + 1, tm + 1, tr, pos, val);
        t[v] = max(t[v << 1], t[(v << 1) + 1]);
    }
}
 
ll get(ll v, ll tl, ll tr, ll l, ll r){
    if(l > r)return 0;
    if(tl == l && tr == r)return t[v];
    ll tm = (tl + tr) >> 1;
    return max(get(v << 1, tl, tm, l, min(r, tm)), get((v << 1) + 1, tm + 1, tr, max(l, tm + 1), r));
}
 
int main(){
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
 
    ll n, m;
    cin >> n >> m;
 
    vector <ll> w(n + 1), le(n + 1);
 
    for(int i = 1; i <= n; i++)cin >> w[i];
 
    w[0] = 1e18;
 
    vector <ll> st;
    st.p_b(0);
 
    for(int i = 1; i <= n; i++){
        while(w[st.back()] <= w[i])st.pop_back();
        le[i] = st.back();
        v[le[i]].p_b(i);
        st.p_b(i);
    }
 
    vector <qry> c(m);
 
    ll uk = n;
 
    for(int i = 0; i < m; i++){
        cin >> c[i].l >> c[i].r >> c[i].k;
        c[i].idx = i;
    }
 
    sort(all(c), cmp);
 
    for(auto kek : c){
        while(kek.l < uk){
            for(auto j : v[uk - 1]){
                modify(1, 1, n, j, w[uk - 1] + w[j]);
            }
            uk--;
        }
        ans[kek.idx] = (get(1, 1, n, kek.l, kek.r) <= kek.k);
    }
 
    for(int i = 0; i < m; i++)cout << ans[i] << "\n";
 
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 26744 KB Output is correct
2 Correct 27 ms 26744 KB Output is correct
3 Correct 28 ms 26744 KB Output is correct
4 Correct 28 ms 26744 KB Output is correct
5 Correct 27 ms 26744 KB Output is correct
6 Correct 27 ms 26744 KB Output is correct
7 Correct 27 ms 26872 KB Output is correct
8 Correct 28 ms 26872 KB Output is correct
9 Correct 29 ms 26744 KB Output is correct
10 Correct 28 ms 26744 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 26744 KB Output is correct
2 Correct 27 ms 26744 KB Output is correct
3 Correct 28 ms 26744 KB Output is correct
4 Correct 28 ms 26744 KB Output is correct
5 Correct 27 ms 26744 KB Output is correct
6 Correct 27 ms 26744 KB Output is correct
7 Correct 27 ms 26872 KB Output is correct
8 Correct 28 ms 26872 KB Output is correct
9 Correct 29 ms 26744 KB Output is correct
10 Correct 28 ms 26744 KB Output is correct
11 Correct 30 ms 27000 KB Output is correct
12 Correct 32 ms 27228 KB Output is correct
13 Correct 31 ms 27256 KB Output is correct
14 Correct 33 ms 27384 KB Output is correct
15 Correct 34 ms 27384 KB Output is correct
16 Correct 32 ms 27256 KB Output is correct
17 Correct 31 ms 27256 KB Output is correct
18 Correct 32 ms 27256 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1690 ms 147812 KB Output is correct
2 Correct 1694 ms 147256 KB Output is correct
3 Correct 1683 ms 147732 KB Output is correct
4 Correct 1695 ms 147320 KB Output is correct
5 Correct 1374 ms 120152 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 156 ms 38268 KB Output is correct
2 Correct 150 ms 38236 KB Output is correct
3 Correct 137 ms 35308 KB Output is correct
4 Correct 144 ms 35376 KB Output is correct
5 Correct 150 ms 35312 KB Output is correct
6 Correct 140 ms 35540 KB Output is correct
7 Correct 134 ms 35536 KB Output is correct
8 Correct 128 ms 36644 KB Output is correct
9 Correct 90 ms 32248 KB Output is correct
10 Correct 144 ms 36084 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 26744 KB Output is correct
2 Correct 27 ms 26744 KB Output is correct
3 Correct 28 ms 26744 KB Output is correct
4 Correct 28 ms 26744 KB Output is correct
5 Correct 27 ms 26744 KB Output is correct
6 Correct 27 ms 26744 KB Output is correct
7 Correct 27 ms 26872 KB Output is correct
8 Correct 28 ms 26872 KB Output is correct
9 Correct 29 ms 26744 KB Output is correct
10 Correct 28 ms 26744 KB Output is correct
11 Correct 30 ms 27000 KB Output is correct
12 Correct 32 ms 27228 KB Output is correct
13 Correct 31 ms 27256 KB Output is correct
14 Correct 33 ms 27384 KB Output is correct
15 Correct 34 ms 27384 KB Output is correct
16 Correct 32 ms 27256 KB Output is correct
17 Correct 31 ms 27256 KB Output is correct
18 Correct 32 ms 27256 KB Output is correct
19 Correct 331 ms 49420 KB Output is correct
20 Correct 330 ms 49404 KB Output is correct
21 Correct 304 ms 49400 KB Output is correct
22 Correct 302 ms 49368 KB Output is correct
23 Correct 304 ms 49396 KB Output is correct
24 Correct 262 ms 43368 KB Output is correct
25 Correct 263 ms 43244 KB Output is correct
26 Correct 274 ms 43296 KB Output is correct
27 Correct 273 ms 43352 KB Output is correct
28 Correct 274 ms 43244 KB Output is correct
29 Correct 279 ms 43420 KB Output is correct
30 Correct 280 ms 43372 KB Output is correct
31 Correct 280 ms 43376 KB Output is correct
32 Correct 283 ms 43500 KB Output is correct
33 Correct 281 ms 43412 KB Output is correct
34 Correct 254 ms 43284 KB Output is correct
35 Correct 256 ms 43372 KB Output is correct
36 Correct 254 ms 43364 KB Output is correct
37 Correct 254 ms 43372 KB Output is correct
38 Correct 259 ms 43280 KB Output is correct
39 Correct 261 ms 45176 KB Output is correct
40 Correct 210 ms 42392 KB Output is correct
41 Correct 253 ms 45932 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 26 ms 26744 KB Output is correct
2 Correct 27 ms 26744 KB Output is correct
3 Correct 28 ms 26744 KB Output is correct
4 Correct 28 ms 26744 KB Output is correct
5 Correct 27 ms 26744 KB Output is correct
6 Correct 27 ms 26744 KB Output is correct
7 Correct 27 ms 26872 KB Output is correct
8 Correct 28 ms 26872 KB Output is correct
9 Correct 29 ms 26744 KB Output is correct
10 Correct 28 ms 26744 KB Output is correct
11 Correct 30 ms 27000 KB Output is correct
12 Correct 32 ms 27228 KB Output is correct
13 Correct 31 ms 27256 KB Output is correct
14 Correct 33 ms 27384 KB Output is correct
15 Correct 34 ms 27384 KB Output is correct
16 Correct 32 ms 27256 KB Output is correct
17 Correct 31 ms 27256 KB Output is correct
18 Correct 32 ms 27256 KB Output is correct
19 Correct 1690 ms 147812 KB Output is correct
20 Correct 1694 ms 147256 KB Output is correct
21 Correct 1683 ms 147732 KB Output is correct
22 Correct 1695 ms 147320 KB Output is correct
23 Correct 1374 ms 120152 KB Output is correct
24 Correct 156 ms 38268 KB Output is correct
25 Correct 150 ms 38236 KB Output is correct
26 Correct 137 ms 35308 KB Output is correct
27 Correct 144 ms 35376 KB Output is correct
28 Correct 150 ms 35312 KB Output is correct
29 Correct 140 ms 35540 KB Output is correct
30 Correct 134 ms 35536 KB Output is correct
31 Correct 128 ms 36644 KB Output is correct
32 Correct 90 ms 32248 KB Output is correct
33 Correct 144 ms 36084 KB Output is correct
34 Correct 331 ms 49420 KB Output is correct
35 Correct 330 ms 49404 KB Output is correct
36 Correct 304 ms 49400 KB Output is correct
37 Correct 302 ms 49368 KB Output is correct
38 Correct 304 ms 49396 KB Output is correct
39 Correct 262 ms 43368 KB Output is correct
40 Correct 263 ms 43244 KB Output is correct
41 Correct 274 ms 43296 KB Output is correct
42 Correct 273 ms 43352 KB Output is correct
43 Correct 274 ms 43244 KB Output is correct
44 Correct 279 ms 43420 KB Output is correct
45 Correct 280 ms 43372 KB Output is correct
46 Correct 280 ms 43376 KB Output is correct
47 Correct 283 ms 43500 KB Output is correct
48 Correct 281 ms 43412 KB Output is correct
49 Correct 254 ms 43284 KB Output is correct
50 Correct 256 ms 43372 KB Output is correct
51 Correct 254 ms 43364 KB Output is correct
52 Correct 254 ms 43372 KB Output is correct
53 Correct 259 ms 43280 KB Output is correct
54 Correct 261 ms 45176 KB Output is correct
55 Correct 210 ms 42392 KB Output is correct
56 Correct 253 ms 45932 KB Output is correct
57 Correct 1744 ms 147168 KB Output is correct
58 Correct 1701 ms 147284 KB Output is correct
59 Correct 1666 ms 147092 KB Output is correct
60 Correct 1724 ms 147188 KB Output is correct
61 Correct 1675 ms 151064 KB Output is correct
62 Correct 1689 ms 147248 KB Output is correct
63 Correct 1325 ms 123144 KB Output is correct
64 Correct 1308 ms 123100 KB Output is correct
65 Correct 1421 ms 124968 KB Output is correct
66 Correct 1498 ms 122404 KB Output is correct
67 Correct 1400 ms 121884 KB Output is correct
68 Correct 1396 ms 124204 KB Output is correct
69 Correct 1397 ms 124408 KB Output is correct
70 Correct 1438 ms 120440 KB Output is correct
71 Correct 1404 ms 121004 KB Output is correct
72 Correct 1443 ms 121280 KB Output is correct
73 Correct 1311 ms 121660 KB Output is correct
74 Correct 1309 ms 121160 KB Output is correct
75 Correct 1291 ms 121808 KB Output is correct
76 Correct 1286 ms 119496 KB Output is correct
77 Correct 1285 ms 121688 KB Output is correct
78 Correct 1297 ms 127900 KB Output is correct
79 Correct 1006 ms 106004 KB Output is correct
80 Correct 1290 ms 129744 KB Output is correct