답안 #68308

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
68308 2018-08-16T14:35:17 Z duality Sterilizing Spray (JOI15_sterilizing) C++11
100 / 100
282 ms 72356 KB
#define DEBUG 0

#include <bits/stdc++.h>
using namespace std;

#if DEBUG
// basic debugging macros
int __i__,__j__;
#define printLine(l) for(__i__=0;__i__<l;__i__++){cout<<"-";}cout<<endl
#define printLine2(l,c) for(__i__=0;__i__<l;__i__++){cout<<c;}cout<<endl
#define printVar(n) cout<<#n<<": "<<n<<endl
#define printArr(a,l) cout<<#a<<": ";for(__i__=0;__i__<l;__i__++){cout<<a[__i__]<<" ";}cout<<endl
#define print2dArr(a,r,c) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<a[__i__][__j__]<<" ";}cout<<endl;}
#define print2dArr2(a,r,c,l) cout<<#a<<":\n";for(__i__=0;__i__<r;__i__++){for(__j__=0;__j__<c;__j__++){cout<<setw(l)<<setfill(' ')<<a[__i__][__j__]<<" ";}cout<<endl;}

// advanced debugging class
// debug 1,2,'A',"test";
class _Debug {
    public:
        template<typename T>
        _Debug& operator,(T val) {
            cout << val << endl;
            return *this;
        }
};
#define debug _Debug(),
#else
#define printLine(l)
#define printLine2(l,c)
#define printVar(n)
#define printArr(a,l)
#define print2dArr(a,r,c)
#define print2dArr2(a,r,c,l)
#define debug
#endif

// define
#define MAX_VAL 999999999
#define MAX_VAL_2 999999999999999999LL
#define EPS 1e-6
#define mp make_pair
#define pb push_back

// typedef
typedef unsigned int UI;
typedef long long int LLI;
typedef unsigned long long int ULLI;
typedef unsigned short int US;
typedef pair<int,int> pii;
typedef pair<LLI,LLI> plli;
typedef vector<int> vi;
typedef vector<LLI> vlli;
typedef vector<pii> vpii;
typedef vector<plli> vplli;

// ---------- END OF TEMPLATE ----------

int C[100000];
LLI bit[100001];
LLI query(int i) {
    LLI sum = 0;
    for (i++; i > 0; i -= i & (-i)) sum += bit[i];
    return sum;
}
int update(int i,LLI num,int N) {
    for (i++; i <= N; i += i & (-i)) bit[i] += num;
    return 0;
}
set<int> s;
int main() {
    int i;
    int N,Q,K;
    int S,T,U;
    scanf("%d %d %d",&N,&Q,&K);
    for (i = 0; i < N; i++) {
        scanf("%d",&C[i]),update(i,C[i],N);
        if (C[i] > 0) s.insert(i);
    }
    for (i = 0; i < Q; i++) {
        scanf("%d %d %d",&S,&T,&U);
        if (S == 1) {
            T--;
            update(T,U-C[T],N),C[T] = U;
            if ((K > 1) && (U > 0)) s.insert(T);
        }
        else if (S == 2) {
            T--,U--;
            if (K > 1) {
                auto it = s.lower_bound(T);
                while ((it != s.end()) && (*it <= U)) {
                    update(*it,(C[*it]/K)-C[*it],N);
                    C[*it] /= K;
                    if (C[*it] == 0) it = s.erase(it);
                    else it++;
                }
            }
        }
        else printf("%lld\n",query(U-1)-query(T-2));
    }

    return 0;
}

Compilation message

sterilizing.cpp: In function 'int main()':
sterilizing.cpp:74:10: 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:76:26: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d",&C[i]),update(i,C[i],N);
         ~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~
sterilizing.cpp:80:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
         scanf("%d %d %d",&S,&T,&U);
         ~~~~~^~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 504 KB Output is correct
2 Correct 3 ms 608 KB Output is correct
3 Correct 5 ms 696 KB Output is correct
4 Correct 7 ms 916 KB Output is correct
5 Correct 6 ms 1208 KB Output is correct
6 Correct 7 ms 1208 KB Output is correct
7 Correct 7 ms 1208 KB Output is correct
8 Correct 7 ms 1332 KB Output is correct
9 Correct 7 ms 1332 KB Output is correct
10 Correct 7 ms 1336 KB Output is correct
11 Correct 7 ms 1404 KB Output is correct
12 Correct 7 ms 1600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 81 ms 6560 KB Output is correct
2 Correct 69 ms 7308 KB Output is correct
3 Correct 71 ms 11404 KB Output is correct
4 Correct 111 ms 14952 KB Output is correct
5 Correct 112 ms 17492 KB Output is correct
6 Correct 108 ms 20072 KB Output is correct
7 Correct 110 ms 22524 KB Output is correct
8 Correct 110 ms 24916 KB Output is correct
9 Correct 107 ms 27288 KB Output is correct
10 Correct 102 ms 29640 KB Output is correct
11 Correct 104 ms 31932 KB Output is correct
12 Correct 104 ms 34172 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 23 ms 34172 KB Output is correct
2 Correct 23 ms 34172 KB Output is correct
3 Correct 30 ms 34172 KB Output is correct
4 Correct 81 ms 34172 KB Output is correct
5 Correct 81 ms 35228 KB Output is correct
6 Correct 87 ms 36636 KB Output is correct
7 Correct 80 ms 38080 KB Output is correct
8 Correct 81 ms 39380 KB Output is correct
9 Correct 75 ms 40672 KB Output is correct
10 Correct 80 ms 41948 KB Output is correct
11 Correct 75 ms 43216 KB Output is correct
12 Correct 85 ms 44632 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 122 ms 45772 KB Output is correct
2 Correct 115 ms 47524 KB Output is correct
3 Correct 109 ms 48204 KB Output is correct
4 Correct 134 ms 49356 KB Output is correct
5 Correct 183 ms 55712 KB Output is correct
6 Correct 178 ms 58236 KB Output is correct
7 Correct 172 ms 60668 KB Output is correct
8 Correct 239 ms 63192 KB Output is correct
9 Correct 215 ms 65460 KB Output is correct
10 Correct 216 ms 67792 KB Output is correct
11 Correct 177 ms 70184 KB Output is correct
12 Correct 282 ms 72356 KB Output is correct