답안 #170223

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
170223 2019-12-24T09:37:33 Z theboatman Simple game (IZhO17_game) C++11
22 / 100
1000 ms 200976 KB
#include <bits/stdc++.h>

#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>

#define y1 theboatman
#define make_struct(args...) {args}

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
template <typename T> using ordset = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const long long INF = ll(1e18) + 10;
const int inf = int(1e9) + 10;
const int N = int(1e6) + 10;

struct Tree {
    int n, timer;
    vector <ordset <pair <int, int> > > t;

    inline void init(int _n) {
        n = _n;
        timer = 0;

        t.resize(n + 1);
    }

    inline void add(int pos, int val) {
        for(int i = pos; i <= n; i += i & -i) {
            t[i].insert({val, timer++});
        }
    }

    inline void del(int pos, int val) {
        for(int i = pos; i <= n; i += i & -i) {
            t[i].erase(t[i].lower_bound({val, 0}));
        }
    }

    inline int get(int pos, int r) {
        int ans = 0;
        for(int i = pos; i > 0; i -= i & -i) {
            ans += t[i].size() - t[i].order_of_key({r + 1, 0});
        }

        return ans;
    }
};

void brute() {
    int n, m;
    cin >> n >> m;

    vector <int> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }

    while(m--) {
        int type;
        cin >> type;

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

            a[pos] = val;
        }
        else {
            int x;
            cin >> x;

            int ans = 0;
            for(auto i : a) {
                if (i == x) {
                    ans++;
                }
            }

            for(int i = 1; i < n; i++) {
                int l = min(a[i], a[i - 1]);
                int r = max(a[i], a[i - 1]);

                if (l < x && x < r) {
                    ans++;
                }
            }

            cout << ans << "\n";
        }
    }
}

int main() {
    //freopen("game.in", "r", stdin);
    //freopen("game.out", "w", stdout);

    cin.tie(0);
    ios::sync_with_stdio(0);

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

    vector <int> a(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }

    Tree osu;
    osu.init(N);

    for(int i = 1; i < n; i++) {
        osu.add(min(a[i], a[i - 1]), max(a[i], a[i - 1]));
    }

    vector <int> cnt(N);
    for(int i = 0; i < n; i++) {
        cnt[a[i]]++;
    }

    for(int iq = 0; iq < m; iq++) {
        int type;
        cin >> type;

        if (type == 2) {
            int x;
            cin >> x;

            cout << cnt[x] + osu.get(x - 1, x) << "\n";
        }
        else {
            int pos, val;
            cin >> pos >> val;
            pos--;

            if (pos > 0) {
                osu.del(min(a[pos], a[pos - 1]), max(a[pos], a[pos - 1]));
            }

            if (pos < n - 1) {
                osu.del(min(a[pos], a[pos + 1]), max(a[pos], a[pos + 1]));
            }

            cnt[a[pos]]--;
            a[pos] = val;
            cnt[a[pos]]++;

            if (pos > 0) {
                osu.add(min(a[pos], a[pos - 1]), max(a[pos], a[pos - 1]));
            }

            if (pos < n - 1) {
                osu.add(min(a[pos], a[pos + 1]), max(a[pos], a[pos + 1]));
            }
        }
    }

    return 0;
}

/*
*/
# 결과 실행 시간 메모리 Grader output
1 Correct 125 ms 98168 KB Output is correct
2 Correct 144 ms 98908 KB Output is correct
3 Correct 142 ms 98824 KB Output is correct
4 Correct 154 ms 98856 KB Output is correct
5 Correct 134 ms 98908 KB Output is correct
6 Correct 134 ms 98908 KB Output is correct
7 Correct 134 ms 99412 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 125 ms 98168 KB Output is correct
2 Correct 144 ms 98908 KB Output is correct
3 Correct 142 ms 98824 KB Output is correct
4 Correct 154 ms 98856 KB Output is correct
5 Correct 134 ms 98908 KB Output is correct
6 Correct 134 ms 98908 KB Output is correct
7 Correct 134 ms 99412 KB Output is correct
8 Execution timed out 1086 ms 200976 KB Time limit exceeded
9 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 125 ms 98168 KB Output is correct
2 Correct 144 ms 98908 KB Output is correct
3 Correct 142 ms 98824 KB Output is correct
4 Correct 154 ms 98856 KB Output is correct
5 Correct 134 ms 98908 KB Output is correct
6 Correct 134 ms 98908 KB Output is correct
7 Correct 134 ms 99412 KB Output is correct
8 Execution timed out 1086 ms 200976 KB Time limit exceeded
9 Halted 0 ms 0 KB -