/*
ID: BidoTeima
LANG: C++11
TASK:
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void moo(string filename);
void ACPLS(string str = "")
{
if(str=="NOF")return;
if(str.size() && str != "IIOT")
moo(str);
else if(str != "IIOT"){
#ifndef ONLINE_JUDGE
freopen("output.txt", "w", stdout);
freopen("input.txt", "r", stdin);
#endif
}
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
void moo(string fileName){
freopen((fileName+".in").c_str(),"r",stdin);
freopen((fileName+".out").c_str(),"w",stdout);
}
#define tc \
int tttttt/*,subtask*/; \
cin >> tttttt/* >> subtask*/; \
while (tttttt--)/*end
*/
const int N = 1e5 + 3;
ll seg[8 * N], lazy[8 * N];
ll a[N];
void propagate(int node){
assert(lazy[node]);
if(lazy[node]!=1){
seg[node] /= lazy[node];
assert(2 * node + 1 < 8 * N);
assert(2 * node + 2 < 8 * N);
lazy[2*node+1]*=lazy[node];
lazy[2*node+2]*=lazy[node];
//lazy[2 * node + 1] = lazy[2 * node + 2] = lazy[node];
}
lazy[node] = 1;
}
void build(int l, int r, int node){
lazy[node] = 1;
if(l == r){
seg[node] = a[l];
return;
}
int mid = (l + r) >> 1;
build(l, mid, 2 * node + 1);
build(mid+1, r, 2 * node + 2);
seg[node] = seg[2 * node + 1] + seg[2 * node + 2];
}
void upd(int l, int r, int idx, ll value, int node){
propagate(node);
if(idx<l||idx>r)
return;
if(l == r){
seg[node] = value;
return;
}
int mid = (l + r) >> 1;
upd(l, mid, idx, value, 2 * node + 1);
upd(mid + 1, r, idx, value, 2 * node + 2);
seg[node] = seg[2 * node + 1] + seg[2 * node + 2];
}
int query(int l, int r, int ql, int qr, int node){
propagate(node);
if(l > r)
return 0;
if(l > qr || r < ql)
return 0;
if(ql <= l && r <= qr)
return seg[node];
int mid = (l + r) >> 1;
return query(l, mid, ql, qr, 2 * node + 1) +
query(mid + 1, r, ql, qr, 2 * node + 2);
}
void lazy_upd(int l, int r, int ql, int qr, ll value, int node){
if(value==1)return;
propagate(node);
if(l > qr || r < ql)
return;
if(l > r)
return;
if(ql <= l && r <= qr){
if(lazy[node] < 2e18/value){
lazy[node] *= value;
}
propagate(node);
return;
}
int mid = (l + r) >> 1;
lazy_upd(l, mid, ql, qr, value, 2 * node + 1);
lazy_upd(mid + 1, r, ql, qr, value, 2 * node + 2);
seg[node] = seg[2 * node + 1] + seg[2 * node + 2];
}
int main()
{
ACPLS("");
int n,q,k;
cin>>n>>q>>k;
for(int i = 0; i < n; i++)
cin>>a[i];
build(0, n - 1, 0);
while(q--){
int S;
cin>>S;
int T, U;
cin>>T>>U;
if(S == 1){
int a=T,b=U;
upd(0, n - 1, a - 1, b, 0);
}
if(S == 2){
int l, r;
l=T,r=U;
--l, --r;
lazy_upd(0, n - 1, l, r, k, 0);
}
if(S == 3){
int l, r;
l=T,r=U;
--l, --r;
cout<<query(0, n - 1, l, r, 0)<<'\n';
}
}
}
Compilation message
sterilizing.cpp: In function 'void ACPLS(std::string)':
sterilizing.cpp:17:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
17 | freopen("output.txt", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
sterilizing.cpp:18:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
18 | freopen("input.txt", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
sterilizing.cpp: In function 'void moo(std::string)':
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((fileName+".in").c_str(),"r",stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
sterilizing.cpp:27:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
27 | freopen((fileName+".out").c_str(),"w",stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
2 ms |
340 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |