이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#pragma GCC optimize("O3,unroll-loops")
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define coutpair(p) cout << p.first << " " << p.second << "\n"
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;
struct node{
int s, e, m; //range is [s,e], m is the middle point
ll val; //sum of [s,e]
node *l, *r; //create two children l and r, where l is [s,m] and [m+1,e]
node (int S, int E){ //constructor called node
s = S, e = E, m = (s+e)/2;
val = 0; //initially all values are 0
if (s != e){ //node is not yet a leaf, so create two children
l = new node(s, m); //create left child
r = new node(m+1, e); //create right child
}
}
void spray(int S, int E, ll V){ //increment [S,E] by V
if (V == 0 || V == 1) return;
if (s == e){
val /= V;
return;
}
if (E <= m) l->spray(S, E, V); //[S,E] is in the left child
else if (S > m) r->spray(S, E, V); //[S,E] is in the right child
else l->spray(S, m, V), r->spray(m+1, E, V);
val = l->val + r->val; //update the range sum
}
void adjust(int X, ll V){
if (s == e){
val = V;
return;
}
else{
if (X <= m) l->adjust(X, V);
else r->adjust(X, V);
}
val = l->val + r->val; //update the range sum
}
ll sum(int S, int E){
if (s == S && e == E) return val; //case 1
if (E <= m) return l->sum(S, E); //case 2, recurse to left child
else if (S >= m+1) return r->sum(S, E); //case 3, recurse to right child
else return l->sum(S, m) + r->sum(m+1, E); //case 4, split the query range, recurse to both childs
}
} *root;
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n, q, k, c, s, t, u; cin >> n >> q >> k;
root = new node(1, n);
for (int i=1; i<=n; i++){
cin >> c;
root->adjust(i, c);
}
for (int i=0; i<q; i++){
cin >> s >> t >> u;
if (s == 1){
root->adjust(t, u);
}
else if (s == 2){
root->spray(t, u, k);
}
else cout << root->sum(t, u) << "\n";
}
return 0;
}
# | 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... |