Submission #345492

#TimeUsernameProblemLanguageResultExecution timeMemory
345492Valera_GrinenkoHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++17
100 / 100
1367 ms89564 KiB
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <iomanip>
#include <cmath>
#include <queue>
#include <bitset>
#include <numeric>
#include <array>
#include <cstring>
#include <random>
#include <chrono>
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define make_unique(x) sort(all((x))); (x).resize(unique(all((x))) - (x).begin())
typedef long long ll;
typedef long double ld;
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
// using namespace __gnu_pbds;
// template<class T>
// using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
const int N = 1e6 + 42;
int fw[N], w[N];
bool ans[N];
vector<pair<pair<int, int>, int> > q[N];
void upd(int pos, int x) {
  for(; pos > 0; pos -= (pos & -pos)) fw[pos] = max(fw[pos], x);
}
int get(int pos) {
  int res = 0;
  for(; pos < N; pos += (pos & -pos)) res = max(res, fw[pos]);
  return res;
}
int main() {

  ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

  int n = 0, m = 0;

  cin >> n >> m;

  for(int i = 1; i <= n; i++) cin >> w[i];

  for(int i = 0; i < m; i++) {
    int l, r, k;
    cin >> l >> r >> k;
    q[r].pb(mp(mp(l, k), i));
  }

  vector<int> av;

  for(int i = 1; i <= n; i++) {
    while(!av.empty() && w[av.back()] <= w[i]) av.pop_back();
    if(!av.empty()) upd(av.back(), w[av.back()] + w[i]);
    av.pb(i);
    for(auto& x : q[i]) {
      ans[x.se] = (get(x.fi.fi) <= x.fi.se);
    }
  }

  for(int i = 0; i < m; i++) cout << ans[i] << '\n';

  return 0;
}
/*
5 2
3 5 1 8 2
1 3 6
2 5 3
*/

Compilation message (stderr)

sortbooks.cpp:3: warning: ignoring #pragma GCC optimization [-Wunknown-pragmas]
    3 | #pragma GCC optimization ("unroll-loops")
      |
#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...