#include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include typedef long long ll; using namespace std; #ifndef LOCAL #define debug(x) ; #else #define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl; template ostream &operator<<(ostream &out, const pair &p) { out << "{" << p.first << ", " << p.second << "}"; return out; } template ostream &operator<<(ostream &out, const vector &v) { out << '{'; for (const T &item : v) out << item << ", "; out << "\b\b}"; return out; } #endif #define mod 1000000007 //1e9+7(prime number) #define INF 1000000000 //1e9 #define LLINF 2000000000000000000LL //2e18 #define SIZE 200010 /* Binary Indexed Tree(0-index) */ template struct BIT{ int bit_size; vector data; BIT(int n){ bit_size = n; data.assign(n+2, 0); } //add x to kth value void add(int k, Type x){ k++; while(k <= bit_size){ data[k] += x; k += k & (-k); } } //sum of [0,k) Type query(int k){ Type rec = 0; while(k > 0){ rec += data[k]; k -= k & (-k); } return rec; } //sum of [a, b) Type query(int a, int b){ return query(b) - query(a); } }; int main(){ int N, Q, a[SIZE], d[SIZE]; scanf("%d%d", &N, &Q); for(int i=0; i 0) d[i-1] = a[i-1] - a[i]; } N--; BIT bit(N+1); for(int i=0; i 0) { bit.add(a-1, -!!d[a-1]); d[a-1] += x; bit.add(a-1, !!d[a-1]); } { bit.add(b, -!!d[b]); d[b] -= x; bit.add(b, !!d[b]); } for(int j=0; j