#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define endl "\n"
#define INF 1000000000
#define LINF 1000000000000000LL
#define pb push_back
#define all(x) x.begin(), x.end()
#define len(s) (int)s.size()
#define test_case { int t; cin>>t; while(t--)solve(); }
#define input(n, v) {for(int i = 0;i<n;i++) cin>>v[i];}
#define output(n, v) {for(int i = 0;i<n;i++) cout<<v[i]<<" "; cout<<endl;}
#define single_case solve();
#define line cout<<"------------"<<endl;
#define ios { ios_base::sync_with_stdio(false); cin.tie(NULL); }
using namespace std;
int n, q, k;
const int N = 1e5 + 5;
ll sum[4*N];
vector<ll> a(N);
ll get_sum(int node, int l, int r, int i, int j)
{
if(i>r||j<l) return 0;
if(i>=l&&j<=r) return sum[node];
int mid = (i+j)/2;
return get_sum(node*2+1, l, r, i, mid) + get_sum(node*2+2, l, r, mid+1, j);
}
void update(int node, int l, int r, int pos, int x)
{
if(l==r)
{
sum[node] = x;
return;
}
int mid = (l+r)/2;
if(pos>mid)
update(node*2+2, mid+1, r, pos, x);
else
update(node*2+1, l, mid, pos, x);
sum[node] = sum[node*2+1] + sum[node*2+2];
}
ll build_sum(int node, int l, int r)
{
if(l==r)
{
return sum[node] = a[l];
}
int mid = (l+r)/2;
return sum[node] = build_sum(node*2+1, l, mid) + build_sum(node*2+2, mid+1, r);
}
int main()
{
ios
cin>>n>>q>>k;
for(int i = 0;i<n;i++)
cin>>a[i];
//cout<<11111<<endl;
set<ll> alive;
for(ll i = 0;i<n;i++)
if(a[i])
alive.insert(i);
build_sum(0, 0, n-1);
//cout<<2222<<endl;
while(q--)
{
ll s, t, u;
cin>>s>>t>>u;
t--;
u--;
if(s==1)
{
// a-ti tanjir na b
u++;
//cout<<a[t]<<" "<<u<<endl;
if(!a[t]&&u)
alive.insert(t);
if(a[t]&&!u)
alive.erase(t);
a[t] = u;
update(0, 0, n-1, t, u);
}
else if(s==2)
{
// sprej
if(k==1) continue;
vector<int> s;
for(int x : alive)
{
//cout<<x<<" ";
//cout<<x<<" ";
//line
//cout<<x<<" "<<a[x]<<endl;
if(x<t||x>u) continue;
//cout<<x<<" "<<a[x]<<endl;
a[x] /= k;
if(!a[x])
s.pb(x);
update(0, 0, n-1, x, a[x]);
}
for(int x : s)
alive.erase(x);
//cout<<endl;
//cout<<endl;
}
else{
// ispisi sumu od l do r
//cout<<u<<" "<<t<<endl;
cout<<get_sum(0, t, u, 0, n-1);
cout<<endl;
}
}
return 0;
}
/*
5 10 3
27 27 27 27 27
2 2 4
2 1 5
2 3 3
2 3 5
1 4 9
1 5 9
3 1 5
3 1 5
3 1 5
3 1 5
*/
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
3 ms |
1132 KB |
Output is correct |
2 |
Correct |
2 ms |
1280 KB |
Output is correct |
3 |
Correct |
4 ms |
1272 KB |
Output is correct |
4 |
Correct |
12 ms |
1280 KB |
Output is correct |
5 |
Correct |
13 ms |
1388 KB |
Output is correct |
6 |
Correct |
10 ms |
1408 KB |
Output is correct |
7 |
Correct |
12 ms |
1388 KB |
Output is correct |
8 |
Correct |
12 ms |
1388 KB |
Output is correct |
9 |
Correct |
16 ms |
1388 KB |
Output is correct |
10 |
Correct |
11 ms |
1388 KB |
Output is correct |
11 |
Correct |
11 ms |
1388 KB |
Output is correct |
12 |
Correct |
12 ms |
1408 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
63 ms |
4972 KB |
Output is correct |
2 |
Correct |
53 ms |
5740 KB |
Output is correct |
3 |
Correct |
59 ms |
8812 KB |
Output is correct |
4 |
Correct |
76 ms |
10436 KB |
Output is correct |
5 |
Correct |
89 ms |
10860 KB |
Output is correct |
6 |
Correct |
89 ms |
10860 KB |
Output is correct |
7 |
Correct |
95 ms |
10836 KB |
Output is correct |
8 |
Correct |
88 ms |
10860 KB |
Output is correct |
9 |
Correct |
83 ms |
10732 KB |
Output is correct |
10 |
Correct |
87 ms |
10732 KB |
Output is correct |
11 |
Correct |
83 ms |
10732 KB |
Output is correct |
12 |
Correct |
84 ms |
10732 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
22 ms |
1920 KB |
Output is correct |
2 |
Correct |
26 ms |
3564 KB |
Output is correct |
3 |
Correct |
31 ms |
3692 KB |
Output is correct |
4 |
Correct |
62 ms |
3052 KB |
Output is correct |
5 |
Correct |
100 ms |
6508 KB |
Output is correct |
6 |
Correct |
102 ms |
6508 KB |
Output is correct |
7 |
Correct |
81 ms |
6508 KB |
Output is correct |
8 |
Correct |
98 ms |
6380 KB |
Output is correct |
9 |
Correct |
87 ms |
6436 KB |
Output is correct |
10 |
Correct |
86 ms |
6436 KB |
Output is correct |
11 |
Correct |
87 ms |
6564 KB |
Output is correct |
12 |
Correct |
88 ms |
6692 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
262 ms |
5612 KB |
Output is correct |
2 |
Correct |
261 ms |
6636 KB |
Output is correct |
3 |
Correct |
474 ms |
5740 KB |
Output is correct |
4 |
Correct |
300 ms |
5356 KB |
Output is correct |
5 |
Correct |
474 ms |
10860 KB |
Output is correct |
6 |
Correct |
567 ms |
10732 KB |
Output is correct |
7 |
Correct |
428 ms |
10988 KB |
Output is correct |
8 |
Correct |
785 ms |
10988 KB |
Output is correct |
9 |
Correct |
476 ms |
10612 KB |
Output is correct |
10 |
Correct |
566 ms |
10776 KB |
Output is correct |
11 |
Correct |
373 ms |
10860 KB |
Output is correct |
12 |
Correct |
823 ms |
10828 KB |
Output is correct |