This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int, int>
#define pipi pair<pii, pii>
int N = 1<<20;
//20? maybe 18
vector<int> bin(2*N, 1e9);
int query(int curr, int l, int r, int a, int b)
{
if (l >= b || r <= a) return 1e9;
if (a <= l && r <= b) return bin[curr];
int m = (l+r)/2;
int mx = query(curr*2, l, m, a, b);
mx = min(mx, query(curr*2+1, m, r, a, b));
return mx;
}
void update(int i, int x)
{
i+=N;
while (i)
{
bin[i] = min(bin[i], x);
i/=2;
}
}
int main()
{
int n, q;
cin >> n >> q;
vector<pii> books(n);
set<int> pos;
for (int i = 0; i < n; i++)
{
int a;
cin >> a;
books[i] = {a, i};
}
sort(books.begin(), books.end());
vector<int> nleft(n, n);
for (int i = 0; i < n; i++)
{
vector<pii> curr(1, books[i]);
while (i+1 < n && books[i+1].second == books[i].second)
{
i++;
curr.push_back(books[i]);
}
for (pii ele:curr)
{
if (pos.lower_bound(ele.second)==pos.end()) continue;
nleft[ele.second] = *pos.lower_bound(ele.second);
}
for (pii ele:curr)
{
pos.insert(ele.second);
}
}
vector<pipi> queries(q);
for (int i = 0; i < q; i++)
{
int l, r, mood;
cin >> l >> r >> mood;
l--;
//not sure
queries[i] = {{mood, i}, {l, r}};
}
sort(queries.begin(), queries.end(), greater<pipi>());
int last = n-1;
vector<int> sol(q, 0);
for (pipi ele:queries)
{
while (books[last].first>ele.first.first)
{
update(books[last].second, nleft[books[last].second]);
last--;
}
int rr = query(1, 0, N, ele.second.first, ele.second.second);
if (rr >= ele.second.second) sol[ele.first.second] = 1;
}
for (int ele:sol)
{
cout << ele << "\n";
}
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |