이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
# include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define int long long
#define pii pair <int, int>
#define pb push_back
const int N = 3e5 + 5;
int t,n,q,k,a[N],tree[N];
set <int> s;
void update(int idx, int val) {
for (int i = idx; i < N; i+=i&(-i)) {
tree[i] += val;
}
}
int getans(int idx) {
int pas = 0;
for (int i = idx; i > 0; i-=i&(-i)) {
pas += tree[i];
}
return pas;
}
main() {
std::ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
cin>>n>>q>>k;
for (int i = 1; i <= n; i++) {
cin>>a[i];
if (a[i] > 0) s.insert(i);
update(i, a[i]);
}
while(q--) {
int ty;
cin>>ty;
if (ty == 1) {
int idx, val; cin>>idx>>val;
update(idx, val - a[idx]); a[idx] = val; if (a[idx]) s.insert(idx);
continue;
} else if (ty == 2) {
int l, r; cin>>l>>r;
if (k == 1) continue;
vector <int> todel;
for (auto it = s.lower_bound(l); it != s.end(); it++) {
int id = *it; if (id > r) break; update(id, -a[id]); update(id, a[id] / k); a[id] /= k; if (a[id] == 0) todel.pb(id);
}
for (int x : todel) s.erase(s.find(x));
} else if (ty == 3) {
int l, r; cin>>l>>r; cout<<getans(r) - getans(l - 1)<<"\n";
}
}
}
컴파일 시 표준 에러 (stderr) 메시지
sterilizing.cpp:23:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
23 | main() {
| ^~~~
# | 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... |