답안 #674365

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
674365 2022-12-23T19:56:34 Z YENGOYAN Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) C++17
0 / 100
3000 ms 104572 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;
      |                                                    ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 3068 ms 104572 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 144 ms 10904 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 0 ms 212 KB Output is correct
3 Incorrect 1 ms 340 KB Output isn't correct
4 Halted 0 ms 0 KB -