답안 #497444

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
497444 2021-12-23T05:55:38 Z xynex Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1514 ms 166480 KB
/*
* Author: xynex
* Created: 23.12.2021 11:37
* Why am I so stupid? :c
* Slishkom slab
*/

#include <bits/stdc++.h>

// #pragma GCC optimize("inline")
// #pragma GCC optimize("-fgcse,-fgcse-lm")
// #pragma GCC optimize("-ftree-pre,-ftree-vrp")
// #pragma GCC optimize("-ffast-math")
// #pragma GCC optimize("-fipa-sra")
// #pragma GCC optimize("-fpeephole2")
// #pragma GCC optimize("-fsched-spec")
// #pragma GCC optimize("Ofast,no-stack-protector")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC optimize("unroll-loops")

using namespace std;

#define ll long long
#define dl double long
#define ull unsigned long long
#define pr pair
#define vt vector
#define ff first
#define ss second
#define mp make_pair
#define sz(a) (int)a.size()
#define pb push_back
#define pf push_front
#define popB pop_back
#define popF pop_front
#define bit_count __builtin_popcount
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sp(x) fixed << setprecision(x)

template<typename T> T get_rand(T l, T r) {
    random_device rd;
    mt19937 gen(rd());
    return uniform_int_distribution<T>(l, r)(gen);
}

template<typename T> T lcm(T a, T b) { return a * (b / __gcd(a, b)); }

template<class A> void read(vt<A>& v);
template<class A, size_t S> void read(array<A, S>& a);
template<class T> void read(T& x) { cin >> x; }
void read(double& d) { string t; read(t); d = stod(t); }
void read(long double& d) { string t; read(t); d = stold(t); }
template<class H, class... T> void read(H& h, T&... t) { read(h); read(t...); }
template<class A> void read(vt<A>& x) { for (auto& a : x) read(a); }
template<class A, size_t S> void read(array<A, S>& x) { for (auto& a : x) read(a); }

string to_string(char c) { return string(1, c); }
string to_string(bool b) { return b ? "true" : "false"; }
string to_string(const char* s) { return string(s); }
string to_string(string s) { return s; }
string to_string(vt<bool> v) { string res; for (int i = 0; i < sz(v); ++i) res += char('0' + v[i]); return res; }
template<size_t S> string to_string(bitset<S> b) { string res; for (int i = 0; i < S; ++i) res += char('0' + b[i]); return res; }
template<class T> string to_string(T v) { bool f = 1; string res; for (auto x : v) { if (!f) res += ' '; f = 0; res += to_string(x); } return res; }

template<class A> void write(A x) { cout << to_string(x); }
template<class H, class... T> void write(const H& h, const T&... t) { write(h); write(t...); }

void print() { write("\n"); }
template<class H, class... T> void print(const H& h, const T&... t) { write(h); if (sizeof...(t)) write(' '); print(t...); }

void freop(string s) {
    freopen((s + ".in").c_str(), "r", stdin);
    freopen((s + ".out").c_str(), "w", stdout);
}

const int MOD = 1e9 + 7;
const int N = 3e6 + 5;
const ll INF = 9e18;
const int M = 3e3 + 5;
const dl pi = acos(-1);
const dl eps = 1e-12;
const int sq = 700;

int dx[] = {-1, 0, 1, 0};
int dy[] = {0, -1, 0, 1};
/* ll vs int*/

void precalc() {

}

int n;
ll cnt[N], a[N];
void upd(int pos, ll ind, int tl = 0,int  tr = n, int v = 1) {
    if(tl == tr) cnt[v] = ind;
    else {
        int mid = (tr + tl) >> 1;
        if(pos <= mid) upd(pos, ind, tl, mid, v * 2);
        else upd(pos, ind, mid + 1, tr, v * 2 + 1);
        cnt[v] = max(cnt[v * 2], cnt[v * 2 + 1]);
    }
}
ll get(int l, int r, int tl = 0, int tr = n, int v = 1) {
    if(tl > r || tr < l) return 0;
    if(tl >= l && tr <= r) return cnt[v];
    int mid = (tl + tr) >> 1;
    return max(get(l, r, tl, mid, v * 2), get(l, r, mid + 1, tr, v * 2 + 1));
}
vt<int> whr[N];
struct qr {
    int l, r;
    ll x;
} query[N];
int ans[N];
void solve() {
    int q;
    read(n, q);
    for(int i = 1; i <= n; ++i) read(a[i]);
    for(int i = 1; i <= q; ++i) {
        read(query[i].l, query[i].r, query[i].x);
        whr[query[i].r].pb(i);
    }
    vt<ll> st = {0};
    a[0] = MOD;
    for(int i = 1; i <= n; ++i) {
        while(a[st.back()] <= a[i]) st.pop_back();
        //print(i, st);
        upd(st.back(), a[st.back()] + a[i]);
        st.push_back(i);
        while(!whr[i].empty()) {
            qr cur = query[whr[i].back()];
            ll mx = get(cur.l, cur.r);
            if(mx <= cur.x) ans[whr[i].back()] = 1;
            whr[i].pop_back();
        }
    }
    for(int i = 1;i <= q; ++i) print(ans[i]);
}

int main() {
    //freop("");
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    //read(t);
    precalc();
    for (int i = 1; i <= t; ++i) {
        //write("Case #" + to_string(i) + ": ");
        solve();
    }
    return 0;
}

Compilation message

sortbooks.cpp: In function 'void freop(std::string)':
sortbooks.cpp:73:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   73 |     freopen((s + ".in").c_str(), "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:74:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   74 |     freopen((s + ".out").c_str(), "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 70796 KB Output is correct
2 Correct 35 ms 70728 KB Output is correct
3 Correct 38 ms 70732 KB Output is correct
4 Correct 34 ms 70720 KB Output is correct
5 Correct 33 ms 70792 KB Output is correct
6 Correct 32 ms 70724 KB Output is correct
7 Correct 33 ms 70696 KB Output is correct
8 Correct 33 ms 70724 KB Output is correct
9 Correct 37 ms 70780 KB Output is correct
10 Correct 38 ms 70776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 70796 KB Output is correct
2 Correct 35 ms 70728 KB Output is correct
3 Correct 38 ms 70732 KB Output is correct
4 Correct 34 ms 70720 KB Output is correct
5 Correct 33 ms 70792 KB Output is correct
6 Correct 32 ms 70724 KB Output is correct
7 Correct 33 ms 70696 KB Output is correct
8 Correct 33 ms 70724 KB Output is correct
9 Correct 37 ms 70780 KB Output is correct
10 Correct 38 ms 70776 KB Output is correct
11 Correct 38 ms 70912 KB Output is correct
12 Correct 36 ms 71080 KB Output is correct
13 Correct 36 ms 71108 KB Output is correct
14 Correct 38 ms 71180 KB Output is correct
15 Correct 37 ms 71236 KB Output is correct
16 Correct 43 ms 71096 KB Output is correct
17 Correct 36 ms 71128 KB Output is correct
18 Correct 46 ms 71088 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1335 ms 130704 KB Output is correct
2 Correct 1405 ms 130576 KB Output is correct
3 Correct 1442 ms 130612 KB Output is correct
4 Correct 1514 ms 130672 KB Output is correct
5 Correct 1281 ms 118220 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 139 ms 77292 KB Output is correct
2 Correct 120 ms 78580 KB Output is correct
3 Correct 122 ms 77080 KB Output is correct
4 Correct 126 ms 77248 KB Output is correct
5 Correct 113 ms 77252 KB Output is correct
6 Correct 124 ms 75756 KB Output is correct
7 Correct 95 ms 75752 KB Output is correct
8 Correct 112 ms 76892 KB Output is correct
9 Correct 75 ms 74764 KB Output is correct
10 Correct 126 ms 76936 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 70796 KB Output is correct
2 Correct 35 ms 70728 KB Output is correct
3 Correct 38 ms 70732 KB Output is correct
4 Correct 34 ms 70720 KB Output is correct
5 Correct 33 ms 70792 KB Output is correct
6 Correct 32 ms 70724 KB Output is correct
7 Correct 33 ms 70696 KB Output is correct
8 Correct 33 ms 70724 KB Output is correct
9 Correct 37 ms 70780 KB Output is correct
10 Correct 38 ms 70776 KB Output is correct
11 Correct 38 ms 70912 KB Output is correct
12 Correct 36 ms 71080 KB Output is correct
13 Correct 36 ms 71108 KB Output is correct
14 Correct 38 ms 71180 KB Output is correct
15 Correct 37 ms 71236 KB Output is correct
16 Correct 43 ms 71096 KB Output is correct
17 Correct 36 ms 71128 KB Output is correct
18 Correct 46 ms 71088 KB Output is correct
19 Correct 285 ms 87944 KB Output is correct
20 Correct 280 ms 87024 KB Output is correct
21 Correct 233 ms 88184 KB Output is correct
22 Correct 232 ms 88712 KB Output is correct
23 Correct 207 ms 88708 KB Output is correct
24 Correct 232 ms 84328 KB Output is correct
25 Correct 207 ms 84436 KB Output is correct
26 Correct 230 ms 85356 KB Output is correct
27 Correct 216 ms 85232 KB Output is correct
28 Correct 240 ms 85576 KB Output is correct
29 Correct 238 ms 86544 KB Output is correct
30 Correct 251 ms 86540 KB Output is correct
31 Correct 268 ms 86384 KB Output is correct
32 Correct 277 ms 86456 KB Output is correct
33 Correct 263 ms 86368 KB Output is correct
34 Correct 187 ms 84120 KB Output is correct
35 Correct 200 ms 84200 KB Output is correct
36 Correct 213 ms 83900 KB Output is correct
37 Correct 191 ms 83912 KB Output is correct
38 Correct 204 ms 84100 KB Output is correct
39 Correct 227 ms 86144 KB Output is correct
40 Correct 217 ms 83308 KB Output is correct
41 Correct 216 ms 84412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 33 ms 70796 KB Output is correct
2 Correct 35 ms 70728 KB Output is correct
3 Correct 38 ms 70732 KB Output is correct
4 Correct 34 ms 70720 KB Output is correct
5 Correct 33 ms 70792 KB Output is correct
6 Correct 32 ms 70724 KB Output is correct
7 Correct 33 ms 70696 KB Output is correct
8 Correct 33 ms 70724 KB Output is correct
9 Correct 37 ms 70780 KB Output is correct
10 Correct 38 ms 70776 KB Output is correct
11 Correct 38 ms 70912 KB Output is correct
12 Correct 36 ms 71080 KB Output is correct
13 Correct 36 ms 71108 KB Output is correct
14 Correct 38 ms 71180 KB Output is correct
15 Correct 37 ms 71236 KB Output is correct
16 Correct 43 ms 71096 KB Output is correct
17 Correct 36 ms 71128 KB Output is correct
18 Correct 46 ms 71088 KB Output is correct
19 Correct 1335 ms 130704 KB Output is correct
20 Correct 1405 ms 130576 KB Output is correct
21 Correct 1442 ms 130612 KB Output is correct
22 Correct 1514 ms 130672 KB Output is correct
23 Correct 1281 ms 118220 KB Output is correct
24 Correct 139 ms 77292 KB Output is correct
25 Correct 120 ms 78580 KB Output is correct
26 Correct 122 ms 77080 KB Output is correct
27 Correct 126 ms 77248 KB Output is correct
28 Correct 113 ms 77252 KB Output is correct
29 Correct 124 ms 75756 KB Output is correct
30 Correct 95 ms 75752 KB Output is correct
31 Correct 112 ms 76892 KB Output is correct
32 Correct 75 ms 74764 KB Output is correct
33 Correct 126 ms 76936 KB Output is correct
34 Correct 285 ms 87944 KB Output is correct
35 Correct 280 ms 87024 KB Output is correct
36 Correct 233 ms 88184 KB Output is correct
37 Correct 232 ms 88712 KB Output is correct
38 Correct 207 ms 88708 KB Output is correct
39 Correct 232 ms 84328 KB Output is correct
40 Correct 207 ms 84436 KB Output is correct
41 Correct 230 ms 85356 KB Output is correct
42 Correct 216 ms 85232 KB Output is correct
43 Correct 240 ms 85576 KB Output is correct
44 Correct 238 ms 86544 KB Output is correct
45 Correct 251 ms 86540 KB Output is correct
46 Correct 268 ms 86384 KB Output is correct
47 Correct 277 ms 86456 KB Output is correct
48 Correct 263 ms 86368 KB Output is correct
49 Correct 187 ms 84120 KB Output is correct
50 Correct 200 ms 84200 KB Output is correct
51 Correct 213 ms 83900 KB Output is correct
52 Correct 191 ms 83912 KB Output is correct
53 Correct 204 ms 84100 KB Output is correct
54 Correct 227 ms 86144 KB Output is correct
55 Correct 217 ms 83308 KB Output is correct
56 Correct 216 ms 84412 KB Output is correct
57 Correct 1418 ms 166480 KB Output is correct
58 Correct 1378 ms 166376 KB Output is correct
59 Correct 1316 ms 162276 KB Output is correct
60 Correct 1337 ms 162428 KB Output is correct
61 Correct 1298 ms 162264 KB Output is correct
62 Correct 1347 ms 162144 KB Output is correct
63 Correct 940 ms 138124 KB Output is correct
64 Correct 1006 ms 138116 KB Output is correct
65 Correct 1226 ms 145268 KB Output is correct
66 Correct 1200 ms 145252 KB Output is correct
67 Correct 1162 ms 145624 KB Output is correct
68 Correct 1230 ms 150068 KB Output is correct
69 Correct 1336 ms 150096 KB Output is correct
70 Correct 1333 ms 149280 KB Output is correct
71 Correct 1227 ms 149388 KB Output is correct
72 Correct 1264 ms 149276 KB Output is correct
73 Correct 907 ms 136132 KB Output is correct
74 Correct 906 ms 137060 KB Output is correct
75 Correct 875 ms 136132 KB Output is correct
76 Correct 883 ms 136112 KB Output is correct
77 Correct 855 ms 136016 KB Output is correct
78 Correct 1083 ms 147632 KB Output is correct
79 Correct 866 ms 131124 KB Output is correct
80 Correct 1029 ms 139496 KB Output is correct