답안 #863978

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
863978 2023-10-21T15:33:45 Z wii Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
646 ms 76384 KB
#include <bits/stdc++.h>
using namespace std;

typedef double db;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;

#define X first
#define Y second
#define gcd __gcd
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define bit(i, mask) ((mask) >> (i) & 1)
#define reset(x, val) memset(x, val, sizeof(x))
#define foru(i,a,b) for(int i = (a); i <= (b); ++i)
#define ford(i,a,b) for(int i = (a); i >= (b); --i)
#define FastIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

template<typename T> bool maximize(T &res, const T &val) { if (res < val) { res = val; return true; } return false; }
template<typename T> bool minimize(T &res, const T &val) { if (val < res) { res = val; return true; } return false; }

const ll Linf = 0x3f3f3f3f3f3f3f3f;
const int Inf = 0x3f3f3f3f;
const ll Mod = 1e9 + 7;
const ll Mod2 = ll(1e9) + 9;
const int Lim = 1e6 + 5;
const int inv6 = 166666668;

/// ====*====*====*====*====*====*====*====*====*====*====*====*====*====*====*====*====

const int base = 3;
const int N = 1e6 + 2;
const int K = log2(N);
const int dx[] = {+1, -1, 0, 0};
const int dy[] = {0, 0, +1, -1};
const int block_size = sqrt(2e9) + 2;

using tup = tuple<int, int, int>;

int n, q;
int a[N];

int f[N];
vector<tup> qs[N];

void update(int u, int x) {
    for (; u > 0; u -= u & -u)
        maximize(f[u], x);
}

int get(int u) {
    int ans = 0;
    for (; u <= n; u += u & -u)
        maximize(ans, f[u]);
    return ans;
}

int ans[N];
void solve() {
    cin >> n >> q;
    foru(i, 1, n) cin >> a[i];

    int l, r, k;
    foru(i, 1, q) {
        cin >> l >> r >> k;
        qs[r].emplace_back(l, k, i);
    }

    stack<int> st;
    foru(i, 1, n) {
        while (!st.empty() && a[i] >= a[st.top()]) st.pop();
        if (!st.empty()) update(st.top(), a[i] + a[st.top()]);//, cout << i << " " << st.top() << " " << a[i] + a[st.top()] << "\n";

        for (auto &[l, k, id]: qs[i]) {
            //cout << "? " << l << " " << i << " " << get(l) << "\n";
            ans[id] = get(l) <= k;
        }

        st.push(i);
    }

    foru(i, 1, q) cout << ans[i] << "\n";
}

signed main() {
    FastIO;

    #define task "test"
    if (fopen(task".inp", "r")) {
		freopen(task".inp", "r", stdin);
		freopen(task".out", "w", stdout);
	}

    #ifdef Sieve
        Linear_sieve();
    #endif

    #ifdef Ckn_calc
        precal_nck();
    #endif

    int ntest = 1;
    // cin >> ntest;
    while (ntest--) {
        //cout << "Case " << q << ": " << "\n"; 
        solve();
        cout << "\n";
    }

    return 0;
}

/**  /\_/\
 *  (= ._.)
 *  / >TL \>AC
**/

Compilation message

sortbooks.cpp: In function 'int main()':
sortbooks.cpp:91:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   91 |   freopen(task".inp", "r", stdin);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:92:10: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   92 |   freopen(task".out", "w", stdout);
      |   ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 29184 KB Output is correct
2 Correct 6 ms 29016 KB Output is correct
3 Correct 6 ms 29136 KB Output is correct
4 Correct 6 ms 29192 KB Output is correct
5 Correct 6 ms 29448 KB Output is correct
6 Correct 6 ms 29152 KB Output is correct
7 Correct 6 ms 29020 KB Output is correct
8 Correct 6 ms 29204 KB Output is correct
9 Correct 6 ms 29020 KB Output is correct
10 Correct 6 ms 29120 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 29184 KB Output is correct
2 Correct 6 ms 29016 KB Output is correct
3 Correct 6 ms 29136 KB Output is correct
4 Correct 6 ms 29192 KB Output is correct
5 Correct 6 ms 29448 KB Output is correct
6 Correct 6 ms 29152 KB Output is correct
7 Correct 6 ms 29020 KB Output is correct
8 Correct 6 ms 29204 KB Output is correct
9 Correct 6 ms 29020 KB Output is correct
10 Correct 6 ms 29120 KB Output is correct
11 Correct 7 ms 29276 KB Output is correct
12 Correct 7 ms 29204 KB Output is correct
13 Correct 7 ms 29276 KB Output is correct
14 Correct 8 ms 29488 KB Output is correct
15 Correct 8 ms 29456 KB Output is correct
16 Correct 7 ms 29276 KB Output is correct
17 Correct 8 ms 29532 KB Output is correct
18 Correct 8 ms 29268 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 646 ms 76036 KB Output is correct
2 Correct 643 ms 76384 KB Output is correct
3 Correct 638 ms 76316 KB Output is correct
4 Correct 627 ms 76336 KB Output is correct
5 Correct 591 ms 74320 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 35156 KB Output is correct
2 Correct 44 ms 34640 KB Output is correct
3 Correct 47 ms 34832 KB Output is correct
4 Correct 42 ms 34960 KB Output is correct
5 Correct 42 ms 34904 KB Output is correct
6 Correct 35 ms 34396 KB Output is correct
7 Correct 35 ms 34416 KB Output is correct
8 Correct 40 ms 34628 KB Output is correct
9 Correct 32 ms 34136 KB Output is correct
10 Correct 39 ms 34776 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 29184 KB Output is correct
2 Correct 6 ms 29016 KB Output is correct
3 Correct 6 ms 29136 KB Output is correct
4 Correct 6 ms 29192 KB Output is correct
5 Correct 6 ms 29448 KB Output is correct
6 Correct 6 ms 29152 KB Output is correct
7 Correct 6 ms 29020 KB Output is correct
8 Correct 6 ms 29204 KB Output is correct
9 Correct 6 ms 29020 KB Output is correct
10 Correct 6 ms 29120 KB Output is correct
11 Correct 7 ms 29276 KB Output is correct
12 Correct 7 ms 29204 KB Output is correct
13 Correct 7 ms 29276 KB Output is correct
14 Correct 8 ms 29488 KB Output is correct
15 Correct 8 ms 29456 KB Output is correct
16 Correct 7 ms 29276 KB Output is correct
17 Correct 8 ms 29532 KB Output is correct
18 Correct 8 ms 29268 KB Output is correct
19 Correct 98 ms 39760 KB Output is correct
20 Correct 102 ms 39804 KB Output is correct
21 Correct 92 ms 39300 KB Output is correct
22 Correct 95 ms 39320 KB Output is correct
23 Correct 88 ms 39244 KB Output is correct
24 Correct 80 ms 38996 KB Output is correct
25 Correct 80 ms 38996 KB Output is correct
26 Correct 87 ms 39508 KB Output is correct
27 Correct 87 ms 39252 KB Output is correct
28 Correct 88 ms 39508 KB Output is correct
29 Correct 91 ms 39760 KB Output is correct
30 Correct 101 ms 39680 KB Output is correct
31 Correct 91 ms 39760 KB Output is correct
32 Correct 90 ms 39764 KB Output is correct
33 Correct 96 ms 39684 KB Output is correct
34 Correct 81 ms 38620 KB Output is correct
35 Correct 81 ms 38732 KB Output is correct
36 Correct 74 ms 38276 KB Output is correct
37 Correct 73 ms 38480 KB Output is correct
38 Correct 82 ms 38776 KB Output is correct
39 Correct 89 ms 38644 KB Output is correct
40 Correct 73 ms 38148 KB Output is correct
41 Correct 82 ms 38432 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 29184 KB Output is correct
2 Correct 6 ms 29016 KB Output is correct
3 Correct 6 ms 29136 KB Output is correct
4 Correct 6 ms 29192 KB Output is correct
5 Correct 6 ms 29448 KB Output is correct
6 Correct 6 ms 29152 KB Output is correct
7 Correct 6 ms 29020 KB Output is correct
8 Correct 6 ms 29204 KB Output is correct
9 Correct 6 ms 29020 KB Output is correct
10 Correct 6 ms 29120 KB Output is correct
11 Correct 7 ms 29276 KB Output is correct
12 Correct 7 ms 29204 KB Output is correct
13 Correct 7 ms 29276 KB Output is correct
14 Correct 8 ms 29488 KB Output is correct
15 Correct 8 ms 29456 KB Output is correct
16 Correct 7 ms 29276 KB Output is correct
17 Correct 8 ms 29532 KB Output is correct
18 Correct 8 ms 29268 KB Output is correct
19 Correct 646 ms 76036 KB Output is correct
20 Correct 643 ms 76384 KB Output is correct
21 Correct 638 ms 76316 KB Output is correct
22 Correct 627 ms 76336 KB Output is correct
23 Correct 591 ms 74320 KB Output is correct
24 Correct 44 ms 35156 KB Output is correct
25 Correct 44 ms 34640 KB Output is correct
26 Correct 47 ms 34832 KB Output is correct
27 Correct 42 ms 34960 KB Output is correct
28 Correct 42 ms 34904 KB Output is correct
29 Correct 35 ms 34396 KB Output is correct
30 Correct 35 ms 34416 KB Output is correct
31 Correct 40 ms 34628 KB Output is correct
32 Correct 32 ms 34136 KB Output is correct
33 Correct 39 ms 34776 KB Output is correct
34 Correct 98 ms 39760 KB Output is correct
35 Correct 102 ms 39804 KB Output is correct
36 Correct 92 ms 39300 KB Output is correct
37 Correct 95 ms 39320 KB Output is correct
38 Correct 88 ms 39244 KB Output is correct
39 Correct 80 ms 38996 KB Output is correct
40 Correct 80 ms 38996 KB Output is correct
41 Correct 87 ms 39508 KB Output is correct
42 Correct 87 ms 39252 KB Output is correct
43 Correct 88 ms 39508 KB Output is correct
44 Correct 91 ms 39760 KB Output is correct
45 Correct 101 ms 39680 KB Output is correct
46 Correct 91 ms 39760 KB Output is correct
47 Correct 90 ms 39764 KB Output is correct
48 Correct 96 ms 39684 KB Output is correct
49 Correct 81 ms 38620 KB Output is correct
50 Correct 81 ms 38732 KB Output is correct
51 Correct 74 ms 38276 KB Output is correct
52 Correct 73 ms 38480 KB Output is correct
53 Correct 82 ms 38776 KB Output is correct
54 Correct 89 ms 38644 KB Output is correct
55 Correct 73 ms 38148 KB Output is correct
56 Correct 82 ms 38432 KB Output is correct
57 Correct 607 ms 75844 KB Output is correct
58 Correct 623 ms 75948 KB Output is correct
59 Correct 547 ms 74516 KB Output is correct
60 Correct 577 ms 74812 KB Output is correct
61 Correct 532 ms 74476 KB Output is correct
62 Correct 536 ms 74452 KB Output is correct
63 Correct 403 ms 70112 KB Output is correct
64 Correct 380 ms 69956 KB Output is correct
65 Correct 529 ms 72416 KB Output is correct
66 Correct 555 ms 72244 KB Output is correct
67 Correct 501 ms 63944 KB Output is correct
68 Correct 594 ms 56932 KB Output is correct
69 Correct 588 ms 56824 KB Output is correct
70 Correct 542 ms 56404 KB Output is correct
71 Correct 549 ms 56540 KB Output is correct
72 Correct 559 ms 56676 KB Output is correct
73 Correct 342 ms 51484 KB Output is correct
74 Correct 374 ms 51204 KB Output is correct
75 Correct 342 ms 51540 KB Output is correct
76 Correct 342 ms 51380 KB Output is correct
77 Correct 347 ms 51188 KB Output is correct
78 Correct 569 ms 56064 KB Output is correct
79 Correct 477 ms 64248 KB Output is correct
80 Correct 518 ms 67848 KB Output is correct