Submission #941713

#TimeUsernameProblemLanguageResultExecution timeMemory
941713andrew단층 (JOI16_ho_t5)C++17
18 / 100
2 ms604 KiB
#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 <int> 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;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...