Codeforces Round #791 (Div. 2) 1679B. Stone Age Problem Solution



 Problem Link:  https://codeforces.com/contest/1679/problem/B

Solve in C++:  

///La ilaha illellahu muhammadur rasulullah
///******Bismillahir-Rahmanir-Rahim******///
///Abul Hasnat  Tonmoy
///Department of CSE,23rd batch
///Islamic University,Bangladesh
///**********ALLAH IS ALMIGHTY************///
#include<bits/stdc++.h>
using namespace std;
map<long long,long long>mp;
int main()
{
    long long  t,n,i,a,b,c,q,k,s=0;
    cin>>n>>q;
    for(i=1; i<=n; i++)
    {
        cin>>mp[i];
        s+=mp[i];
    }
    while(q--)
    {
        cin>>k;
        if(k==1)
        {
            cin>>a>>b;
            if(mp.find(a)==mp.end())
            {
                mp[a]=c;
            }
            s-=mp[a];
            mp[a]=b;
            s+=mp[a];
            cout<<s<<endl;
        }
        else
        {
            cin>>c;
            s=n*c;
            cout<<s<<endl;
            mp.clear();
        }
    }
}
 


No comments

Most View Post

Recent post

Codeforces Round 971 (Div. 4) 2009C. The Legend of Freya the Frog Solution

  Problem Link    https://codeforces.com/contest/2009/problem/C S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. h &g...

Powered by Blogger.