제출 #81469

#제출 시각아이디문제언어결과실행 시간메모리
81469inomSimple game (IZhO17_game)C++14
49 / 100
428 ms24120 KiB
#include <bits/stdc++.h>
 
#define fin(s) freopen( s, "r", stdin );
#define fout(s) freopen( s, "w", stdout );
 
using namespace std;
 
const int N = 100100;
 
int TN = 1;
 
multiset<pair<int, int> > st;
 
int a[N];
 
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(NULL); cout.tie(NULL);
    /// -------------------------------------
    // fin("game.in"); fout("game.out");
    /// cin >> TN;
    /// -------------------------------------
    int n, m;
    cin >> n >> m;
    if (n <= 1000 && m <= 1000) {
        for (int i = 1; i <= n; i++) {
            cin >> a[i];
        }
        int t, pos, new_val, x;
        for (int i = 1; i <= m; i++) {
            cin >> t;
            if (t == 1) {
                cin >> pos >> new_val;
                a[pos] = new_val;
            }
            else {
                int cnt = 0;
                cin >> x;
                for (int j = 1; j < n; j++) {
                    if ((a[j] <= x && x <= a[j + 1]) || (a[j + 1] <= x && x <= a[j])) {
                        cnt++;
                    }
                }
                cout << cnt << endl;
            }
        }
        return 0;
    }
    else {
    multiset<pair<int, int> > st;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        if (i > 1) {
            st.insert(make_pair(min(a[i], a[i - 1]), 0));
            st.insert(make_pair(max(a[i], a[i - 1]), INT_MAX));
        }
    }
    int t, h;
    for (int i = 1; i <= m; i++) {
        cin >> t;
        if (t == 2) {
            cin >> h;
            st.insert(make_pair(h, i));
        }
    }
    multiset<pair<int, int> > :: iterator it;
    vector<int> ans(N);
    int cnt = 0;
    for (it = st.begin(); it != st.end(); it++) {
        pair<int, int> p = *it;
        if (p.second == 0) cnt++;
        if (p.second > 0 && p.second < INT_MAX) ans[p.second] = cnt;
        if (p.second == INT_MAX) cnt--;
    }
    for (int i = 1; i <= m; i++) {
        cout << ans[i] << endl;
    }
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...