#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("O3")
#define int long long
#define ll long long
#define endl "\n"
#define vi vector<int>
#define vpii vector<pair<int,int> >
#define umap unordered_map
#define uset unordered_set
#define mk make_pair
#define pb push_back
//#define pop pop_back
#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define read(x) for (auto& zu: (x)) cin >> zu;
#define F first
#define S second
#define mustawa ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
#define pii pair<int,int>
#define mishari main
const int inf=1e9+7;
void fa(bool ok){ cout << (ok ? "Yes": "No") << "\n";}
void usaco(string s) {
freopen((s + ".in").c_str(), "r", stdin);
freopen((s + ".out").c_str(), "w", stdout);
}
int n;
int N=1<<((int)ceil(log2(2e5)));
vi tree(2*N);
int f(int l,int r,int cl=0,int cr=N-1,int i=1){
if(cl>r||cr<l)return 0;
else if(cl>=l&&cr<=r){
return tree[i];
}int md=(cl+cr)/2;
return f(l,r,cl,md,i*2)+f(l,r,md+1,cr,i*2+1);
}
void update(int i,int x){
int j=N+i;
tree[j]=x;
while(j/=2){
tree[j]=tree[j*2]+tree[j*2+1];
}
}
void solve() {
int q,k;
cin>>n>>q>>k;
if(k==1) {
for (int i = 0; i < n; ++i) {
cin >> tree[N + i];
}
for (int i = N; --i;) {
tree[i] = tree[i * 2] + tree[i * 2 + 1];
}
while (q--) {
int a, b, c;
cin >> a >> b >> c;
if (a == 1)update(b - 1, c);
else if (a == 3) cout << f(b - 1, c - 1) << endl;
}
}else{
int a[n];
for(int i=0;i<n;i++)cin>>a[i];
while(q--){
int g,l,r;
cin>>g>>l>>r;
l--;
if(g==1){
a[l]=r;
}else if(g==2){
for(int i=l;i<r;i++){
a[i]/=k;
}
}else{
int ans=0;
for(int i=l;i<r;i++){
ans+=a[i];
}cout<<ans<<endl;
}
}
}
}
signed mishari() {
mustawa;
//usaco("");
int t = 1;
//cin>>t;
while (t--)solve();
}
Compilation message
sterilizing.cpp: In function 'void usaco(std::string)':
sterilizing.cpp:25:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
25 | freopen((s + ".in").c_str(), "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sterilizing.cpp:26:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
26 | freopen((s + ".out").c_str(), "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
4444 KB |
Output is correct |
2 |
Correct |
2 ms |
4444 KB |
Output is correct |
3 |
Correct |
2 ms |
4592 KB |
Output is correct |
4 |
Correct |
4 ms |
4440 KB |
Output is correct |
5 |
Correct |
6 ms |
4660 KB |
Output is correct |
6 |
Correct |
6 ms |
4444 KB |
Output is correct |
7 |
Correct |
6 ms |
4444 KB |
Output is correct |
8 |
Correct |
6 ms |
4444 KB |
Output is correct |
9 |
Correct |
6 ms |
4444 KB |
Output is correct |
10 |
Correct |
6 ms |
4464 KB |
Output is correct |
11 |
Correct |
6 ms |
4444 KB |
Output is correct |
12 |
Correct |
6 ms |
4444 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
35 ms |
6400 KB |
Output is correct |
2 |
Correct |
31 ms |
5972 KB |
Output is correct |
3 |
Correct |
30 ms |
5832 KB |
Output is correct |
4 |
Correct |
33 ms |
6148 KB |
Output is correct |
5 |
Correct |
39 ms |
6484 KB |
Output is correct |
6 |
Correct |
39 ms |
6484 KB |
Output is correct |
7 |
Correct |
38 ms |
6332 KB |
Output is correct |
8 |
Correct |
43 ms |
6524 KB |
Output is correct |
9 |
Correct |
36 ms |
6284 KB |
Output is correct |
10 |
Correct |
36 ms |
6228 KB |
Output is correct |
11 |
Correct |
45 ms |
6252 KB |
Output is correct |
12 |
Correct |
41 ms |
6312 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
111 ms |
4980 KB |
Output is correct |
2 |
Correct |
268 ms |
5140 KB |
Output is correct |
3 |
Correct |
434 ms |
5716 KB |
Output is correct |
4 |
Correct |
933 ms |
5972 KB |
Output is correct |
5 |
Correct |
3866 ms |
6736 KB |
Output is correct |
6 |
Correct |
3838 ms |
7196 KB |
Output is correct |
7 |
Correct |
33 ms |
6108 KB |
Output is correct |
8 |
Correct |
3862 ms |
6640 KB |
Output is correct |
9 |
Execution timed out |
5018 ms |
6088 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1393 ms |
6664 KB |
Output is correct |
2 |
Correct |
1624 ms |
7236 KB |
Output is correct |
3 |
Correct |
866 ms |
6192 KB |
Output is correct |
4 |
Correct |
1187 ms |
6720 KB |
Output is correct |
5 |
Correct |
3890 ms |
7860 KB |
Output is correct |
6 |
Correct |
3884 ms |
8008 KB |
Output is correct |
7 |
Correct |
3916 ms |
7988 KB |
Output is correct |
8 |
Correct |
3853 ms |
8092 KB |
Output is correct |
9 |
Execution timed out |
5032 ms |
7060 KB |
Time limit exceeded |
10 |
Halted |
0 ms |
0 KB |
- |