답안 #25103

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
25103 2017-06-20T06:55:20 Z 윤교준(#1055) Sterilizing Spray (JOI15_sterilizing) C++11
10 / 100
1396 ms 2804 KB
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <bitset>
#include <string>
#define pb push_back
#define sz(V) ((int)(V).size())
#define allv(V) ((V).begin()),((V).end())
#define befv(V) ((V)[(sz(V)-2)])
#define sorv(V) sort(allv(V))
#define univ(V) (V).erase(unique(allv(V)),(V).end())
#define upmin(a,b) (a)=min((a),(b))
#define upmax(a,b) (a)=max((a),(b))
#define INF (1100000099)
#define INFLL (1100000000000000099ll)
#define MAXN (100005)
#define SQN (333)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
struct BUC {
    ll dt[MAXN];
    ll sum[MAXN/SQN + 5], div[MAXN/SQN + 5];

    void init() { fill(div, div+(MAXN/SQN + 5), 1); }
    int getIdx(int X) { return (X-1)/SQN + 1; }
    int getSidx(int idx) { return (idx-1)*SQN + 1; }
    int getEidx(int idx) { return idx*SQN; }
    void updiv(int idx, ll R) { div[idx] *= R; if(INF < div[idx]) div[idx] = (ll)INF*4; }
    void updBuc(int idx) {
        const int S = getSidx(idx), E = getEidx(idx);
        ll &ret = sum[idx]; ret = 0;
        for(int i = S; i <= E; i++) {
            dt[i] /= div[idx]; ret += dt[i];
        }
        div[idx] = 1;
    }
    void update(int S, int E, ll R) {
        const int Sidx = getIdx(S), Eidx = getIdx(E);
        for(int i = Sidx+1; i < Eidx; i++) {
            updiv(i, R); sum[i] /= R;
        }
        if(Sidx == Eidx) {
            updBuc(Sidx); for(int i = S; i <= E; i++) dt[i] /= R;
            updBuc(Sidx);
        } else {
            updBuc(Sidx); updBuc(Eidx);
            for(int i = getEidx(Sidx); S <= i; i--) dt[i] /= R;
            for(int i = getSidx(Eidx); i <= E; i++) dt[i] /= R;
            updBuc(Sidx); updBuc(Eidx);
        }
    }
    void insert(int X, int R) {
        const int idx = getIdx(X);
        updBuc(idx); dt[X] = R; updBuc(idx);
    }
    ll getSum(int S, int E) {
        const int Sidx = getIdx(S), Eidx = getIdx(E);
        ll ret = 0;
        for(int i = Sidx+1; i < Eidx; i++) ret += sum[i];
        updBuc(Sidx); if(Sidx != Eidx) updBuc(Eidx);
        if(Sidx == Eidx) {
            for(int i = S; i <= E; i++) ret += dt[i];
        } else {
            for(int i = getEidx(Sidx); S <= i; i--) ret += dt[i];
            for(int i = getSidx(Eidx); i <= E; i++) ret += dt[i];
        }
        return ret;
    }
};

BUC BT;
int N, Q, K;

int main() {
    BT.init();
    scanf("%d%d%d", &N, &Q, &K);
    for(int i = 1, c; i <= N; i++) {
        scanf("%d", &c); BT.dt[i] = c; BT.sum[BT.getIdx(i)] += c;
    }
    for(int type, a, b; Q--;) {
        scanf("%d%d%d", &type, &a, &b);
        if(1 == type) BT.insert(a, b);
        else if(2 == type) BT.update(a, b, K);
        else printf("%lld\n", BT.getSum(a, b));
    }
    return 0;
}

Compilation message

sterilizing.cpp: In function 'int main()':
sterilizing.cpp:90:32: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
     scanf("%d%d%d", &N, &Q, &K);
                                ^
sterilizing.cpp:92:24: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d", &c); BT.dt[i] = c; BT.sum[BT.getIdx(i)] += c;
                        ^
sterilizing.cpp:95:39: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d%d%d", &type, &a, &b);
                                       ^
# 결과 실행 시간 메모리 Grader output
1 Correct 13 ms 2804 KB Output is correct
2 Correct 9 ms 2804 KB Output is correct
3 Incorrect 3 ms 2804 KB Output isn't correct
4 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 1179 ms 2804 KB Output is correct
2 Correct 1022 ms 2804 KB Output is correct
3 Correct 806 ms 2804 KB Output is correct
4 Correct 916 ms 2804 KB Output is correct
5 Correct 1149 ms 2804 KB Output is correct
6 Correct 1236 ms 2804 KB Output is correct
7 Correct 1179 ms 2804 KB Output is correct
8 Correct 1286 ms 2804 KB Output is correct
9 Correct 1396 ms 2804 KB Output is correct
10 Correct 1349 ms 2804 KB Output is correct
11 Correct 1263 ms 2804 KB Output is correct
12 Correct 1273 ms 2804 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Incorrect 459 ms 2804 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 853 ms 2804 KB Output isn't correct
2 Halted 0 ms 0 KB -