제출 #535902

#제출 시각아이디문제언어결과실행 시간메모리
535902Danilo21Sterilizing Spray (JOI15_sterilizing)C++14
100 / 100
211 ms5708 KiB
#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define pb push_back
#define fi first
#define se second
#define en '\n'
#define sp ' '
#define tb '\t'
#define ri(n) int n; cin >> n
#define rl(n) ll n; cin >> n
#define rs(s) string s; cin >> s
#define rc(c) char c; cin >> c
#define rv(v) for (auto &x : v) cin >> x
#define pven(v) for (auto x : v) cout << x << en
#define pv(v) for (auto x : v) cout << x << sp; cout << en
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define yes cout << "YES" << en
#define no cout << "NO" << en
#define smin(a, b) a = min(a, b)
#define smax(a, b) a = max(a, b)
#define ssort(a, b) if (a < b) swap(a, b)
#define bitcnt(a) __builtin_popcountll(a)
#define bithigh(a) 63-__builtin_clzll(a)
#define lg bithigh
ll highpow(ll a) { return 1LL << (ll)lg(a); }

using namespace std;

class segtree{
private:
    vector<ll> sum, mx;
    int n;

    void init(int n){
        this->n = n;
        if (highpow(n)^n) this->n = 2*highpow(n);
        this->sum = vector<ll>(2 * this->n, 0);
        this->mx = vector<ll>(2 * this->n, 0);
    }
    void build(int s, int l, int r, ll* arr){
        if (l == r){
            this->sum[s] = this->mx[s] = arr[l];
            return;
        }

        int m = (l + r) / 2;
        build(2*s, l, m, arr);
        build(2*s+1, m+1, r, arr);
        this->sum[s] = this->sum[2*s] + this->sum[2*s+1];
        this->mx[s] = this->mx[2*s] + this->mx[2*s+1];
    }
    void set(int s, int l, int r, int pos, ll x){
        if (l > pos || r < pos) return;
        if (l == r){
            this->sum[s] = this->mx[s] = x;
            return;
        }

        int m = (l + r) / 2;
        set(2*s, l, m, pos, x);
        set(2*s+1, m+1, r, pos, x);
        this->sum[s] = this->sum[2*s] + this->sum[2*s+1];
        this->mx[s] = this->mx[2*s] + this->mx[2*s+1];
    }
    void update(int s, int l, int r, int ul, int ur, ll x){
        if (l > ur || r < ul || !this->mx[s]) return;
        if (l == r){
            this->sum[s] = this->mx[s] = this->sum[s] / x;
            return;
        }

        int m = (l + r) / 2;
        update(2*s, l, m, ul, ur, x);
        update(2*s+1, m+1, r, ul, ur, x);
        this->sum[s] = this->sum[2*s] + this->sum[2*s+1];
        this->mx[s] = this->mx[2*s] + this->mx[2*s+1];
    }
    ll query(int s, int l, int r, int ql, int qr) {
        if (l > qr || r < ql) return 0;
        if (l >= ql && r <= qr) return this->sum[s];

        int m = (l + r) / 2;
        return query(2*s, l, m, ql, qr) + query(2*s+1, m+1, r, ql, qr);
    }
public:
    segtree(int n, ll* arr){ init(n); build(1, 0, this->n-1, arr); }
    void set(int pos, ll x){ set(1, 0, this->n-1, pos, x); }
    void update(int l, int r, ll x){ update(1, 0, this->n-1, l, r, x); }
    ll query(int l, int r){ if (l>r) return 0; return query(1, 0, this->n-1, l, r); }
};

const ll LINF = 4e18;
const int mxN = 2e5+10, INF = 2e9, mod = (1 ? 1e9+7 : 998244353);
ll n, q, m, a[mxN];
segtree* st;

void Solve(){

    cin >> n >> q >> m;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    st = new segtree(n, a);
    while (q--){
        ri(t); ri(l); ri(r);
        l--;
        if (t == 1) st->set(l, r);
        if (t == 2){
            r--;
            if (m^1) st->update(l, r, m);
        }
        if (t == 3){
            r--;
            cout << st->query(l, r) << en;
        }
    }
}

int main(){

    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0); cerr.tie(0);
    cout << setprecision(12) << fixed;
    cerr << setprecision(12) << fixed;
    cerr << "Started!" << endl;

    int t = 1;
    //cin >> t;
    while (t--)
        Solve();

    return 0;
}

컴파일 시 표준 에러 (stderr) 메시지

sterilizing.cpp: In function 'long long int highpow(long long int)':
sterilizing.cpp:26:22: warning: suggest parentheses around '-' inside '<<' [-Wparentheses]
   26 | #define bithigh(a) 63-__builtin_clzll(a)
      |                      ^
sterilizing.cpp:27:12: note: in expansion of macro 'bithigh'
   27 | #define lg bithigh
      |            ^~~~~~~
sterilizing.cpp:28:38: note: in expansion of macro 'lg'
   28 | ll highpow(ll a) { return 1LL << (ll)lg(a); }
      |                                      ^~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...