Submission #955541

# Submission time Handle Problem Language Result Execution time Memory
955541 2024-03-30T22:23:28 Z AliMark71 Sterilizing Spray (JOI15_sterilizing) C++17
Compilation error
0 ms 0 KB
//
//  main.cpp
//  GeneralCompetitiveProgramming
//
//  Created by Ali AlSalman on 12/07/2023.
//

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <optional>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <cmath>
#include <climits>

#define endl '\n'

using namespace std;


class SegmentTree {
private:
    int _offset, _back, _sth;
    vector<long long> _data;
    set<int> _non_zero;
    
    long long _query(int v, int qlo, int qhi, int lo, int hi) {
        if (qlo <= lo && hi <= qhi) return _data[v];
        else if (hi <= qlo || qhi <= lo) return 0;
        else {
            int mid = (lo + hi) >> 1;
            return _query(v * 2,     qlo, qhi, lo, mid) +
                   _query(v * 2 + 1, qlo, qhi, mid, hi);
        }
    }
    
    void _log_update(int v) {
        for (v >>= 1; 1 <= v; v >>= 1) {
            _data[v] = _data[v * 2] + _data[v * 2 + 1];
        }
    }
    
public:
    SegmentTree(unsigned int n, int strength) : _offset(1) {
        if (__builtin_popcount(n) == 1) _offset = n;
        else _offset = 1<<((sizeof(unsigned int) * 8) - __builtin_clz(n));
        
        _data = vector<long long>(_offset * 2);
        _back = _offset;
        _sth = strength;
    };
    
    void push_back(long long val) {
        if (val) _non_zero.insert(_back);
        _data[_back] = val;
        _log_update(_back++);
    }
    
    void set(int ind, long long val) {
        ind += _offset;
        
        if (val) _non_zero.insert(ind);
        else _non_zero.erase(ind);
        _data[ind] = val;
        _log_update(ind);
    }
    
    void spray(int low, int hi) {
        if (_sth == 1) return;
        
        std::set<int> _non_zero_copy(_non_zero.begin(), _non_zero.end());
        auto low_it = _non_zero.lower_bound(low + _offset), hi_it = _non_zero.lower_bound(hi + _offset);
        for (auto it = low_it; it != hi_it; it = next(it)) {
            _data[*it] /= _sth;
            if (_data[*it] == 0) _non_zero_copy.erase(*it);
            _log_update(*it);
        }
        
        _non_zero = std::move(_non_zero_copy);
    }
    
    long long query(int query_low, int query_hi) {
        query_low += _offset; query_hi += _offset;
        return _query(1, query_low, query_hi, _offset, _offset * 2);
    }
};

istream& operator>>(istream &in, SegmentTree &tree) {
    long long _t; in>>_t;
    tree.push_back(_t);
    return in;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    
    
    int n, q, k;
    cin>>n>>q>>k;
    
    SegmentTree tree(n, k);
    while (n--) cin>>tree;
    
    while (q--) {
        int t;
        cin>>t;
        if (t == 1) {
            int i, val;
            cin>>i>>val;
            tree.set(--i, (long long) val);
        } else if (t == 2) {
            int l, r;
            cin>>l>>r;
            tree.spray(--l, r);
        } else {
            int l, r;
            cin>>l>>r;
            cout<<tree.query(--l, r)<<endl;
        }
    }
}

Compilation message

sterilizing.cpp:70:10: error: declaration of 'void SegmentTree::set(int, long long int)' changes meaning of 'set' [-fpermissive]
   70 |     void set(int ind, long long val) {
      |          ^~~
In file included from /usr/include/c++/10/set:61,
                 from sterilizing.cpp:20:
/usr/include/c++/10/bits/stl_set.h:94:11: note: 'set' declared here as 'class std::set<int>'
   94 |     class set
      |           ^~~