Submission #393501

# Submission time Handle Problem Language Result Execution time Memory
393501 2021-04-23T15:59:00 Z SavicS Simple game (IZhO17_game) C++14
100 / 100
225 ms 9084 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 > 1) {
                upd(min(niz[pos - 1], niz[pos]), -1);
                upd(max(niz[pos - 1], niz[pos]) + 1, 1);
            }

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

            niz[pos] = val;

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

            if(pos < n) {
                upd(min(niz[pos], niz[pos + 1]), 1);
                upd(max(niz[pos], niz[pos + 1]) + 1, -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 Correct 5 ms 6732 KB Output is correct
3 Correct 5 ms 6604 KB Output is correct
4 Correct 4 ms 6604 KB Output is correct
5 Correct 5 ms 6604 KB Output is correct
6 Correct 5 ms 6860 KB Output is correct
7 Correct 3 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 5 ms 6732 KB Output is correct
3 Correct 5 ms 6604 KB Output is correct
4 Correct 4 ms 6604 KB Output is correct
5 Correct 5 ms 6604 KB Output is correct
6 Correct 5 ms 6860 KB Output is correct
7 Correct 3 ms 332 KB Output is correct
8 Correct 187 ms 828 KB Output is correct
9 Correct 225 ms 9064 KB Output is correct
10 Correct 216 ms 9084 KB Output is correct
11 Correct 183 ms 964 KB Output is correct
12 Correct 194 ms 1600 KB Output is correct
13 Correct 196 ms 1348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 5 ms 6732 KB Output is correct
3 Correct 5 ms 6604 KB Output is correct
4 Correct 4 ms 6604 KB Output is correct
5 Correct 5 ms 6604 KB Output is correct
6 Correct 5 ms 6860 KB Output is correct
7 Correct 3 ms 332 KB Output is correct
8 Correct 187 ms 828 KB Output is correct
9 Correct 225 ms 9064 KB Output is correct
10 Correct 216 ms 9084 KB Output is correct
11 Correct 183 ms 964 KB Output is correct
12 Correct 194 ms 1600 KB Output is correct
13 Correct 196 ms 1348 KB Output is correct
14 Correct 169 ms 8936 KB Output is correct
15 Correct 168 ms 8804 KB Output is correct
16 Correct 164 ms 8784 KB Output is correct
17 Correct 160 ms 8760 KB Output is correct
18 Correct 170 ms 8784 KB Output is correct