# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
992781 | n3rm1n | Hedgehog Daniyar and Algorithms (IZhO19_sortbooks) | C++17 | 308 ms | 18128 KiB |
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>
#define endl '\n'
#define ll long long
using namespace std;
const long long MAXN = 1e6+10;
void speed()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
}
long long n, m;
long long a[MAXN], w;
long long l, r, k;
long long go[MAXN];
void read()
{
cin >> n >> m;
for (long long i = 1; i <= n; ++ i)
{
cin >> a[i];
}
}
int marked[5005];
void solve5000()
{
for (long long i = 1; i <= m; ++ i)
{
cin >> l >> r >> k;
vector < pair < long long, long long > > g;
for (long long j = l; j <= r; ++ j)
{
marked[j] = 0;
g.push_back(make_pair(-a[j], j));
}
sort(g.begin(), g.end());
long long cut = r+1, ok = 1;
for (long long j = 0; j < g.size() && ok; ++ j)
{
if(marked[j])continue;
for (long long id = g[j].second+1; id < cut && ok; ++ id)
{
if(a[id] - g[j].first <= k)
{
marked[id] = 1;
continue;
}
else
{
//cout << a[id] << " " << g[j].first << endl;
ok = 0;
}
}
cut = g[j].second;
}
cout << ok << endl;
}
}
void solve13()
{
long long j = 1;
for (long long i = 1; i <= n; ++ i)
{
j = max(j, i);
while(j < n && a[j] <= a[j+1])j ++;
go[i] = j;
}
for (long long i = 1; i <= m; ++ i)
{
cin >> l >> r >> k;
if(go[l] < r)cout << 0 << endl;
else cout << 1 << endl;
}
}
int main()
{
speed();
read();
if(n <= 5000)solve5000();
else solve13();
return 0;
}
Compilation message (stderr)
# | 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... |