-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcode.cpp
87 lines (60 loc) · 1.31 KB
/
code.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <unistd.h>
#include <utility>
#include <vector>
using namespace std;
#include <climits>
typedef unsigned long long uint64;
#define get getchar_unlocked
#define repeat(n) for (int i = (1); i <= n; i++)
#define ZERO(v) memset((v), 0, sizeof (v))
#define ALL(x) (x).begin(), (x).end()
inline long long int scan2(){
long long int n=0,s=1;
char p=get();
if(p=='-') s=-1;
while((p<'0'||p>'9')&&p!=EOF&&p!='-') p=get();
if(p=='-') s=-1,p=get();
while(p>='0'&&p<='9') { n = (n<< 3) + (n<< 1) + (p - '0'); p=get(); }
return n*s;
}
long long int a[20000] = {0};
long long int f(long long int n,long long int k,long long int ans,string op){
for(int i=1;i<=k;i++){
for(int j=1;j<=n;j++){
if(op.compare("OR") == 0)
ans = ans | a[j];
else if(op.compare("AND") == 0)
ans = ans & a[j];
else if(op.compare("XOR") == 0)
ans = ans^a[j];
}
}
return ans;
}
int main(){
long long int rounds = 0;
long long n,k,ans;
string operato;
rounds = scan2();
while(rounds--){
n =scan2();
k =scan2();
ans = scan2();
repeat(n){
a[i] = scan2();
}
cin >> operato;
cout << f(n,k,ans,operato) << "\n";
ans = 0;
ZERO(a);
n = 0;
k = 0;
}
return 0;
}