답안 #674367

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
674367 2022-12-23T20:01:52 Z YENGOYAN Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
100 / 100
1025 ms 67740 KB
// eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee //
// 271828___182845__904523__53602__ //
// 87___47____13______52____66__24_ //
// 97___75____72______47____09___36 // 
// 999595_____74______96____69___67 // 
// 62___77____24______07____66__30_ // 
// 35___35____47______59____45713__ //
// eeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee //
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_map>
#include <cmath>
#include <climits>
#include <algorithm>
#include <random>
#include <queue>
#include <deque>
#include <iomanip>
#include <string>
#include <tuple>
#include <bitset>
#include <chrono>
#include <ctime>
#include <fstream>
#include <stack>
#include <cstdio>

using namespace std;
using ll = long long;
const int N = 1e5 + 5;
const ll mod = 1e9 + 7, inf = 1e18;

int n, m, s = 1;
vector<int> seg;

int get(int l, int r, int lx = 0, int rx = s - 1, int u = 0) {
    if (lx >= l && rx <= r) return seg[u];
    if (lx > r || rx < l) return -1;
    int m = (lx + rx) / 2;
    return max(get(l, r, lx, m, 2 * u + 1), get(l, r, m + 1, rx, 2 * u + 2));
}

void modify(int l, int r, int u, int i, int val) {
    if (l == r) {
        seg[u] = max(seg[u], val);
        return;
    }
    int m = (l + r) / 2;
    if (i <= m) modify(l, m, 2 * u + 1, i, val);
    else modify(m + 1, r, 2 * u + 2, i, val);
    seg[u] = max(seg[2 * u + 1], seg[2 * u + 2]);
}

void solve() {
    cin >> n >> m;
    while (s < n) s <<= 1;
    seg.resize(2 * s);
    vector<int> v(n);
    vector<int> lftlrg(n, -1);
    stack<int> st;
    st.push(-1);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
        while (st.size() > 1 && v[st.top()] <= v[i]) {
            st.pop();
        }
        if (st.size() > 1) lftlrg[i] = st.top();
        st.push(i);
    }       
    vector<pair<pair<int, int>, pair<int, int>>> vp;
    map<pair<int, int>, int> mp;
    int idx = 0;
    while (m--) {
        int l, r, k; cin >> l >> r >> k;
        vp.push_back({ {--r, --l}, {k, idx++} });
    }
    //vector<pair<pair<int, int>, int>> vp_ = vp;

    int j = 0;
    vector<bool> res(vp.size());
    sort(vp.begin(), vp.end());
    for (pair<pair<int, int>, pair<int, int>> & i : vp) {
        int r = i.first.first, l = i.first.second, k = i.second.first;
        idx = i.second.second;
        while (j <= r) {
            if (lftlrg[j] != -1) {
                modify(0, s - 1, 0, lftlrg[j], v[j] + v[lftlrg[j]]);
            }
            ++j;
        }
        res[idx] = (get(l, r) <= k);
        //mp[{l, r}] = get(l, r);
    }
    for (int i = 0; i < vp.size(); ++i) cout << res[i] << "\n";
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    //int _; cin >> _; while (_--)
        solve();
}

Compilation message

sortbooks.cpp: In function 'void solve()':
sortbooks.cpp:98:23: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<std::pair<int, int>, std::pair<int, int> > >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   98 |     for (int i = 0; i < vp.size(); ++i) cout << res[i] << "\n";
      |                     ~~^~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 3 ms 468 KB Output is correct
12 Correct 3 ms 468 KB Output is correct
13 Correct 3 ms 468 KB Output is correct
14 Correct 4 ms 596 KB Output is correct
15 Correct 5 ms 596 KB Output is correct
16 Correct 4 ms 596 KB Output is correct
17 Correct 3 ms 596 KB Output is correct
18 Correct 4 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1020 ms 34116 KB Output is correct
2 Correct 991 ms 38652 KB Output is correct
3 Correct 976 ms 35648 KB Output is correct
4 Correct 1002 ms 35436 KB Output is correct
5 Correct 846 ms 35580 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 4304 KB Output is correct
2 Correct 84 ms 4228 KB Output is correct
3 Correct 70 ms 4228 KB Output is correct
4 Correct 69 ms 4304 KB Output is correct
5 Correct 70 ms 4292 KB Output is correct
6 Correct 65 ms 4320 KB Output is correct
7 Correct 66 ms 4304 KB Output is correct
8 Correct 67 ms 4304 KB Output is correct
9 Correct 39 ms 2448 KB Output is correct
10 Correct 65 ms 4296 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 3 ms 468 KB Output is correct
12 Correct 3 ms 468 KB Output is correct
13 Correct 3 ms 468 KB Output is correct
14 Correct 4 ms 596 KB Output is correct
15 Correct 5 ms 596 KB Output is correct
16 Correct 4 ms 596 KB Output is correct
17 Correct 3 ms 596 KB Output is correct
18 Correct 4 ms 596 KB Output is correct
19 Correct 185 ms 8072 KB Output is correct
20 Correct 206 ms 8148 KB Output is correct
21 Correct 180 ms 8132 KB Output is correct
22 Correct 179 ms 8132 KB Output is correct
23 Correct 192 ms 8168 KB Output is correct
24 Correct 155 ms 8156 KB Output is correct
25 Correct 158 ms 8132 KB Output is correct
26 Correct 159 ms 8140 KB Output is correct
27 Correct 166 ms 8152 KB Output is correct
28 Correct 157 ms 8148 KB Output is correct
29 Correct 160 ms 8128 KB Output is correct
30 Correct 159 ms 8060 KB Output is correct
31 Correct 160 ms 8084 KB Output is correct
32 Correct 163 ms 8172 KB Output is correct
33 Correct 159 ms 8132 KB Output is correct
34 Correct 156 ms 8336 KB Output is correct
35 Correct 150 ms 8160 KB Output is correct
36 Correct 146 ms 8096 KB Output is correct
37 Correct 145 ms 8092 KB Output is correct
38 Correct 150 ms 8164 KB Output is correct
39 Correct 148 ms 8072 KB Output is correct
40 Correct 116 ms 6600 KB Output is correct
41 Correct 158 ms 8080 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 212 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 3 ms 468 KB Output is correct
12 Correct 3 ms 468 KB Output is correct
13 Correct 3 ms 468 KB Output is correct
14 Correct 4 ms 596 KB Output is correct
15 Correct 5 ms 596 KB Output is correct
16 Correct 4 ms 596 KB Output is correct
17 Correct 3 ms 596 KB Output is correct
18 Correct 4 ms 596 KB Output is correct
19 Correct 1020 ms 34116 KB Output is correct
20 Correct 991 ms 38652 KB Output is correct
21 Correct 976 ms 35648 KB Output is correct
22 Correct 1002 ms 35436 KB Output is correct
23 Correct 846 ms 35580 KB Output is correct
24 Correct 81 ms 4304 KB Output is correct
25 Correct 84 ms 4228 KB Output is correct
26 Correct 70 ms 4228 KB Output is correct
27 Correct 69 ms 4304 KB Output is correct
28 Correct 70 ms 4292 KB Output is correct
29 Correct 65 ms 4320 KB Output is correct
30 Correct 66 ms 4304 KB Output is correct
31 Correct 67 ms 4304 KB Output is correct
32 Correct 39 ms 2448 KB Output is correct
33 Correct 65 ms 4296 KB Output is correct
34 Correct 185 ms 8072 KB Output is correct
35 Correct 206 ms 8148 KB Output is correct
36 Correct 180 ms 8132 KB Output is correct
37 Correct 179 ms 8132 KB Output is correct
38 Correct 192 ms 8168 KB Output is correct
39 Correct 155 ms 8156 KB Output is correct
40 Correct 158 ms 8132 KB Output is correct
41 Correct 159 ms 8140 KB Output is correct
42 Correct 166 ms 8152 KB Output is correct
43 Correct 157 ms 8148 KB Output is correct
44 Correct 160 ms 8128 KB Output is correct
45 Correct 159 ms 8060 KB Output is correct
46 Correct 160 ms 8084 KB Output is correct
47 Correct 163 ms 8172 KB Output is correct
48 Correct 159 ms 8132 KB Output is correct
49 Correct 156 ms 8336 KB Output is correct
50 Correct 150 ms 8160 KB Output is correct
51 Correct 146 ms 8096 KB Output is correct
52 Correct 145 ms 8092 KB Output is correct
53 Correct 150 ms 8164 KB Output is correct
54 Correct 148 ms 8072 KB Output is correct
55 Correct 116 ms 6600 KB Output is correct
56 Correct 158 ms 8080 KB Output is correct
57 Correct 1022 ms 67740 KB Output is correct
58 Correct 1008 ms 67608 KB Output is correct
59 Correct 1025 ms 67520 KB Output is correct
60 Correct 1024 ms 67564 KB Output is correct
61 Correct 993 ms 67652 KB Output is correct
62 Correct 1022 ms 67612 KB Output is correct
63 Correct 809 ms 65672 KB Output is correct
64 Correct 814 ms 65776 KB Output is correct
65 Correct 855 ms 67480 KB Output is correct
66 Correct 864 ms 67504 KB Output is correct
67 Correct 867 ms 67576 KB Output is correct
68 Correct 890 ms 67704 KB Output is correct
69 Correct 895 ms 67604 KB Output is correct
70 Correct 891 ms 67552 KB Output is correct
71 Correct 871 ms 67500 KB Output is correct
72 Correct 875 ms 67548 KB Output is correct
73 Correct 789 ms 64196 KB Output is correct
74 Correct 810 ms 65120 KB Output is correct
75 Correct 787 ms 64112 KB Output is correct
76 Correct 772 ms 64084 KB Output is correct
77 Correct 779 ms 64088 KB Output is correct
78 Correct 825 ms 61396 KB Output is correct
79 Correct 604 ms 48832 KB Output is correct
80 Correct 810 ms 58640 KB Output is correct