/*
IN THE NAME OF GOD
*/
#include <bits/stdc++.h>
// #pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
// #pragma GCC optimize("O3")
// #pragma GCC optimize("unroll-loops")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
typedef long double ld;
#define F first
#define S second
#define Mp make_pair
#define pb push_back
#define pf push_front
#define size(x) ((ll)x.size())
#define all(x) (x).begin(),(x).end()
#define kill(x) cout << x << '\n', exit(0);
#define fuck(x) cout << "(" << #x << " , " << x << ")" << endl
#define endl '\n'
const int N = 1e6+23, lg = 20;
ll Mod = 1e9+7; //998244353;
inline ll MOD(ll a, ll mod=Mod) {a%=mod; (a<0)&&(a+=mod); return a;}
inline ll poww(ll a, ll b, ll mod=Mod) {
ll ans = 1;
a=MOD(a, mod);
while (b) {
if (b & 1) ans = MOD(ans*a, mod);
b >>= 1;
a = MOD(a*a, mod);
}
return ans;
}
int n, m, a[N], ans[N], ptr=1;
vector<vector<int>> q[N];
int seg[4*N], lazy[4*N];
inline void pushdown(int ind) {
if(lazy[ind] == 0) return;
seg[ind] += lazy[ind];
if(ind < (1<<lg)) {
lazy[2*ind] += lazy[ind];
lazy[2*ind+1] += lazy[ind];
}
lazy[ind] = 0;
}
void update(int l, int r, int val, int ind=1, int lc=1, int rc=(1<<lg)+1) {
if(lc>=l && rc<=r) {
lazy[ind] += val;
pushdown(ind);
return;
}
pushdown(ind);
if(lc>=r || l>=rc) {
return;
}
int mid = (lc+rc)/2;
update(l, r, val, 2*ind, lc, mid);
update(l, r, val, 2*ind+1, mid, rc);
seg[ind] = max(seg[2*ind], seg[2*ind+1]);
}
int query(int l, int r, int ind=1, int lc=1, int rc=(1<<lg)+1) {
pushdown(ind);
if(lc>=l && rc<=r) {
return seg[ind];
}
if(lc>=r || l>=rc) {
return 0;
}
int mid = (lc+rc)/2;
return max(query(l, r, 2*ind, lc, mid), query(l, r, 2*ind+1, mid, rc));
}
vector<int> st;
int main () {
ios_base::sync_with_stdio(false), cin.tie(0);
cin>>n>>m;
for(int i=1; i<=n; i++) {
cin>>a[i];
}
for(int l,r,k,i=1; i<=m; i++) {
cin>>l>>r>>k;
q[r].pb({l, k, i});
}
for(int i=1; i<=n; i++) {
while(size(st)>0 && a[i] <= a[st.back()]) {
int tmp = st.back();
st.pop_back();
//cout<<tmp<<<<endl;
if(size(st)>0) update(st.back()+1, tmp+1, a[tmp]-a[i]);
else update(1, tmp+1, a[tmp]-a[i]);
}
st.pb(i);
for(auto it : q[i]) {
if(query(it[0], i+1) <= it[1]) {
ans[it[2]] = 1;
}
}
}
for(int i=1; i<=m; i++) cout<<ans[i]<<'\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
33116 KB |
Output is correct |
2 |
Correct |
6 ms |
26968 KB |
Output is correct |
3 |
Incorrect |
8 ms |
33624 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
33116 KB |
Output is correct |
2 |
Correct |
6 ms |
26968 KB |
Output is correct |
3 |
Incorrect |
8 ms |
33624 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1525 ms |
146764 KB |
Output is correct |
2 |
Incorrect |
1544 ms |
147612 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
105 ms |
42576 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
33116 KB |
Output is correct |
2 |
Correct |
6 ms |
26968 KB |
Output is correct |
3 |
Incorrect |
8 ms |
33624 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
7 ms |
33116 KB |
Output is correct |
2 |
Correct |
6 ms |
26968 KB |
Output is correct |
3 |
Incorrect |
8 ms |
33624 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |