-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxor_ninja.cpp
More file actions
115 lines (73 loc) · 2.48 KB
/
xor_ninja.cpp
File metadata and controls
115 lines (73 loc) · 2.48 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
/* Enter your code here. Read input from STDIN. Print output to STDOUT */
int T, N;
vector<long int> storage[2];
vector<int> counter[2];
vector<long int> input;
cin >> T;
for (int t = 0; t < T; t++) {
// Get number of input integers N
cin >> N;
cin.ignore();
// cout << "N is " << N << endl;
input.clear();
storage[0].clear();
storage[1].clear();
counter[0].clear();
counter[1].clear();
long int temp;
long int result = 0;
string line;
std::getline(cin, line);
istringstream lineStream(line);
// for (int num = 0; num < N; num++) {
while ( lineStream >> temp ) {
// Get input in input vector, storage[0] and acculmulate their sum in result
// cin >> temp;
input.push_back(temp);
storage[0].push_back(temp);
result += temp;
}
storage[0].pop_back();
for (int i = N-1; i > 0; i--) {
counter[0].push_back(i);
}
int read ;
int write;
for (int i = 0; i < N-1; i++) {
// For all length of inputs
// For access of storage vectors
read = i & 1;
write = (i+1) & 1;
storage[write].clear();
counter[write].clear();
int curr_read_size = storage[read].size();
/*cout << "i is " << i << endl;
cout << "read is " << read << endl;
cout << "read size is " << storage[read].size() << endl;
*/
for (int j = 0; j <= curr_read_size - 1 ; j++) {
for ( int k = N-counter[read].at(j); k < N; k++ ) {
long int temp2 = storage[read].at(j) ^ input[k];
// cout << i << "\t" << j << "\t" << N-1-k << endl;
result += temp2;
if (k != N-1) {
storage[write].push_back(temp2);
// cout << "Pushing" << N-1-k << endl;
counter[write].push_back(N-1-k);
}
}
}
}
cout << result % (1000000000+7) << endl;
}
return 0;
}