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 ll long long
#define pb push_back
#define task "tests"
#define pll pair<ll, ll>
#define pi pair<ll, pll>
#define fi first
#define se second
using namespace std;
const ll mod = 1e9;
const ll N = 1e6+55;
const int base = 313;
ll n, m, t, k, T, ans, q, tong, c[N], a[N], b[N], h[N], d[N], lab[N], fe[N];
vector<ll> adj[N], kq;
ll pw(ll k, ll n)
{
ll total = 1;
for(; n; n >>= 1)
{
if(n & 1)total = total * k % mod;
k = k * k % mod;
}
return total;
}
void add(ll id, ll x)
{
for(; id; id -= id & -id)fe[id] = max(fe[id], x);
}
ll get(ll id)
{
ll total = 0;
for(; id <= n; id += id & -id)total = max(total, fe[id]);
return total;
}
void sol()
{
cin >> n >> m;
for(int i = 1; i <= n; i ++)cin >> a[i];
for(int i = 1; i <= m; i ++)
{
cin >> b[i] >> c[i] >> h[i];
adj[c[i]].pb(i);
}
for(int i = 1; i <= n; i ++)
{
while(!kq.empty() && a[i] >= a[kq.back()])kq.pop_back();
k = kq.empty() ? 0 : kq.back();
add(k, a[k]+a[i]);
for(ll j: adj[i])
{
d[j] = (get(b[j]) <= h[j]);
}
kq.pb(i);
}
for(int i = 1; i <= m; i ++)cout << d[i] << '\n';
}
int main()
{
if(fopen(task".in", "r"))
{
freopen(task".in", "r", stdin);
freopen(task".out", "w", stdout);
}
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int ntest = 1;
//cin >> ntest;
while(ntest -- > 0)
sol();
}
Compilation message (stderr)
sortbooks.cpp: In function 'int main()':
sortbooks.cpp:62:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
62 | freopen(task".in", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
sortbooks.cpp:63:15: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
63 | freopen(task".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |