Submission #340208

# Submission time Handle Problem Language Result Execution time Memory
340208 2020-12-27T09:39:18 Z Sprdalo Simple game (IZhO17_game) C++17
0 / 100
7 ms 10604 KB
#include <bits/stdc++.h>

using namespace std;

#define int ll
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pi> vp;
typedef vector<pl> vpl;

//Jako je vazno da uvek bude levo + desno dete
//Ako je potrebno drugacije (zasto?) menjati node operator+
template<int MAXN>
struct segtree{
    
    struct update{
        int x;

        update(int x = 0) : x(x){}

        update& operator+=(const update& other){
            x += other.x;
            return *this;
        }

        update operator+(const update& other){
            update tmp = *this;
            return tmp += other;
        }
    };

    struct node{
        int x, l, r;
        update y;

        node(int x = 0, int l = 0, int r = 0) : x(x), l(l), r(r) {}

        node& operator+= (const node& other){
            x += other.x;
            return *this;
        }

        node& operator+ (const node& other){
            node tmp = *this;
            return tmp += other;
        }

        node& operator+= (const update& other){
            x += other.x * (r - l + 1);
            return *this;
        }

        node& operator+ (const update& other){
            node tmp = *this;
            tmp.r = other.r;
            return tmp += other;
        }
    };

    node a[2 * MAXN];
    update lazy[2 * MAXN];

    void init(){
        for (int i = 1; i <= MAXN; ++i){
            a[i+MAXN-1] = node{0,i,i};
        }
        for (int i = MAXN - 1; i > -1; --i){
            a[i] = a[2 * i] + a[2 * i + 1];
            a[i].l = a[2 * i].l;
            a[i].r = a[2 * i + 1].r;
        }
    }

    void push(int i){
        if (lazy[i].x == 0) return;

        a[i] += lazy[i];
        if (i < MAXN){
            lazy[2 * i] += lazy[i];
            lazy[2 * i + 1] += lazy[i];
        }

        lazy[i] = update{};
    }

    void add(int l, int r, update v, int pos = 1, int L = 1, int R = MAXN){
        push(pos);

        if (l > R || L > r) return;
        if (l <= L && R <= r){
            lazy[pos] += v;
            push(pos);
            return;
        }

        int mid = (L + R) / 2;
        add(l,r,v,2*pos,L,mid);
        add(l,r,v,2*pos+1,mid+1,R);

        a[pos] = a[pos * 2] + a[pos * 2 + 1];
    }

    node get(int l, int r, int pos = 1, int L = 1, int R = MAXN){
        push(pos);
        if (l > R || L > r) return node{};
        if (l <= L && R <= r) return a[pos];

        int mid = (L + R) / 2;
        return get(l,r,2*pos,L,mid) + get(l,r,2*pos+1,mid+1,R);
    }
};
segtree<131072> drvo;

void oduzmi(int a, int b){
    //cout << "BRISI " << a << ' ' << b << endl;
    if (a > b)
        swap(a, b);
    drvo.add(a, b, -1);
}

void dodaj(int a, int b){
    //cout << "DODAJ " << a << ' ' << b << endl;
    if (a > b)
        swap(a, b);
    drvo.add(a,b,1);
}

signed main()
{
    ios_base::sync_with_stdio(false); 
    cin.tie(nullptr); 
    cout.tie(nullptr); 
    cerr.tie(nullptr);    
    drvo.init();

    int n, m;
    cin >> n >> m;

    vi a(n+1);
    for (int i = 1; i <= n; ++i)
        cin >> a[i];

    for (int i = 2; i <= n; ++i){
        dodaj(a[i-1],a[i]);
    }

    for (int e = 0; e < m; ++e){
        int z;
        cin >> z;

        if (z == 2){
            int h;
            cin >> h;
            cout << drvo.get(h, h).x << '\n';
            continue;
        }

        int pos, val;
        cin >> pos >> val;

        if (pos > 1) oduzmi(a[pos], a[pos-1]);
        if (pos < n) oduzmi(a[pos], a[pos+1]);
        a[pos] = val;
        if (pos > 1) dodaj(a[pos], a[pos-1]);
        if (pos < n) dodaj(a[pos], a[pos+1]);
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 10604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 10604 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 7 ms 10604 KB Output isn't correct
2 Halted 0 ms 0 KB -