Submission #153111

# Submission time Handle Problem Language Result Execution time Memory
153111 2019-09-12T12:52:22 Z karma Sterilizing Spray (JOI15_sterilizing) C++14
80 / 100
5000 ms 9372 KB
#include<bits/stdc++.h>
#pragma GCC optimize("O3")
#define ll      long long
#define pb      emplace_back

using namespace std;

const int N = int(1e5) + 2;

int n, q, k, a[N], irene, cmd, x, y;
ll t[N];
set<int> s;
vector<int> rmv;

void Update(int x, int val) {
     for(; x <= n; x += (x & -x)) t[x] += val;
}

ll Query(int x) {
    ll res = 0;
    for(; x > 0; x -= (x & -x)) res += t[x];
    return res;
}

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    if(fopen("test.inp", "r")) {
        freopen("test.inp", "r", stdin);
        freopen("test.out", "w", stdout);
    }
    cin >> n >> q >> k;
    for(int i = 1; i <= n; ++i) {
        cin >> a[i]; Update(i, a[i]);
        if(a[i]) s.insert(i);
    }
    rmv.clear();
    while(q --) {
        cin >> cmd >> x >> y;
        if(cmd == 1) {
            if(y && !a[x]) s.insert(x);
            Update(x, y - a[x]); a[x] = y;
        } else if(cmd == 2) {
           auto ptr = s.lower_bound(x);
           while(*ptr >= x && *ptr <= y && ptr != s.end()) {
               irene = a[*ptr] / k;
               Update(*ptr, irene - a[*ptr]);
               if(!irene) rmv.pb(*ptr);
               a[*ptr] = irene, ptr = next(ptr);
           }
           while(rmv.size()) s.erase(rmv.back()), rmv.pop_back();
        } else cout << Query(y) - Query(x - 1) << '\n';
    }
}

Compilation message

sterilizing.cpp: In function 'int main()':
sterilizing.cpp:29:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen("test.inp", "r", stdin);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
sterilizing.cpp:30:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)', declared with attribute warn_unused_result [-Wunused-result]
         freopen("test.out", "w", stdout);
         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 4 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 4 ms 504 KB Output is correct
4 Correct 6 ms 504 KB Output is correct
5 Correct 6 ms 632 KB Output is correct
6 Correct 6 ms 664 KB Output is correct
7 Correct 6 ms 632 KB Output is correct
8 Correct 6 ms 632 KB Output is correct
9 Correct 7 ms 632 KB Output is correct
10 Correct 6 ms 632 KB Output is correct
11 Correct 6 ms 632 KB Output is correct
12 Correct 6 ms 632 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 5065 ms 4960 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 18 ms 1144 KB Output is correct
2 Correct 19 ms 2228 KB Output is correct
3 Correct 24 ms 2400 KB Output is correct
4 Correct 44 ms 2552 KB Output is correct
5 Correct 71 ms 5424 KB Output is correct
6 Correct 68 ms 5344 KB Output is correct
7 Execution timed out 5058 ms 4816 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 86 ms 5240 KB Output is correct
2 Correct 93 ms 5332 KB Output is correct
3 Correct 107 ms 4344 KB Output is correct
4 Correct 101 ms 4248 KB Output is correct
5 Correct 155 ms 9080 KB Output is correct
6 Correct 167 ms 8972 KB Output is correct
7 Correct 147 ms 8952 KB Output is correct
8 Correct 204 ms 9108 KB Output is correct
9 Correct 167 ms 9324 KB Output is correct
10 Correct 220 ms 9204 KB Output is correct
11 Correct 152 ms 9204 KB Output is correct
12 Correct 245 ms 9372 KB Output is correct