답안 #970757

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
970757 2024-04-27T08:11:48 Z Beerus13 Sterilizing Spray (JOI15_sterilizing) C++14
80 / 100
5000 ms 7504 KB
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5 + 5;

struct node {
    ll sum, mx;
    node() {}
    node(ll sum, ll mx) : sum(sum), mx(mx) {}
};

node operator + (node &a, node &b) {
    node res;
    res.sum = a.sum + b.sum;
    res.mx = max(a.mx, b.mx);
    return res;
}

int n, q, k;
node st[N << 2];

void update_point(int u, int val) {
    int id = 1, l = 1, r = n;
    while(l < r) {
        int m = l + r >> 1;
        if(u > m) id = id << 1 | 1, l = m + 1;
        else id = id << 1, r = m;
    }
    st[id] = node(val, val);
    while(id > 1) id = id >> 1, st[id] = st[id << 1] + st[id << 1 | 1];
}

void update(int u, int v, int id = 1, int l = 1, int r = n) {
    if(u > r || v < l || st[id].mx == 0) return;
    if(l == r) {
        st[id].sum /= k;
        st[id].mx /= k;
        return;
    }
    int m = l + r >> 1;
    update(u, v, id << 1, l, m);
    update(u, v, id << 1 | 1, m + 1, r);
    st[id] = st[id << 1] + st[id << 1 | 1];
}

ll query(int u, int v, int id = 1, int l = 1, int r = n) {
    if(u > r || v < l) return 0;
    if(u <= l && r <= v) return st[id].sum;
    int m = l + r >> 1;
    return query(u, v, id << 1, l, m) + query(u, v, id << 1 | 1, m + 1, r);
}

void solve() {
     cin >> n >> q >> k;
     for(int i = 1, x; i <= n; ++i) {
        cin >> x;
        update_point(i, x);
     }
     while(q--) {
        int type, u, v; cin >> type >> u >> v;
        if(type == 1) update_point(u, v);
        if(type == 2) update(u, v);
        if(type == 3) cout << query(u, v) << '\n';
     }
}

signed main() {
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int test = 1;
    // cin >> test;
    while(test--) solve();
    return 0;
}

Compilation message

sterilizing.cpp: In function 'void update_point(int, int)':
sterilizing.cpp:25:19: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   25 |         int m = l + r >> 1;
      |                 ~~^~~
sterilizing.cpp: In function 'void update(int, int, int, int, int)':
sterilizing.cpp:40:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   40 |     int m = l + r >> 1;
      |             ~~^~~
sterilizing.cpp: In function 'long long int query(int, int, int, int, int)':
sterilizing.cpp:49:15: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
   49 |     int m = l + r >> 1;
      |             ~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 344 KB Output is correct
2 Correct 2 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 3 ms 348 KB Output is correct
5 Correct 3 ms 604 KB Output is correct
6 Correct 3 ms 604 KB Output is correct
7 Correct 3 ms 604 KB Output is correct
8 Correct 3 ms 600 KB Output is correct
9 Correct 4 ms 600 KB Output is correct
10 Correct 3 ms 600 KB Output is correct
11 Correct 3 ms 612 KB Output is correct
12 Correct 3 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Execution timed out 5022 ms 4216 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 22 ms 3160 KB Output is correct
2 Correct 12 ms 2908 KB Output is correct
3 Correct 16 ms 2908 KB Output is correct
4 Correct 40 ms 3840 KB Output is correct
5 Correct 77 ms 5968 KB Output is correct
6 Correct 50 ms 6128 KB Output is correct
7 Execution timed out 5021 ms 5820 KB Time limit exceeded
8 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 75 ms 4176 KB Output is correct
2 Correct 74 ms 4436 KB Output is correct
3 Correct 93 ms 3924 KB Output is correct
4 Correct 96 ms 4556 KB Output is correct
5 Correct 112 ms 7248 KB Output is correct
6 Correct 130 ms 7252 KB Output is correct
7 Correct 122 ms 7392 KB Output is correct
8 Correct 162 ms 7416 KB Output is correct
9 Correct 145 ms 7308 KB Output is correct
10 Correct 160 ms 7504 KB Output is correct
11 Correct 116 ms 7148 KB Output is correct
12 Correct 207 ms 7140 KB Output is correct