Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- using ll = long long;
- void solve() {
- /*********
- * Inputs *
- *********/
- int n; cin >> n;
- int q; cin >> q; //q is 1
- int arr[n];
- for (int i = 0; i < n; i++) {
- cin >> arr[i];
- }
- /********
- * Calcs *
- ********/
- ll tSum = 0; //total sum
- ll tXor = 0; //total xor
- ll tMax; //max value
- for (int i = 0; i < n; i++) {
- tSum += arr[i];
- tXor ^= arr[i];
- }
- tMax = tSum - tXor;
- if (tMax == 0) {
- cout << "1 1\n";
- return;
- }
- //
- ll cSum = tSum;
- ll cXor = tXor;
- ll cMax = tMax;
- int e1 = 0; // inclusive bound
- int e2 = n-1; // inclusive bound
- for (int i = n-1; i > -1; i--) {
- cSum -= arr[i];
- cXor ^= arr[i];
- cMax = cSum - cXor;
- if (cMax == tMax) {
- e2--;
- } else {
- cSum += arr[i];
- cXor ^= arr[i];
- cMax = cSum - cXor;
- break;
- }
- }
- //
- for (int i = 0; i < n; i++) {
- cSum -= arr[i];
- cXor ^= arr[i];
- cMax = cSum - cXor;
- if (cMax == tMax) {
- e1++;
- } else {
- cSum += arr[i];
- cXor ^= arr[i];
- cMax = cSum - cXor;
- break;
- }
- }
- /**
- for (int rb = e2+1; rb < n; rb++) {
- cSum += arr[rb];
- cXor ^= arr[rb];
- cMax = cSum - cXor;
- while (cMax == tMax) {
- e1++;
- }
- }**/
- cout << e1+1 << " " << e2+1 << "\n";
- }
- int main() {
- int t; cin >> t;
- for (int i = 0; i < t; i++) {
- solve();
- int a; cin >> a; cin >> a;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement