이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long ll;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
}
const int maxn = 1e6 + 10;
int n, m, w[maxn];
int tree[4 * maxn];
void update(int root, int left, int right, int pivot, int val)
{
if (left == right)
{
tree[root] = max(tree[root] , val);
return;
}
int mid = (left + right) / 2;
if (pivot <= mid)
update(root * 2, left, mid, pivot, val);
else
update(root * 2 + 1, mid + 1, right, pivot, val);
tree[root] = max(tree[root * 2], tree[root * 2 + 1]);
}
int query(int root, int left, int right, int qleft, int qright)
{
if (left > qright || right < qleft)
return 0;
if (left >= qleft && right <= qright)
return tree[root];
int mid = (left + right) / 2;
return max(query(root * 2, left, mid, qleft, qright),
query(root * 2 + 1, mid + 1, right, qleft, qright));
}
vector < pair < int, int > > spot[maxn];
struct query_data
{
int idx, r, k;
};
int ans[maxn];
vector < query_data > task[maxn];
void solve()
{
cin >> n >> m;
for (int i = 1; i <= n; i ++)
{
cin >> w[i];
}
stack < int > st;
vector < pair < int, int > > fun;
for (int i = 1; i <= n; i ++)
{
while(!st.empty() && w[st.top()] <= w[i])
st.pop();
if (!st.empty())
{
fun.push_back({st.top(), i});
}
st.push(i);
}
for (pair < int, int > cur : fun)
{
spot[cur.first].push_back({cur.second, w[cur.first] + w[cur.second]});
}
for (int i = 1; i <= m; i ++)
{
query_data cur;
int sp;
cin >> sp >> cur.r >> cur.k;
cur.idx = i;
task[sp].push_back(cur);
}
for (int i = n; i > 0; i --)
{
for (pair < int, int > cur : spot[i])
{
update(1, 1, n, cur.first, cur.second);
}
for (query_data cur : task[i])
{
int mx = query(1, 1, n, i, cur.r);
ans[cur.idx] = (mx <= cur.k);
}
}
for (int i = 1; i <= m; i ++)
cout << ans[i] << endl;
}
int main()
{
speed();
solve();
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... |