Codeforces Round 828 (Div. 3) 1744B - Even-Odd Increments Solution


 

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

Solution in C++:

  1. /// Author : AH_Tonmoy
  2. #include<bits/stdc++.h>
  3. using namespace std;
  4. int32_t main() {
  5. ios_base::sync_with_stdio(0);
  6. cin.tie(0);
  7. int t; cin >> t;
  8. while (t--) {
  9. int n , q ;
  10. cin >> n >> q ;
  11. std::vector<int> a(n);
  12. long long sum = 0 ;
  13. int cnt0 = 0 , cnt1 = 0 ;
  14. for ( int i = 0 ; i < n ; i++) {
  15. cin >> a[i] ;
  16. sum += a[i] ;
  17. if ( a[i] % 2 == 0) cnt0++ ;
  18. else cnt1++ ;
  19. }
  20. while ( q --) {
  21. int x , v ;
  22. cin >> x >> v ;
  23. if ( x == 0 ) {
  24. if ( v % 2 == 0){
  25. sum +=(v*cnt0) ;
  26. }
  27. else {
  28. sum +=(v*cnt0) ;
  29. cnt1 = n ;
  30. cnt0 = 0 ;
  31. }
  32. }
  33. else {
  34. if ( v % 2 == 0){
  35. sum +=(v*cnt1) ;
  36. }
  37. else {
  38. sum +=(v*cnt1) ;
  39. cnt0 = n ;
  40. cnt1 = 0 ;
  41. }
  42. }
  43. cout << sum <<"\n";
  44. }
  45. }
  46. return 0 ;
  47. }

No comments

Most View Post

Recent post

Codeforces Round 925 (Div. 3) 1931D. Divisible Pairs Solution

    Problem Link  :   https://codeforces.com/contest/1931/problem/D S olution in C++: /// Author : AH_Tonmoy #include < bits / stdc ++. ...

Powered by Blogger.