Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <string>
- #include <iomanip>
- #include <queue>
- #include <cmath>
- #include <algorithm>
- #include <tuple>
- #include <iomanip>
- #include <stdio.h>
- #include <numeric>
- #include <map>
- #include <bitset>
- #include <set>
- #include <stack>
- #include <queue>
- /*
- #pragma GCC optimize("Ofast,no-stack-protector")
- #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
- #pragma GCC optimize("unroll-loops")
- #pragma GCC optimize("fast-math")
- #pragma GCC optimize("section-anchors")
- #pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
- #pragma GCC optimize("vpt")
- #pragma GCC optimize("rename-registers")
- #pragma GCC optimize("move-loop-invariants")
- #pragma GCC optimize("unswitch-loops")
- #pragma GCC optimize("function-sections")
- #pragma GCC optimize("data-sections")
- #pragma GCC optimize("branch-target-load-optimize")
- #pragma GCC optimize("branch-target-load-optimize2")
- #pragma GCC optimize("btr-bb-exclusive")
- */
- #define int long long
- #define ll long long
- #define ull unsigned long long
- #define all(a) a.begin(), a.end()
- #define pii pair<int, int>
- #define pb push_back
- #define ld long double
- using namespace std;
- //const int INF = 1e13;
- //const int mod = 2600000069;
- //const int p = 179;
- vector<int> a, t;
- void build(int v, int l, int r) {
- if (r - l == 1) {
- t[v] = a[l];
- return;
- }
- int m = (l + r) / 2;
- build(2 * v + 1, l, m);
- build(2 * v + 2, m, r);
- t[v] = max(t[2 * v + 1], t[2 * v + 2]);
- }
- int get_ans(int v, int l, int r, int pos, int val) {
- if (r - l == 1) {
- if (t[v] >= val && l >= pos) {
- return l;
- } else {
- return -2;
- }
- }
- if (r <= pos) {
- return -2;
- }
- int m = (l + r) / 2;
- int first = get_ans(2 * v + 1, l, m, pos, val), second = get_ans(2 * v + 2, m, r, pos, val);
- if (first == -2) {
- return second;
- }
- return first;
- }
- void update(int v, int l, int r, int pos, int val) {
- if (r - l == 1) {
- t[v] = val;
- return;
- }
- int m = (l + r) / 2;
- if (pos < m) {
- update(2 * v + 1, l, m, pos, val);
- } else {
- update(2 * v + 2, m, r, pos, val);
- }
- t[v] = max(t[2 * v + 1], t[2 * v + 2]);
- }
- signed main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- cout.tie(0);
- freopen("nearandmore.in", "r", stdin);
- freopen("nearandmore.out", "w", stdout);
- int n, m;
- cin >> n >> m;
- t.resize(4 * n);
- a.resize(n);
- for (int i = 0; i < n; i++) cin >> a[i];
- build(0, 0, n);
- int type, l, r;
- while (m--) {
- cin >> type >> l >> r;
- if (!type) {
- update(0, 0, n, l - 1, r);
- } else {
- cout << get_ans(0, 0, n, l - 1, r) + 1 << "\n";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement