이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_set>
#include <bitset>
#include <time.h>
#include <limits.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define Fi first
#define Se second
#define pb push_back
#define szz(x) (int)x.size()
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
typedef tuple<int, int, int> t3;
int N, K, Q;
int A[100010];
ll T[1<<18];
int H[1<<18];
void init(int rt, int l, int r) {
if(l == r) T[rt] = A[l];
else {
int m = (l + r) >> 1;
init(rt*2, l, m);
init(rt*2+1, m+1, r);
T[rt] = T[rt*2] + T[rt*2+1];
H[rt] = H[rt*2] & H[rt*2+1];
}
}
void update_v(int rt, int l, int r, int x, int v) {
if(l == r) {
T[rt] = v;
H[rt] = (v == 0);
return;
}
int m = (l + r) >> 1;
if(x <= m) update_v(rt*2, l, m, x, v);
else update_v(rt*2+1, m+1, r, x, v);
T[rt] = T[rt*2] + T[rt*2+1];
H[rt] = H[rt*2] & H[rt*2+1];
}
void update_s(int rt, int l, int r, int s, int e) {
if(H[rt]) return;
if(l == r) {
T[rt] /= K;
H[rt] = (T[rt] == 0);
return;
}
int m = (l + r) >> 1;
if(s <= m) update_s(rt*2, l, m, s, e);
if(m < e) update_s(rt*2+1, m+1, r, s, e);
T[rt] = T[rt*2] + T[rt*2+1];
H[rt] = H[rt*2] & H[rt*2+1];
}
ll get_sum(int rt, int l, int r, int s, int e) {
if(s <= l && r <= e) return T[rt];
int m = (l + r) >> 1;
ll res = 0;
if(s <= m) res += get_sum(rt*2, l, m, s, e);
if(m < e) res += get_sum(rt*2+1, m+1, r, s, e);
return res;
}
int main() {
scanf("%d%d%d", &N, &Q, &K);
for(int i=1;i<=N;i++) scanf("%d", A + i);
init(1, 1, N);
for(int i=1;i<=Q;i++) {
int cmd; scanf("%d", &cmd);
if(cmd == 1) {
int x, y; scanf("%d%d", &x, &y);
update_v(1, 1, N, x, y);
}
else if(cmd == 2) {
int l, r; scanf("%d%d", &l, &r);
if(K > 1) update_s(1, 1, N, l, r);
}
else {
int l, r; scanf("%d%d", &l, &r);
printf("%lld\n", get_sum(1, 1, N, l, r));
}
}
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
sterilizing.cpp: In function 'int main()':
sterilizing.cpp:86:7: 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:87:29: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
for(int i=1;i<=N;i++) scanf("%d", A + i);
~~~~~^~~~~~~~~~~~~
sterilizing.cpp:90:17: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
int cmd; scanf("%d", &cmd);
~~~~~^~~~~~~~~~~~
sterilizing.cpp:92:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
int x, y; scanf("%d%d", &x, &y);
~~~~~^~~~~~~~~~~~~~~~
sterilizing.cpp:96:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
int l, r; scanf("%d%d", &l, &r);
~~~~~^~~~~~~~~~~~~~~~
sterilizing.cpp:100:19: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
int l, r; scanf("%d%d", &l, &r);
~~~~~^~~~~~~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |