Submission #520155

#TimeUsernameProblemLanguageResultExecution timeMemory
520155shmadHedgehog Daniyar and Algorithms (IZhO19_sortbooks)C++17
0 / 100
534 ms262144 KiB
#pragma GCC optimize("O3", "unroll-loops") // "Ofast" #pragma GCC target("avx2", "bmi", "bmi2", "lzcnt", "popcnt") #include <bits/stdc++.h> #define int long long #define vt vector #define pb push_back #define all(x) (x).begin(), (x).end() #define sz(x) (int)(x).size() #define ff first #define ss second #define dbg(x) cerr << #x << " = " << x << '\n' using namespace std; using ll = long long; using pii = pair<int, int>; using vvi = vt< vt<int> >; const int N = 1e6 + 5, mod = 1e9 + 7, inf = 1e18 + 7, B = 500, LIM = (1ll << 60); const double eps = 1e-6; int n, m, w[N], st[N][21], lg[N]; vt<int> id[1001]; void precalc () { lg[1] = 0; for (int i = 2; i < N; i++) lg[i] = lg[i / 2] + 1; for (int i = 1; i <= n; i++) st[i][0] = w[i]; for (int j = 1; j <= 20; j++) { for (int i = 0; i + (1ll << j) <= n; i++) st[i][j] = max(st[i][j - 1], st[i + (1ll << (j - 1))][j - 1]); } } int get (int l, int r) { int i = lg[r - l + 1]; return max(st[l][i], st[r - (1ll << i) + 1][i]); } int gt (vt<int> a, int x) { auto it = upper_bound(all(a), x - 1); if (it == a.begin()) return -1; return (*--it); } void solve () { cin >> n >> m; vt<int> ans(m + 1, 1); for (int i = 1; i <= n; i++) cin >> w[i]; precalc(); for (int i = 1; i <= n; i++) id[w[i]].pb(i); for (int q = 1; q <= m; q++) { int l, r, k; cin >> l >> r >> k; for (int i = 1; i <= 10; i++) { if (id[i].empty()) continue; int pos = gt(id[i], r - 1); if (pos == -1) continue; if (l <= pos && pos <= r) { int x = get(l, pos); if (x > i && i + x > k) { ans[q] = 0; break; } } } } for (int i = 1; i <= m; i++) cout << ans[i] << '\n'; cout << '\n'; } bool testcases = 0; signed main() { #ifdef ONLINE_JUDGE freopen(".in", "r", stdin); freopen(".out", "w", stdout); #endif cin.tie(0) -> sync_with_stdio(0); int test = 1; if (testcases) cin >> test; for (int cs = 1; cs <= test; cs++) { solve(); } }
#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...