Submission #523829

# Submission time Handle Problem Language Result Execution time Memory
523829 2022-02-08T08:56:32 Z IMystic Sterilizing Spray (JOI15_sterilizing) C++17
0 / 100
3 ms 332 KB
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;



template <typename T>
class fenwick {
public : 
    int n;
    vector<T> fen;
    explicit fenwick(vector<int> &a) : n(int(a.size())) {
        fen.resize(n);
        for(int i=0; i<n; i++)this->inc(i, a[i]);
    }

    T get(int p){
        T v = 0;
        while(p >= 0){
            v += fen[p];
            p = (p & ( p + 1)) - 1;
        }
        return v;
    }

    T get(int l, int r){
        return (get(r) - get(l - 1));
    }

    void set(int p, T v){
        v = v - get(p, p);
        inc(p, v);
    }

    void inc(int p, T v){
        while(p < n){
            fen[p] += v;
            p |= (p + 1);
        }
    }
};


int main(){
    ios_base :: sync_with_stdio(false);
    cin.tie(nullptr);

    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif

    int n, q, k;
    cin >> n >> q >> k;
    vector<int> a(n);
    for(int i=0; i<n; i++)cin >> a[i];

    fenwick<int> d(a);
    set<int> b;
    for(int i=0; i<n; i++)b.insert(i);

    for(int i=0; i<q; i++){
        int t, l, r;
        cin >> t >>  l >> r;
        --l, --r;
        if(t == 1){
            d.set(l, r + 1);
            b.insert(l);
        }
        else if(t == 2){
            while(true){
                auto it = lower_bound(b.begin(), b.end(), l);
                if(*it > r || it == b.end())break;
                int nw = d.get(*it, *it)/k;
                d.set(*it, nw);
                l = *it + 1;
                if(nw == 0)b.erase(*it);
            }
        }else{
            cout << d.get(l, r) << '\n';
        }

        for(int i=0; i<n; i++)cout << d.get(i, i) << ' ';
        cout << '\n';
    }
    return 0;
}

Compilation message

sterilizing.cpp: In function 'int main()':
sterilizing.cpp:49:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |     freopen("input.txt", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
sterilizing.cpp:50:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |     freopen("output.txt", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 3 ms 332 KB Output isn't correct
2 Halted 0 ms 0 KB -