답안 #863973

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
863973 2023-10-21T15:21:55 Z wii Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
680 ms 92412 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 29020 KB Output is correct
2 Correct 5 ms 29112 KB Output is correct
3 Correct 6 ms 29020 KB Output is correct
4 Correct 6 ms 29020 KB Output is correct
5 Correct 6 ms 29020 KB Output is correct
6 Correct 5 ms 29020 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 29016 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 29020 KB Output is correct
2 Correct 5 ms 29112 KB Output is correct
3 Correct 6 ms 29020 KB Output is correct
4 Correct 6 ms 29020 KB Output is correct
5 Correct 6 ms 29020 KB Output is correct
6 Correct 5 ms 29020 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 29016 KB Output is correct
11 Correct 7 ms 29276 KB Output is correct
12 Correct 7 ms 29276 KB Output is correct
13 Correct 7 ms 29196 KB Output is correct
14 Correct 8 ms 29484 KB Output is correct
15 Correct 9 ms 29452 KB Output is correct
16 Correct 7 ms 29276 KB Output is correct
17 Correct 8 ms 29204 KB Output is correct
18 Correct 7 ms 29276 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 664 ms 59372 KB Output is correct
2 Correct 620 ms 76268 KB Output is correct
3 Correct 667 ms 76072 KB Output is correct
4 Correct 644 ms 76160 KB Output is correct
5 Correct 616 ms 73996 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 44 ms 33616 KB Output is correct
2 Correct 43 ms 35412 KB Output is correct
3 Correct 52 ms 35424 KB Output is correct
4 Correct 54 ms 35644 KB Output is correct
5 Correct 43 ms 35668 KB Output is correct
6 Correct 35 ms 34900 KB Output is correct
7 Correct 39 ms 35144 KB Output is correct
8 Correct 48 ms 35156 KB Output is correct
9 Correct 33 ms 34412 KB Output is correct
10 Correct 41 ms 35216 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 29020 KB Output is correct
2 Correct 5 ms 29112 KB Output is correct
3 Correct 6 ms 29020 KB Output is correct
4 Correct 6 ms 29020 KB Output is correct
5 Correct 6 ms 29020 KB Output is correct
6 Correct 5 ms 29020 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 29016 KB Output is correct
11 Correct 7 ms 29276 KB Output is correct
12 Correct 7 ms 29276 KB Output is correct
13 Correct 7 ms 29196 KB Output is correct
14 Correct 8 ms 29484 KB Output is correct
15 Correct 9 ms 29452 KB Output is correct
16 Correct 7 ms 29276 KB Output is correct
17 Correct 8 ms 29204 KB Output is correct
18 Correct 7 ms 29276 KB Output is correct
19 Correct 104 ms 42456 KB Output is correct
20 Correct 115 ms 42580 KB Output is correct
21 Correct 89 ms 41928 KB Output is correct
22 Correct 93 ms 41812 KB Output is correct
23 Correct 94 ms 41740 KB Output is correct
24 Correct 80 ms 41660 KB Output is correct
25 Correct 80 ms 41744 KB Output is correct
26 Correct 94 ms 42096 KB Output is correct
27 Correct 85 ms 42064 KB Output is correct
28 Correct 90 ms 42068 KB Output is correct
29 Correct 94 ms 42632 KB Output is correct
30 Correct 105 ms 42468 KB Output is correct
31 Correct 93 ms 42580 KB Output is correct
32 Correct 96 ms 42424 KB Output is correct
33 Correct 92 ms 42576 KB Output is correct
34 Correct 75 ms 41240 KB Output is correct
35 Correct 76 ms 41316 KB Output is correct
36 Correct 74 ms 41040 KB Output is correct
37 Correct 75 ms 41172 KB Output is correct
38 Correct 78 ms 41556 KB Output is correct
39 Correct 94 ms 40860 KB Output is correct
40 Correct 78 ms 39652 KB Output is correct
41 Correct 83 ms 40200 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 29020 KB Output is correct
2 Correct 5 ms 29112 KB Output is correct
3 Correct 6 ms 29020 KB Output is correct
4 Correct 6 ms 29020 KB Output is correct
5 Correct 6 ms 29020 KB Output is correct
6 Correct 5 ms 29020 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 29016 KB Output is correct
11 Correct 7 ms 29276 KB Output is correct
12 Correct 7 ms 29276 KB Output is correct
13 Correct 7 ms 29196 KB Output is correct
14 Correct 8 ms 29484 KB Output is correct
15 Correct 9 ms 29452 KB Output is correct
16 Correct 7 ms 29276 KB Output is correct
17 Correct 8 ms 29204 KB Output is correct
18 Correct 7 ms 29276 KB Output is correct
19 Correct 664 ms 59372 KB Output is correct
20 Correct 620 ms 76268 KB Output is correct
21 Correct 667 ms 76072 KB Output is correct
22 Correct 644 ms 76160 KB Output is correct
23 Correct 616 ms 73996 KB Output is correct
24 Correct 44 ms 33616 KB Output is correct
25 Correct 43 ms 35412 KB Output is correct
26 Correct 52 ms 35424 KB Output is correct
27 Correct 54 ms 35644 KB Output is correct
28 Correct 43 ms 35668 KB Output is correct
29 Correct 35 ms 34900 KB Output is correct
30 Correct 39 ms 35144 KB Output is correct
31 Correct 48 ms 35156 KB Output is correct
32 Correct 33 ms 34412 KB Output is correct
33 Correct 41 ms 35216 KB Output is correct
34 Correct 104 ms 42456 KB Output is correct
35 Correct 115 ms 42580 KB Output is correct
36 Correct 89 ms 41928 KB Output is correct
37 Correct 93 ms 41812 KB Output is correct
38 Correct 94 ms 41740 KB Output is correct
39 Correct 80 ms 41660 KB Output is correct
40 Correct 80 ms 41744 KB Output is correct
41 Correct 94 ms 42096 KB Output is correct
42 Correct 85 ms 42064 KB Output is correct
43 Correct 90 ms 42068 KB Output is correct
44 Correct 94 ms 42632 KB Output is correct
45 Correct 105 ms 42468 KB Output is correct
46 Correct 93 ms 42580 KB Output is correct
47 Correct 96 ms 42424 KB Output is correct
48 Correct 92 ms 42576 KB Output is correct
49 Correct 75 ms 41240 KB Output is correct
50 Correct 76 ms 41316 KB Output is correct
51 Correct 74 ms 41040 KB Output is correct
52 Correct 75 ms 41172 KB Output is correct
53 Correct 78 ms 41556 KB Output is correct
54 Correct 94 ms 40860 KB Output is correct
55 Correct 78 ms 39652 KB Output is correct
56 Correct 83 ms 40200 KB Output is correct
57 Correct 680 ms 92176 KB Output is correct
58 Correct 610 ms 92412 KB Output is correct
59 Correct 605 ms 90864 KB Output is correct
60 Correct 608 ms 91068 KB Output is correct
61 Correct 554 ms 90632 KB Output is correct
62 Correct 588 ms 91108 KB Output is correct
63 Correct 374 ms 85588 KB Output is correct
64 Correct 383 ms 85588 KB Output is correct
65 Correct 547 ms 88704 KB Output is correct
66 Correct 511 ms 88404 KB Output is correct
67 Correct 535 ms 88644 KB Output is correct
68 Correct 603 ms 90340 KB Output is correct
69 Correct 592 ms 90324 KB Output is correct
70 Correct 592 ms 89976 KB Output is correct
71 Correct 587 ms 89688 KB Output is correct
72 Correct 585 ms 89864 KB Output is correct
73 Correct 360 ms 81372 KB Output is correct
74 Correct 362 ms 82256 KB Output is correct
75 Correct 373 ms 81600 KB Output is correct
76 Correct 378 ms 81500 KB Output is correct
77 Correct 353 ms 81124 KB Output is correct
78 Correct 543 ms 83500 KB Output is correct
79 Correct 423 ms 75040 KB Output is correct
80 Correct 537 ms 80520 KB Output is correct