Submission #1270884

#TimeUsernameProblemLanguageResultExecution timeMemory
1270884sunitHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++20
0 / 100
75 ms8128 KiB
#include<bits/stdc++.h>

/*

    --> Solution by chuppy <--

        No eat no fat

*/

#define int long long
#define bl bool
#define db double 
#define fl float 
#define st string 
#define pb push_back
#define pf push_front
#define is insert
#define endl "\n"
#define pba pop_back
#define pfr pop_front
#define ub upper_bound
#define lb lower_bound 
#define fi first 
#define se second 
#define FOR(i, l, r, st) for(int i = l; i <= r; i += st)
#define FOS(i, l, r, sl) for(int i = l; i >= r; i -= sl)
#define mii map<int, int>
#define us unordered_set 
#define pii pair<int, int>
#define vt vector
using namespace std;

const int maxn = 2e5 + 5;

const int mod = 1e9 + 7;

const int oo = 1e18;

/* 

    Oh sorry my fault

        o(* ̄▽ ̄*)ブ
        
    I love copy code !!!

*/

void suncuti() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
}

void fre() {
	if(fopen(".inp", "r")) {
		freopen(".inp", "r", stdin);
		freopen(".out", "w", stdout);
	}
}

int N, M, A[maxn], seg[4 * maxn], Res[maxn];

vt<int> use;

pair<pair<int, int>, pair<int, int>>kt[maxn];

void up(int id, int l, int r, int pos, int val) {
    if(l > pos || r < pos) return;
    if(l == r) {
        seg[id] = val;
        return;
    }
    int mid = (l + r) / 2;
    if(pos <= mid) up(2 * id, l, mid, pos, val);
    else up(2 * id + 1, mid + 1, r, pos, val);
    seg[id] = max(seg[2 * id], seg[2 * id + 1]);
}

int get(int id, int l, int r, int lr, int rr) {
    if(lr > r || rr < l) return 0;
    if(lr <= l && r <= rr) return seg[id];
    int mid = (l + r) / 2;
    return max(get(2 * id, l, mid, lr, rr), get(2 * id + 1, mid + 1, r, lr, rr));
}

main() {
    suncuti();

    cin >> N >> M;

    FOR(i, 1, N, 1) {
        cin >> A[i];

        use.pb(A[i]);
    }

    sort(use.begin(), use.end());

    use.erase(unique(use.begin(), use.end()), use.end());

    FOR(i, 1, N, 1) {
        A[i] = lb(use.begin(), use.end(), A[i]) - use.begin() + 1;
    }

    FOR(i, 1, M, 1) {
        cin >> kt[i].fi.fi >> kt[i].fi.se >> kt[i].se.fi;
        kt[i].se.se = i;
    }

    sort(kt + 1, kt + M + 1, [](auto a, auto b){
        return a.fi.se < b.fi.se;
    });

    stack<int>meo;

    int id = 1;

    FOR(r, 1, N, 1) {
        while(meo.size() && A[meo.top()] <= A[r]) {
            meo.pop();
        }

        if(meo.size()) {
            up(1, 1, N, meo.top(), A[meo.top()] + A[r]);

            // cerr << meo.top() << endl;
        }

        meo.push(r);

        while(r >= kt[id].fi.se && id <= M) {
            Res[kt[id].se.se] = ((get(1, 1, N, kt[id].fi.fi, kt[id].fi.se) <= kt[id].se.fi) ? 1 : 0);

            // cerr << kt[id].se.fi << endl;

            id ++;
        }
    }

    FOR(i, 1, M, 1) {
        cout << Res[i] << endl;
    }
}

Compilation message (stderr)

sortbooks.cpp:88:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   88 | main() {
      | ^~~~
sortbooks.cpp: In function 'void fre()':
sortbooks.cpp:58:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   58 |                 freopen(".inp", "r", stdin);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:59:24: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   59 |                 freopen(".out", "w", stdout);
      |                 ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...