답안 #941714

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
941714 2024-03-09T10:35:09 Z andrew 단층 (JOI16_ho_t5) C++17
100 / 100
119 ms 13136 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const int N = 2e5;

template <typename T>
struct fenwick_tree{
    vector <T> t;
    fenwick_tree(int n){
        t.resize(n + 1);
        fill(t.begin(), t.end(), 0);
    }

    T f(int pos){
        T res = 0;
        for(int i = pos; i > 0; i -= i & -i) res += t[i];
        return res;
    }
    void u(int pos, T val){
        for(int i = pos; i < (int)t.size(); i += i & -i) t[i] += val;
    }
};

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0);  

    int n, q;
    cin >> n >> q;

    fenwick_tree <long long> x(n), y(n);

    for (int i = 1; i <= n; i++) {
        x.u(i, 1);
        y.u(i, 1);
    }

    vector <int> P(q), D(q), L(q);

    for (int i = 0; i < q; i++) {
        cin >> P[i] >> D[i] >> L[i];
    }

    for (int i = q - 1; i >= 0; i--) {
        if (D[i] == 1) {
            int l = 0, r = n + 1;
            while (r - l > 1) {
                int mid = (l + r) >> 1;
                if (x.f(mid) <= P[i]) l = mid;
                else r = mid;
            }
            y.u(1, -2 * L[i]);
            y.u(l + 1, 2 * L[i]);
        }else {
            int l = 0, r = n + 1;
            while (r - l > 1) {
                int mid = (l + r) >> 1;
                if (y.f(mid) <= P[i]) l = mid;
                else r = mid;
            }            
            x.u(r, 2 * L[i]);
        }
    }

    for (int i = 1; i <= n; i++) {
        cout << (x.f(i) - y.f(i)) / 2 << "\n";
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 416 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 416 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 2 ms 348 KB Output is correct
39 Correct 1 ms 344 KB Output is correct
40 Correct 2 ms 348 KB Output is correct
41 Correct 2 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 2 ms 464 KB Output is correct
45 Correct 3 ms 600 KB Output is correct
46 Correct 1 ms 600 KB Output is correct
47 Correct 2 ms 604 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 1 ms 348 KB Output is correct
50 Correct 1 ms 348 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 1 ms 600 KB Output is correct
53 Correct 2 ms 348 KB Output is correct
54 Correct 2 ms 604 KB Output is correct
55 Correct 2 ms 348 KB Output is correct
56 Correct 1 ms 604 KB Output is correct
57 Correct 2 ms 564 KB Output is correct
58 Correct 2 ms 348 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 1 ms 604 KB Output is correct
61 Correct 1 ms 344 KB Output is correct
62 Correct 2 ms 348 KB Output is correct
63 Correct 1 ms 348 KB Output is correct
64 Correct 1 ms 600 KB Output is correct
65 Correct 1 ms 348 KB Output is correct
66 Correct 1 ms 604 KB Output is correct
67 Correct 1 ms 348 KB Output is correct
68 Correct 1 ms 348 KB Output is correct
69 Correct 1 ms 348 KB Output is correct
70 Correct 1 ms 348 KB Output is correct
71 Correct 1 ms 348 KB Output is correct
72 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 344 KB Output is correct
7 Correct 0 ms 344 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 0 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 0 ms 348 KB Output is correct
12 Correct 0 ms 348 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 1 ms 416 KB Output is correct
15 Correct 0 ms 348 KB Output is correct
16 Correct 0 ms 348 KB Output is correct
17 Correct 0 ms 348 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 0 ms 348 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 0 ms 348 KB Output is correct
23 Correct 1 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 1 ms 348 KB Output is correct
26 Correct 0 ms 348 KB Output is correct
27 Correct 1 ms 348 KB Output is correct
28 Correct 1 ms 348 KB Output is correct
29 Correct 1 ms 348 KB Output is correct
30 Correct 1 ms 348 KB Output is correct
31 Correct 1 ms 348 KB Output is correct
32 Correct 1 ms 348 KB Output is correct
33 Correct 1 ms 344 KB Output is correct
34 Correct 1 ms 348 KB Output is correct
35 Correct 1 ms 348 KB Output is correct
36 Correct 1 ms 348 KB Output is correct
37 Correct 1 ms 348 KB Output is correct
38 Correct 2 ms 348 KB Output is correct
39 Correct 1 ms 344 KB Output is correct
40 Correct 2 ms 348 KB Output is correct
41 Correct 2 ms 348 KB Output is correct
42 Correct 1 ms 348 KB Output is correct
43 Correct 1 ms 348 KB Output is correct
44 Correct 2 ms 464 KB Output is correct
45 Correct 3 ms 600 KB Output is correct
46 Correct 1 ms 600 KB Output is correct
47 Correct 2 ms 604 KB Output is correct
48 Correct 1 ms 348 KB Output is correct
49 Correct 1 ms 348 KB Output is correct
50 Correct 1 ms 348 KB Output is correct
51 Correct 1 ms 348 KB Output is correct
52 Correct 1 ms 600 KB Output is correct
53 Correct 2 ms 348 KB Output is correct
54 Correct 2 ms 604 KB Output is correct
55 Correct 2 ms 348 KB Output is correct
56 Correct 1 ms 604 KB Output is correct
57 Correct 2 ms 564 KB Output is correct
58 Correct 2 ms 348 KB Output is correct
59 Correct 1 ms 348 KB Output is correct
60 Correct 1 ms 604 KB Output is correct
61 Correct 1 ms 344 KB Output is correct
62 Correct 2 ms 348 KB Output is correct
63 Correct 1 ms 348 KB Output is correct
64 Correct 1 ms 600 KB Output is correct
65 Correct 1 ms 348 KB Output is correct
66 Correct 1 ms 604 KB Output is correct
67 Correct 1 ms 348 KB Output is correct
68 Correct 1 ms 348 KB Output is correct
69 Correct 1 ms 348 KB Output is correct
70 Correct 1 ms 348 KB Output is correct
71 Correct 1 ms 348 KB Output is correct
72 Correct 1 ms 348 KB Output is correct
73 Correct 110 ms 9256 KB Output is correct
74 Correct 118 ms 9108 KB Output is correct
75 Correct 111 ms 9360 KB Output is correct
76 Correct 114 ms 9300 KB Output is correct
77 Correct 107 ms 9364 KB Output is correct
78 Correct 108 ms 9300 KB Output is correct
79 Correct 111 ms 9444 KB Output is correct
80 Correct 105 ms 9640 KB Output is correct
81 Correct 97 ms 10064 KB Output is correct
82 Correct 109 ms 10068 KB Output is correct
83 Correct 101 ms 10784 KB Output is correct
84 Correct 106 ms 11092 KB Output is correct
85 Correct 101 ms 10672 KB Output is correct
86 Correct 103 ms 11348 KB Output is correct
87 Correct 105 ms 11980 KB Output is correct
88 Correct 109 ms 13136 KB Output is correct
89 Correct 110 ms 13068 KB Output is correct
90 Correct 96 ms 11608 KB Output is correct
91 Correct 89 ms 8276 KB Output is correct
92 Correct 94 ms 8608 KB Output is correct
93 Correct 111 ms 11964 KB Output is correct
94 Correct 104 ms 9376 KB Output is correct
95 Correct 108 ms 11088 KB Output is correct
96 Correct 96 ms 9276 KB Output is correct
97 Correct 105 ms 10288 KB Output is correct
98 Correct 103 ms 8996 KB Output is correct
99 Correct 106 ms 11092 KB Output is correct
100 Correct 105 ms 9116 KB Output is correct
101 Correct 106 ms 10356 KB Output is correct
102 Correct 110 ms 9252 KB Output is correct
103 Correct 108 ms 10944 KB Output is correct
104 Correct 110 ms 9000 KB Output is correct
105 Correct 97 ms 10584 KB Output is correct
106 Correct 106 ms 9124 KB Output is correct
107 Correct 106 ms 11060 KB Output is correct
108 Correct 105 ms 9124 KB Output is correct
109 Correct 99 ms 10580 KB Output is correct
110 Correct 105 ms 9388 KB Output is correct
111 Correct 107 ms 12304 KB Output is correct
112 Correct 99 ms 9300 KB Output is correct
113 Correct 108 ms 12580 KB Output is correct
114 Correct 106 ms 9300 KB Output is correct
115 Correct 98 ms 9740 KB Output is correct
116 Correct 100 ms 9264 KB Output is correct
117 Correct 119 ms 12428 KB Output is correct
118 Correct 102 ms 9376 KB Output is correct
119 Correct 26 ms 5716 KB Output is correct
120 Correct 23 ms 3984 KB Output is correct