이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
//GOAL : BECOME A MASTER
//cf : Mali
//Toktarbek Muhammedali 10B
//Esyk BIL
// #include <bits/stdc++.h>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <fstream>
using namespace std;
#define fast() ios_base::sync_with_stdio(0),cin.tie(0)
#define int long long
#define F first
#define S second
const int N = 1e6 + 10;
const long long INF = 1e18 + 1;
const int mod = 1e9;
using namespace std;
int a[N] , l[N] , r , k[N];
int res[N];
int t[4*N];
vector<int>g[N];
stack<int>st;
int llmax(int a, int b){
if (a > b)return a;
else return b;
}
void build(int v, int tl , int tr){
if (tl == tr){
t[v] = a[tl];
// d[v] = {b[tl] , tl};
return;
}
int md = (tl + tr) / 2;
build(v+v , tl , md) , build(v+v+1 , md+1 , tr);
t[v] = max(t[v+v] , t[v+v+1]);
// d[v] = max(d[v+v] , d[v+v+1]);
}
void u1(int v , int tl , int tr , int pos , int val){
if (tl == tr){
t[v] = val;
return;
}
int md = (tl + tr) / 2;
if (pos <= md)u1(v+v , tl , md , pos , val);
else u1(v+v+1 , md+1 , tr , pos , val);
t[v] = max(t[v+v] , t[v+v+1]);
return;
}
int g1(int v , int tl , int tr , int l , int r){
if (r < tl || tr < l)return 0;
if (l <= tl && tr <= r)return t[v];
int md = (tl + tr) / 2;
return max(g1(v+v , tl , md , l , r) , g1(v+v , md+1 , tr , l , r));
}
void goat(){
int n , q;
cin >> n >> q;
for (int i = 1 ; i <= n ; i ++)cin >> a[i];
for (int i = 1 ; i <= q ; i ++){cin >> l[i] >> r >> k[i];g[r].push_back(i);}
st.push(0);a[0] = INF;
for (int i = 1 ; i <= n ; i ++){
while (a[st.top()] <= a[i])st.pop();
if (st.top() != 0)u1(1 , 1 , n , st.top() , a[st.top()] + a[i]);
for (auto to:g[i])if (g1(1 , 1 , n , l[to] , i) <= k[to])res[to] = 1;
st.push(i);
}
for (int i = 1 ; i <= q ; i ++)cout << res[i] << endl;
}
signed main () {
fast();
// cout << 1;
// freopen("B.in", "r", stdin);
// freopen("B.out", "w", stdout);
// int T;
// cin >> T;
// for (int i = 1 ; i <= T ; i ++){
goat();
// }
}
| # | 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... |