Hello @anonymousins,
After so many complaints about many people having WA veredict, I decided to double check the test cases and unfortunately, one of the files is oddly formatted, with the 1st query being used directly after the input array.
Sadly, this was not detected by any of the 4 people who tested the problem (!!!), and, when I wrote it, I obviously had confidence on it and I also believe more people looked at some of my test case generators, so, it still remains a mystery to me as how this slipped trough…
However, having over 1500 successful submissions, probably also indicates that this was not a very “serious” bug, as many, many people possibly thought alike me and the testers…
All I can do now, besides being sorry, is to leave here my solution as a reference:
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <math.h>
#include <numeric>
#include <stdio.h>
using namespace std;
inline int lowbit(int & i) { return (i & -i); }
void update(vector<long long int> & T, int i, long long int value)
{
for(; i < T.size(); i+= lowbit(i))
T[i] += value;
}
void build(vector<long long int> & T, vector<long long int> & A)
{
for(int i=0; i < A.size(); i++) update(T, i+1, A[i]);
}
inline long long int sum(vector<long long int> & T, int i)
{
long long int value = 0LL;
for(; i > 0; i-= lowbit(i)) value+= T[i];
return value;
}
inline long long int sum(vector<long long int> & T, int i, int j)
{
return i > 1 ? sum(T,j) - sum(T,i-1) : sum(T,j);
}
int main()
{
int N,Q;
scanf("%d %d",&N, &Q);
vector<long long int> v(N);
vector<long long int> t(N+1);
for(int i = 0; i < N; i++)
scanf("%lld",&v[i]);
build(t,v);
for(int i = 0; i < Q; i++)
{
string s;
cin >> s;
if(s=="G")
{
int ind;
long long int val;
scanf("%d %lld",&ind, &val);
update(t,ind+1,val);
}
if(s=="T")
{
int ind;
long long int val;
scanf("%d %lld",&ind, &val);
update(t,ind+1,-1*val);
}
if(s=="S")
{
int low, high;
scanf("%d %d",&low, &high);
long long int x = sum(t,low+1,high+1);
printf("%lld\n",x);
}
}
return 0;
}
As I’ve said earlier, it’s terrible that such big mistake happened, and, it’s of no use to try to find excuses for this…
I’m sorry to everyone who was affected in a more serious way (Python users!!! Sorry guys!!)…
I guess it’s fate telling me to take a break of setting problems for a while…
Best,
Bruno