Submission #393499

# Submission time Handle Problem Language Result Execution time Memory
393499 2021-04-23T15:54:00 Z SavicS Simple game (IZhO17_game) C++14
0 / 100
5 ms 6732 KB
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>

#define fi first
#define se second
#define pb push_back
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define ff(i,a,b) for(int i=a;i<=b;i++)
#define fb(i,b,a) for(int i=b;i>=a;i--)

using namespace std;
using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn = 100005;
const int inf = 1e9 + 5;

template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

// os.order_of_key(k) the number of elements in the os less than k
// *os.find_by_order(k)  print the k-th smallest number in os(0-based)

int n, q;
int niz[maxn];

const int N = (int)1e6 + 5;
ll dud[N];
void upd(int x, ll val) {
    while(x <= N) {
        dud[x] += val;
        x += x&(-x);
    }
}
ll query(int x) {
    ll sum = 0;
    while(x > 0) {
        sum += dud[x];
        x -= x&(-x);
    }
    return sum;
}

int main() 
{
    ios::sync_with_stdio(false);
    cout.tie(nullptr);
    cin.tie(nullptr);
    cin >> n >> q;
    ff(i,1,n)cin >> niz[i];

    ff(i,1,n - 1) {
        if(niz[i] == niz[i + 1])continue;

        int mn = min(niz[i], niz[i + 1]);
        int mx = max(niz[i], niz[i + 1]);

        upd(mn, 1);
        upd(mx + 1, -1);

    }

    while(q--) {
        int tip;
        cin >> tip;

        if(tip == 1) {
            int pos, val;
            cin >> pos >> val;

            if(pos == n) {
                upd(max(niz[pos - 1], niz[pos]) + 1, 1);
                upd(min(niz[pos - 1], niz[pos]), -1);

                niz[pos] = val;

                upd(max(niz[pos - 1], niz[pos]) + 1, -1);
                upd(min(niz[pos - 1], niz[pos]), 1);

                continue;
            }

            if(pos == 1) {
                upd(max(niz[pos + 1], niz[pos]) + 1, 1);
                upd(min(niz[pos + 1], niz[pos]), -1);

                niz[pos] = val;

                upd(max(niz[pos + 1], niz[pos]) + 1, -1);
                upd(min(niz[pos + 1], niz[pos]), 1);

                continue;
            }

            upd(max(niz[pos - 1], niz[pos]) + 1, 1);
            upd(min(niz[pos - 1], niz[pos]), -1);

            upd(max(niz[pos - 1], niz[pos]) + 1, 1);
            upd(min(niz[pos - 1], niz[pos]), -1);

            niz[pos] = val;

            upd(max(niz[pos + 1], niz[pos]) + 1, -1);
            upd(min(niz[pos + 1], niz[pos]), 1);

            upd(max(niz[pos - 1], niz[pos]) + 1, -1);
            upd(min(niz[pos - 1], niz[pos]), 1);

        }

        if(tip == 2) {
            int H;
            cin >> H;

            cout << query(H) << endl;

        }

    }

    return 0;
}
/**

3 3
1 5 1
2 3
1 1 5
2 3

// probati bojenje sahovski ili slicno

**/


# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Incorrect 5 ms 6732 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Incorrect 5 ms 6732 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Incorrect 5 ms 6732 KB Output isn't correct
3 Halted 0 ms 0 KB -