This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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);
}
struct Segtree{
int off;
vi tree;
Segtree(int n){
off= 1<<(int)ceil(log2(n));
tree.resize(off*2);
}
int _query(int l, int r, int cl, int cr, int i){
if(cl>r||cr<l)return 0;
else if(cl>=l&&cr<=r){
return tree[i];
}int md=(cl+cr)/2;
return _query(l, r, cl, md, i * 2) + _query(l, r, md + 1, cr, i * 2 + 1);
}int query(int l,int r){
return _query(l,r,0,off - 1, 1);
}
void update(int i,int x){
i+=off;
tree[i]=x;
while(i/=2){
tree[i]=tree[i*2]+tree[i*2+1];
}
}
};
void solve() {
int n,q,k;
cin>>n>>q>>k;
int a[n];
Segtree seg=Segtree(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){
seg.update(l,r);
}else if(g==2){
// for(int i=l;i<r;i++){
// a[i]/=k;
// }
}else{
cout<<seg.query(l,r-1)<<endl;
}
}
}
signed mishari() {
mustawa;
//usaco("");
int t = 1;
//cin>>t;
while (t--)solve();
}
Compilation message (stderr)
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);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |