Submission #320935

# Submission time Handle Problem Language Result Execution time Memory
320935 2020-11-10T09:53:37 Z lohacho Employment (JOI16_employment) C++14
100 / 100
292 ms 14048 KB
#include <bits/stdc++.h>

using namespace std;

using LL = long long;
const int MOD = (int)1e9 + 7;
const int NS = (int)2e5 + 4;
int N, M;
int a[NS];
int q[NS][3];
vector<int> srt;
struct fenwick{
    vector < int > fenw;
    int N;
    fenwick(){}
    fenwick(int n):N(n){
        fenw.resize(N);
    }
    void push(int x, int val){
        for(int i = x; i < N; i += (i & -i)){
            fenw[i] += val;
        }
    }
    int get(int x){
        int rv = 0;
        for(int i = x; i; i -= (i & -i)){
            rv += fenw[i];
        }
        return rv;
    }
}fen(NS * 2), lfen(NS * 2);

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> N >> M;
    for(int i = 1; i <= N; ++i){
        cin >> a[i];
        srt.push_back(a[i]);
    }
    for(int i = 1; i <= M; ++i){
        cin >> q[i][0] >> q[i][1];
        if(q[i][0] - 1){
            cin >> q[i][2];
            srt.push_back(q[i][2]);
        }
        else{
            srt.push_back(q[i][1]);
        }
    }
    sort(srt.begin(), srt.end());
    srt.erase(unique(srt.begin(), srt.end()), srt.end());
    for(int i = 1; i <= N; ++i){
        a[i] = lower_bound(srt.begin(), srt.end(), a[i]) - srt.begin() + 1;
        fen.push(a[i], 1);
        if(i > 1){
            lfen.push(min(a[i], a[i - 1]), 1);
        }
    }
    for(int i = 1; i <= M; ++i){
        q[i][q[i][0]] = lower_bound(srt.begin(), srt.end(), q[i][q[i][0]]) - srt.begin() + 1;
        if(q[i][0] == 1){
            cout << fen.get(NS * 2 - 1) - fen.get(q[i][1] - 1) - (lfen.get(NS * 2 - 1) - lfen.get(q[i][1] - 1)) << '\n';
        }
        else{
            fen.push(a[q[i][1]], -1);
            if(q[i][1] > 1){
                lfen.push(min(a[q[i][1]], a[q[i][1] - 1]), -1);
            }
            if(q[i][1] < N){
                lfen.push(min(a[q[i][1]], a[q[i][1] + 1]), -1);
            }
            a[q[i][1]] = q[i][2];
            fen.push(a[q[i][1]], 1);
            if(q[i][1] > 1){
                lfen.push(min(a[q[i][1]], a[q[i][1] - 1]), 1);
            }
            if(q[i][1] < N){
                lfen.push(min(a[q[i][1]], a[q[i][1] + 1]), 1);
            }
        }
    }
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3436 KB Output is correct
2 Correct 4 ms 3436 KB Output is correct
3 Correct 3 ms 3436 KB Output is correct
4 Correct 3 ms 3564 KB Output is correct
5 Correct 3 ms 3564 KB Output is correct
6 Correct 3 ms 3564 KB Output is correct
7 Correct 4 ms 3564 KB Output is correct
8 Correct 4 ms 3564 KB Output is correct
9 Correct 4 ms 3564 KB Output is correct
10 Correct 4 ms 3564 KB Output is correct
11 Correct 4 ms 3564 KB Output is correct
12 Correct 5 ms 3564 KB Output is correct
13 Correct 4 ms 3564 KB Output is correct
14 Correct 4 ms 3564 KB Output is correct
15 Correct 4 ms 3564 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 3692 KB Output is correct
2 Correct 5 ms 3692 KB Output is correct
3 Correct 5 ms 3692 KB Output is correct
4 Correct 19 ms 4460 KB Output is correct
5 Correct 32 ms 5224 KB Output is correct
6 Correct 51 ms 6116 KB Output is correct
7 Correct 77 ms 7392 KB Output is correct
8 Correct 98 ms 8416 KB Output is correct
9 Correct 174 ms 11868 KB Output is correct
10 Correct 169 ms 10460 KB Output is correct
11 Correct 199 ms 12764 KB Output is correct
12 Correct 233 ms 13788 KB Output is correct
13 Correct 254 ms 13660 KB Output is correct
14 Correct 230 ms 13656 KB Output is correct
15 Correct 237 ms 13528 KB Output is correct
16 Correct 252 ms 13788 KB Output is correct
17 Correct 243 ms 14048 KB Output is correct
18 Correct 242 ms 13788 KB Output is correct
19 Correct 240 ms 13788 KB Output is correct
20 Correct 271 ms 13916 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 3 ms 3436 KB Output is correct
2 Correct 4 ms 3436 KB Output is correct
3 Correct 3 ms 3436 KB Output is correct
4 Correct 3 ms 3564 KB Output is correct
5 Correct 3 ms 3564 KB Output is correct
6 Correct 3 ms 3564 KB Output is correct
7 Correct 4 ms 3564 KB Output is correct
8 Correct 4 ms 3564 KB Output is correct
9 Correct 4 ms 3564 KB Output is correct
10 Correct 4 ms 3564 KB Output is correct
11 Correct 4 ms 3564 KB Output is correct
12 Correct 5 ms 3564 KB Output is correct
13 Correct 4 ms 3564 KB Output is correct
14 Correct 4 ms 3564 KB Output is correct
15 Correct 4 ms 3564 KB Output is correct
16 Correct 4 ms 3692 KB Output is correct
17 Correct 5 ms 3692 KB Output is correct
18 Correct 5 ms 3692 KB Output is correct
19 Correct 19 ms 4460 KB Output is correct
20 Correct 32 ms 5224 KB Output is correct
21 Correct 51 ms 6116 KB Output is correct
22 Correct 77 ms 7392 KB Output is correct
23 Correct 98 ms 8416 KB Output is correct
24 Correct 174 ms 11868 KB Output is correct
25 Correct 169 ms 10460 KB Output is correct
26 Correct 199 ms 12764 KB Output is correct
27 Correct 233 ms 13788 KB Output is correct
28 Correct 254 ms 13660 KB Output is correct
29 Correct 230 ms 13656 KB Output is correct
30 Correct 237 ms 13528 KB Output is correct
31 Correct 252 ms 13788 KB Output is correct
32 Correct 243 ms 14048 KB Output is correct
33 Correct 242 ms 13788 KB Output is correct
34 Correct 240 ms 13788 KB Output is correct
35 Correct 271 ms 13916 KB Output is correct
36 Correct 4 ms 3564 KB Output is correct
37 Correct 4 ms 3564 KB Output is correct
38 Correct 5 ms 3820 KB Output is correct
39 Correct 18 ms 4460 KB Output is correct
40 Correct 33 ms 5104 KB Output is correct
41 Correct 67 ms 6164 KB Output is correct
42 Correct 81 ms 7268 KB Output is correct
43 Correct 106 ms 8464 KB Output is correct
44 Correct 212 ms 11996 KB Output is correct
45 Correct 158 ms 10852 KB Output is correct
46 Correct 186 ms 11228 KB Output is correct
47 Correct 251 ms 13532 KB Output is correct
48 Correct 269 ms 13872 KB Output is correct
49 Correct 292 ms 13972 KB Output is correct
50 Correct 253 ms 13536 KB Output is correct
51 Correct 288 ms 13920 KB Output is correct
52 Correct 281 ms 13916 KB Output is correct
53 Correct 268 ms 13788 KB Output is correct
54 Correct 268 ms 13788 KB Output is correct
55 Correct 280 ms 13788 KB Output is correct