답안 #78905

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
78905 2018-10-09T14:25:27 Z SpeedOfMagic Sterilizing Spray (JOI15_sterilizing) C++14
0 / 100
774 ms 357072 KB
/** MIT License Copyright (c) 2018 Vasilyev Daniil **/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
#pragma GCC optimize("Ofast")
template<typename T> using v = vector<T>;
template<typename T, typename U>  using hmap = __gnu_pbds::gp_hash_table<T, U>;
#define int long long
typedef long double ld;
typedef string str;
typedef vector<int> vint;
#define rep(a, l, r) for(int a = (l); a < (r); a++)
#define pb push_back
#define fs first
#define sc second
#define sz(a) ((int) a.size())
const long long inf = 4611686018427387903; //2^62 - 1
#if 0  //FileIO
const string fileName = "";
ifstream fin ((fileName == "" ? "input.txt"  : fileName + ".in" ));
ofstream fout((fileName == "" ? "output.txt" : fileName + ".out"));
#define get fin>>
#define put fout<<
#else
#define get cin>>
#define put cout<<
#endif
#define eol put endl
#define check(a) put #a << ": " << a << endl;
void read() {}     template<typename Arg,typename... Args> void read (Arg& arg,Args&... args){get (arg)     ;read(args...) ;}
void print(){}     template<typename Arg,typename... Args> void print(Arg  arg,Args...  args){put (arg)<<" ";print(args...);}
void println(){eol;} template<typename Arg,typename... Args> void println(Arg  arg,Args...  args){put (arg)<<" ";println(args...);}
int getInt(){int a; get a; return a;}
//code goes here
const int N = 131072;
const int LIM = 30;
queue<int> segTree[N * 2];
int lazy[N * 2];
int k;

void processLazy(int cur) {
    if (cur < N) {
        lazy[cur * 2] += lazy[cur];
        lazy[cur * 2 + 1] += lazy[cur];
    }

    for (; lazy[cur] && segTree[cur].front(); lazy[cur]--)
        segTree[cur].pop();

    lazy[cur] = 0;
}

void updateElement(int cur) {
    assert(cur < N);

    queue<int> left = segTree[cur * 2], right = segTree[cur * 2 + 1];
    if (sz(left) > sz(right))
        swap(left, right);

    segTree[cur] = queue<int>();
    while (!left.empty()) {
        segTree[cur].push(left.front() + (right.empty() ? 0 : right.front()));
        left.pop();
        right.pop();
    }
}

void updatePos(int p, int val, int cur = 1, int ll = 1, int rr = N) {
    processLazy(cur);
    if (ll != rr) {
        int mid = (ll + rr) / 2;
        if (p <= mid) {
            updatePos(p, val, cur * 2, ll, mid);
            processLazy(cur * 2 + 1);
        } else {
            processLazy(cur * 2);
            updatePos(p, val, cur * 2 + 1, mid + 1, rr);
        }

        updateElement(cur);
    } else {
        segTree[cur] = queue<int>();
        for (; val && sz(segTree[cur]) <= LIM; val /= k)
            segTree[cur].push(val);

        segTree[cur].push(0);
    }
}

void spray(int l, int r, int cur = 1, int ll = 1, int rr = N) {
    //debug(l, r, cur, ll, rr);
    if (l == ll && r == rr)
        lazy[cur]++;

    processLazy(cur);
    if (l > r || (l == ll && r == rr))
        return;

    int mid = (ll + rr) / 2;
    spray(l, min(r, mid), cur * 2, ll, mid);
    spray(max(l, mid + 1), r, cur * 2 + 1, mid + 1, rr);
}

int query(int l, int r, int cur = 1, int ll = 1, int rr = N) {
    processLazy(cur);
    if (l > r)
        return 0;
    if (l == ll && r == rr)
        return segTree[cur].front();
    int mid = (ll + rr) / 2;
    return query(l, min(r, mid), cur * 2, ll, mid) + query(max(l, mid + 1), r, cur * 2 + 1, mid + 1, rr);
}

void run() {
    int n, q;
    read(n, q, k);

    rep(i, 0, 2 * N)
        segTree[i].push(0);

    rep(i, 0, n)
        updatePos(i + 1, getInt());

    for (; q; q--) {
        int s, t, u;
        read(s, t, u);
        if (s == 1)
            updatePos(t, u);
        else if (s == 2)
            spray(t, u);
        else
            put query(t, u), eol;
    }
}

int32_t main() {srand(time(0)); ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); put fixed; put setprecision(15); run(); return 0;}
# 결과 실행 시간 메모리 Grader output
1 Runtime error 381 ms 351024 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 767 ms 356060 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 481 ms 356060 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 774 ms 357072 KB Execution killed with signal 11 (could be triggered by violating memory limits)
2 Halted 0 ms 0 KB -