-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathB_Even-Odd_Increments.cpp
73 lines (69 loc) · 1.46 KB
/
B_Even-Odd_Increments.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#include<bits/stdc++.h>
using namespace std;
#define mod 1000000007 // 1e9+7
#define ll long long int
#define read(arr, n) for(ll i=0; i<n; i++) cin>>arr[i];
#define print(arr, n) for(ll i=0; i<n; i++) cout<<arr[i]<<' '; cout<<endl;
#define fori(s,e,g) for(ll i=s; i<=e; i+=g)
#define ford(s,e,g) for(ll i=s; i>=e; i-=g)
#define p(temp) cout<<temp<<endl
ll sum(ll arr[],ll n) {ll sum=0; for(ll i=0; i<n; i++) sum+=arr[i]; return sum;}
ll maxi(ll arr[],ll n) {ll maxi= -1000000000000; for(ll i=0; i<n; i++) if(maxi<arr[i])maxi=arr[i]; return maxi;}
ll mini(ll arr[],ll n) {ll mini= 1000000000000; for(ll i=0; i<n; i++) if(mini>arr[i])mini=arr[i]; return mini;}
void print_vect(vector < ll > &vect) {for(auto it: vect) cout<<it<<' '; cout<<endl; }
// space for helper functions
int main()
{
ll tc;
cin>>tc;
while(tc--)
{
// your testcases here
ll n,q;
cin>>n>>q;
ll arr[n];
read(arr, n);
ll so=0,se=0,on=0, en=0;
fori(0,n-1, 1)
{
if(arr[i]%2==1)
{
on++;
so+=arr[i];
}
else
{ en++;
se+=arr[i];
}
}
while(q--)
{
ll flag,num;
cin>>flag>>num;
if(flag)
{
so+=(on*num);
if(num%2==1)
{
se+=so;
so=0;
en+=on;
on=0;
}
}
else
{
se+=(en*num);
if(num%2==1)
{
so+=se;
se=0;
on+=en;
en=0;
}
}
p(so+se);
}
}
return 0;
}