Submission #674366

# Submission time Handle Problem Language Result Execution time Memory
674366 2022-12-23T19:58:56 Z YENGOYAN Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
64 / 100
3000 ms 104416 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>, int>> vp;
    map<pair<int, int>, int> mp;
    while (m--) {
        int l, r, k; cin >> l >> r >> k;
        vp.push_back({ {--r, --l}, k });
    }
    vector<pair<pair<int, int>, int>> vp_ = vp;

    int j = 0;
    sort(vp.begin(), vp.end());
    for (pair<pair<int, int>, int> & i : vp) {
        int r = i.first.first, l = i.first.second, k = i.second;
        while (j <= r) {
            if (lftlrg[j] != -1) {
                modify(0, s - 1, 0, lftlrg[j], v[j] + v[lftlrg[j]]);
            }
            ++j;
        }
        mp[{l, r}] = get(l, r);
    }
    for (pair<pair<int, int>, int>& i : vp_) {
        int r = i.first.first, l = i.first.second, k = i.second;
        cout << (mp[{l, r}] <= k) << "\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:85:52: warning: unused variable 'k' [-Wunused-variable]
   85 |         int r = i.first.first, l = i.first.second, k = i.second;
      |                                                    ^
# Verdict Execution time Memory 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 1 ms 320 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
# Verdict Execution time Memory 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 1 ms 320 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 3 ms 676 KB Output is correct
12 Correct 4 ms 724 KB Output is correct
13 Correct 4 ms 720 KB Output is correct
14 Correct 7 ms 976 KB Output is correct
15 Correct 6 ms 924 KB Output is correct
16 Correct 5 ms 852 KB Output is correct
17 Correct 4 ms 740 KB Output is correct
18 Correct 5 ms 724 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 3068 ms 104416 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 150 ms 10820 KB Output is correct
2 Correct 145 ms 12776 KB Output is correct
3 Correct 140 ms 12904 KB Output is correct
4 Correct 136 ms 12868 KB Output is correct
5 Correct 153 ms 12852 KB Output is correct
6 Correct 140 ms 12456 KB Output is correct
7 Correct 125 ms 12396 KB Output is correct
8 Correct 104 ms 10500 KB Output is correct
9 Correct 66 ms 6516 KB Output is correct
10 Correct 104 ms 10500 KB Output is correct
# Verdict Execution time Memory 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 1 ms 320 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 3 ms 676 KB Output is correct
12 Correct 4 ms 724 KB Output is correct
13 Correct 4 ms 720 KB Output is correct
14 Correct 7 ms 976 KB Output is correct
15 Correct 6 ms 924 KB Output is correct
16 Correct 5 ms 852 KB Output is correct
17 Correct 4 ms 740 KB Output is correct
18 Correct 5 ms 724 KB Output is correct
19 Correct 421 ms 26680 KB Output is correct
20 Correct 366 ms 26644 KB Output is correct
21 Correct 423 ms 26776 KB Output is correct
22 Correct 388 ms 26468 KB Output is correct
23 Correct 388 ms 26492 KB Output is correct
24 Correct 360 ms 26384 KB Output is correct
25 Correct 363 ms 26256 KB Output is correct
26 Correct 381 ms 26576 KB Output is correct
27 Correct 368 ms 26560 KB Output is correct
28 Correct 371 ms 26732 KB Output is correct
29 Correct 367 ms 26596 KB Output is correct
30 Correct 380 ms 26660 KB Output is correct
31 Correct 399 ms 26660 KB Output is correct
32 Correct 368 ms 26652 KB Output is correct
33 Correct 405 ms 26648 KB Output is correct
34 Correct 322 ms 25036 KB Output is correct
35 Correct 329 ms 25152 KB Output is correct
36 Correct 320 ms 24924 KB Output is correct
37 Correct 321 ms 24856 KB Output is correct
38 Correct 317 ms 25124 KB Output is correct
39 Correct 281 ms 22036 KB Output is correct
40 Correct 183 ms 16752 KB Output is correct
41 Correct 271 ms 20560 KB Output is correct
# Verdict Execution time Memory 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 1 ms 320 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 328 KB Output is correct
8 Correct 1 ms 340 KB Output is correct
9 Correct 1 ms 324 KB Output is correct
10 Correct 1 ms 340 KB Output is correct
11 Correct 3 ms 676 KB Output is correct
12 Correct 4 ms 724 KB Output is correct
13 Correct 4 ms 720 KB Output is correct
14 Correct 7 ms 976 KB Output is correct
15 Correct 6 ms 924 KB Output is correct
16 Correct 5 ms 852 KB Output is correct
17 Correct 4 ms 740 KB Output is correct
18 Correct 5 ms 724 KB Output is correct
19 Execution timed out 3068 ms 104416 KB Time limit exceeded
20 Halted 0 ms 0 KB -