Codeforces Round 828 (Div. 3) 1744B - Even-Odd Increments Solution
Problem Link : https://codeforces.com/contest/1744/problem/B
Solution in C++:
- /// Author : AH_Tonmoy
- #include<bits/stdc++.h>
- using namespace std;
- int32_t main() {
- ios_base::sync_with_stdio(0);
- cin.tie(0);
- int t; cin >> t;
- while (t--) {
- int n , q ;
- cin >> n >> q ;
- std::vector<int> a(n);
- long long sum = 0 ;
- int cnt0 = 0 , cnt1 = 0 ;
- for ( int i = 0 ; i < n ; i++) {
- cin >> a[i] ;
- sum += a[i] ;
- if ( a[i] % 2 == 0) cnt0++ ;
- else cnt1++ ;
- }
- while ( q --) {
- int x , v ;
- cin >> x >> v ;
- if ( x == 0 ) {
- if ( v % 2 == 0){
- sum +=(v*cnt0) ;
- }
- else {
- sum +=(v*cnt0) ;
- cnt1 = n ;
- cnt0 = 0 ;
- }
- }
- else {
- if ( v % 2 == 0){
- sum +=(v*cnt1) ;
- }
- else {
- sum +=(v*cnt1) ;
- cnt0 = n ;
- cnt1 = 0 ;
- }
- }
- cout << sum <<"\n";
- }
- }
- return 0 ;
- }
No comments