Submission #519905

# Submission time Handle Problem Language Result Execution time Memory
519905 2022-01-27T14:29:20 Z Be_dos Simple game (IZhO17_game) C++17
0 / 100
10 ms 15948 KB
#include <iostream>
#include <cmath>
#include <cctype>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <deque>
#include <stack>
#include <unordered_set>
#include <sstream>
#include <cstring>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <random>
#include <cfloat>
#include <chrono>
#include <bitset>
#include <complex>
#include <immintrin.h>
#include <cassert>

int32_t* segtree;

void add(int32_t node, int32_t left, int32_t right, int32_t query_left, int32_t query_right, int32_t x) {
    if(left >= query_right || right <= query_left)
        return;
    if(left >= query_left && right <= query_right) {
        segtree[node] += x;
        return;
    }
    int32_t m = (left + right) / 2;
    add(node * 2 + 1, left, m, query_left, query_right, x);
    add(node * 2 + 2, m, right, query_left, query_right, x);
}

int32_t get(int32_t node, int32_t left, int32_t right, int32_t ind) {
    if(right - left == 1)
        return segtree[node];
    int32_t m = (left + right) / 2;
    if(ind >= m)
        return segtree[node] + get(node * 2 + 2, m, right, ind);
    return segtree[node] + get(node * 2 + 1, left, m, ind);
}

int main() {
    int32_t n, m;
    std::cin >> n >> m;

    int32_t* arr = new int32_t[n];
    for(int32_t i = 0; i < n; i++)
        std::cin >> arr[i];

    segtree = new int32_t[4 * 1'000'005];
    for(int32_t i = 0; i < 4 * 1'000'005; i++)
        segtree[i] = 0;
    for(int32_t i = 0; i < n - 1; i++)
        add(0, 0, 1'000'005, std::min(arr[i], arr[i + 1]), std::max(arr[i], arr[i + 1]), 1);

    for(int32_t q = 0; q < m; q++) {
        int32_t type;
        std::cin >> type;

        if(type == 1) {
            int32_t pos, val;
            std::cin >> pos >> val;
            pos--;

            if(pos > 0) {
                add(0, 0, 1'000'005, std::min(arr[pos - 1], arr[pos]), std::max(arr[pos - 1], arr[pos]) + 1, -1);
                add(0, 0, 1'000'005, std::min(arr[pos - 1], val), std::max(arr[pos - 1], val) + 1, 1);
            }
            if(pos < n - 1) {
                add(0, 0, 1'000'005, std::min(arr[pos + 1], arr[pos]), std::max(arr[pos + 1], arr[pos]) + 1, -1);
                add(0, 0, 1'000'005, std::min(arr[pos + 1], val), std::max(arr[pos + 1], val) + 1, 1);
            }
            arr[pos] = val;
        } else {
            int32_t h;
            std::cin >> h;

            std::cout << get(0, 0, 1'000'005, h) << "\n";
        }
    }
    return 0;
}





# Verdict Execution time Memory Grader output
1 Correct 7 ms 15948 KB Output is correct
2 Correct 9 ms 15940 KB Output is correct
3 Incorrect 10 ms 15900 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 15948 KB Output is correct
2 Correct 9 ms 15940 KB Output is correct
3 Incorrect 10 ms 15900 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 7 ms 15948 KB Output is correct
2 Correct 9 ms 15940 KB Output is correct
3 Incorrect 10 ms 15900 KB Output isn't correct
4 Halted 0 ms 0 KB -