Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- int n;
- int pref[100005];
- int a[100005];
- void update(int l,int r,int x){
- pref[l]+=x;
- pref[r+1]-=x;
- }
- void printArray(){
- for(int i=1;i<n;i++){
- pref[i]=pref[i]+pref[i-1];
- }
- for(int i=0;i<n;i++){
- a[i]=a[i]+pref[i];
- }
- cout<<"pref\n";
- for(int i=0;i<n;i++){
- cout<<pref[i]<<" ";
- }
- cout<<endl;
- cout<<"array\n";
- for(int i=0;i<n;i++){
- cout<<a[i]<<" ";
- }
- cout<<endl;
- }
- int main(){
- //int n;
- cin>>n;
- for(int i=0;i<n;i++){
- cin>>a[i];
- }
- while(1){
- int choice;
- cout<<"Enter choice= \n";
- cin>>choice;
- if(choice==1){
- int l,r,x;
- cin>>l>>r>>x;
- update(l,r,x);
- }
- else{
- printArray();
- memset(pref,0,sizeof(pref));
- }
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment