315B - Sereja and Array - CodeForces Solution


implementation *1200

Please click on ads to support us..

Python Code:

_, m = map(int, input().split(" "))
valores = list(map(int, input().split(" ")))
acumulador_de_incrementos = 0

for _ in range(m):
    operacao = list(map(int, input().split(" ")))
    
    if operacao[0] == 1:
        valores[operacao[1] - 1] = operacao[2] - acumulador_de_incrementos
    elif operacao[0] == 2:
        acumulador_de_incrementos += operacao[1]
    else:
        print(valores[operacao[1] - 1] + acumulador_de_incrementos)
        
        
        

C++ Code:

#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <map>
#include <queue>
#include <deque>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <chrono>
#include <cstring>

#define INF 10000000000
#define MOD 1000000007

#define ll long long
#define pb push_back
#define pf push_front
#define mp make_pair

#define rep(i, n) for(int i = 0; i < n; ++i)
#define dbg(x) cerr << x << endl;

//author: @u_d_ash_

using namespace std;
using namespace std::chrono;


int main(){
    auto start = high_resolution_clock::now();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    //code here
    ll n, m;
    cin >> n >> m;
    vector<ll> vec;
    vector<ll> ex(n, 0);
    ll count = 0;
    rep(i, n){
        ll x;
        cin >> x;
        vec.pb(x);
    }
    rep(i, m){
        ll a;
        cin >> a;
        if(a == 1){
            ll v, x;
            cin >> v >> x;
            ex[v - 1] = (x - (vec[v - 1] + count));
        }else if(a == 2){
            ll y;
            cin >> y;
            count += y;
        }else{
            ll q;
            cin >> q;
            cout << vec[q - 1] + ex[q - 1] + count << endl;
        }
    }



    auto stop = high_resolution_clock::now();
    auto dur = duration_cast<milliseconds>(stop - start);
    cerr << dur.count();
}


Comments

Submit
0 Comments
More Questions

Split houses
Divisible
Three primes
Coprimes
Cost of balloons
One String No Trouble
Help Jarvis!
Lift queries
Goki and his breakup
Ali and Helping innocent people
Book of Potion making
Duration
Birthday Party
e-maze-in
Bricks Game
Char Sum
Two Strings
Anagrams
Prime Number
Lexical Sorting Reloaded
1514A - Perfectly Imperfect Array
580A- Kefa and First Steps
1472B- Fair Division
996A - Hit the Lottery
MSNSADM1 Football
MATCHES Playing with Matches
HRDSEQ Hard Sequence
DRCHEF Doctor Chef
559. Maximum Depth of N-ary Tree
821. Shortest Distance to a Character