 # Array Range Query Updation

Below is the link of the Question

my solution

https://www.codechef.com/viewsolution/42430995

If anyone can figure out What’s wrong with my code plz tell me .

Apparently the brute force solution got accepted and this one didn’t lol… 1 Like

I also got amazed by seeing the accepted solutions .
How ???
Also this solution didn’t get accepted , Isn’t it strange ?

I’ve just done a spot-check of the accepted solutions, and they all seem to use `int`s as the underlying type, rather than `long long`, raising the possibility that the Editorial solution is wrong (overflows) and so, in turn, are the testcases.

Maybe try again, without the `#define ll long long`.

Edit:

Or based on these two, it might just be that you have to have a line break after printing your array 2 Likes
2. You are not re-initializing your global vectors with zeroes (Don’t use Global variables unless it’s unavoidable)
YOUR_AC_CODE
``````#include <bits/stdc++.h>
#define ll long long
using namespace std ;

vector <ll> a(100005,0) ;
vector <ll> update(100010,0) ;

void print ( ll n ) {
ll count = 0 ;
for ( ll i = 1 ; i <= n ; i++ ) {
count += update[i] ;
cout << a[i]+count << " " ;
}
cout << '\n' ;
}

void Update ( ll l , ll r , ll x ) {
update[l] += x ;
update[r+1] -= x ;
}

void solve () {
ll n = 0 ;
cin >> n ;

for ( int i = 1 ; i <= n ; i++ ) {
cin >> a[i] ;
}

ll q = 0 ; cin >> q ;
string ls ;
ll l , r , x ;
for ( int i = 0 ; i < q ; i++ ) {
cin >> ls ;
if ( ls == "U" ) {
print ( n ) ;
}
else {
l = stoll(ls) ;
cin >> r >> x ;
Update ( l , r , x ) ;
}
}
update.assign(n+1,0) ;
}

int main()
{
int t = 0 ; cin >> t ;
while ( t-- ) {
solve() ;
}
return 0;
}
``````
2 Likes

Learnt New thing .
Thx @cubefreak777 @ssjgz

2 Likes