Submission #11171718


Source Code Expand

Copy
#include <bits/stdc++.h>
#include <cmath>

const double PI = 3.14159265358979323846;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//typedef pair<ll, ll> P;
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
//const ll mod = 1e10;
typedef priority_queue<string, vector<string>, greater<string> > PQ_ASK;

#include <iostream>
#include <vector>

using namespace std;

void tow_pointer(int n,
                 function<bool(int left)> check_begin,
                 function<void(int left)> begin,
                 function<bool(int right)> check_right,
                 function<void(int right)> push_right,
                 function<void(int left)> pop_left,
                 function<void(int left, int right)> dead_end
) {

    auto go = [&](P range) {
        int right = -1;
        for (int left = range.first; left <= range.second; left++) {
            if (right < left) {
                right = left;
                begin(left);
            }
            while (right + 1 <= range.second && check_right(right + 1)) {
                right++;
                push_right(right);
            }
            dead_end(left, right);
            pop_left(left);
        }
    };


    auto get_ranges = [&] {
        vector<bool> enable_items(n);
        rep(i, n) enable_items[i] = check_begin(i);

        auto start = [&](int i) {
            if (i == 0) {
                return enable_items[i] == true;
            }
            if (!enable_items[i - 1] && enable_items[i]) {
                return true;
            }
            return false;
        };

        auto end = [&](int i) {

            if (i == n - 1) {
                return enable_items[i] == true;
            }

            if (enable_items[i] && !enable_items[i + 1]) {
                return true;
            }

            return false;
        };

        vector<P> ans;
        P p;
        rep(i, n) {
            if (start(i)) {
                p = P(i, -1);
            }
            if (end(i)) {
                p.second = i;
                ans.push_back(p);
            }
        }
        return ans;
    };


    vector<P> ranges = get_ranges();
    for (P range: ranges) go(range);
}


int main() {
    int n;
    cin >> n;
    set<ll> sweets;
    vector<ll> numbers(n);
    rep(i, n) cin >> numbers[i];

    ll sum = 0;
    auto check_begin = [&](int i) {
        return true;
    };

    auto begin = [&](int i) {
        sum = numbers[i];
    };

    auto check_right = [&](int right) {
        return (sum + numbers[right]) == (sum ^ numbers[right]);
    };

    auto push_right = [&](int right) {
        sum += numbers[right];

    };
    auto pop_left = [&](int left) {
        sum -= numbers[left];

    };

    ll ans = 0;

    auto dead_end = [&](int left, int right) {
        ll now = right - left + 1;
        ans += now;
    };


    tow_pointer(
            n,
            check_begin,
            begin,
            check_right,
            push_right,
            pop_left,
            dead_end
    );
    cout << ans << endl;

}

Submission Info

Submission Time
Task D - Xor Sum 2
User riku_tanide
Language C++14 (GCC 5.4.1)
Score 500
Code Size 3958 Byte
Status
Exec Time 65 ms
Memory 1920 KB

Test Cases

Set Name Score / Max Score Test Cases
Sample 0 / 0 sample_01.txt, sample_02.txt, sample_03.txt
All 500 / 500 sample_01.txt, sample_02.txt, sample_03.txt, sample_01.txt, sample_02.txt, sample_03.txt, subtask_1_01.txt, subtask_1_02.txt, subtask_1_03.txt, subtask_1_04.txt, subtask_1_05.txt, subtask_1_06.txt, subtask_1_07.txt, subtask_1_08.txt, subtask_1_09.txt, subtask_1_10.txt, subtask_1_11.txt, subtask_1_12.txt, subtask_1_13.txt, subtask_1_14.txt, subtask_1_15.txt, subtask_1_16.txt, subtask_1_17.txt, subtask_1_18.txt, subtask_1_19.txt, subtask_1_20.txt, subtask_1_21.txt, subtask_1_22.txt, subtask_1_23.txt, subtask_1_24.txt, subtask_1_25.txt, subtask_1_26.txt, subtask_1_27.txt, subtask_1_28.txt, subtask_1_29.txt, subtask_1_30.txt, subtask_1_31.txt, subtask_1_32.txt
Case Name Status Exec Time Memory
sample_01.txt 1 ms 256 KB
sample_02.txt 1 ms 256 KB
sample_03.txt 1 ms 256 KB
subtask_1_01.txt 1 ms 256 KB
subtask_1_02.txt 1 ms 256 KB
subtask_1_03.txt 30 ms 1536 KB
subtask_1_04.txt 2 ms 256 KB
subtask_1_05.txt 26 ms 1152 KB
subtask_1_06.txt 24 ms 768 KB
subtask_1_07.txt 2 ms 256 KB
subtask_1_08.txt 23 ms 896 KB
subtask_1_09.txt 28 ms 1280 KB
subtask_1_10.txt 37 ms 1408 KB
subtask_1_11.txt 36 ms 1536 KB
subtask_1_12.txt 54 ms 1664 KB
subtask_1_13.txt 12 ms 768 KB
subtask_1_14.txt 10 ms 640 KB
subtask_1_15.txt 15 ms 896 KB
subtask_1_16.txt 2 ms 256 KB
subtask_1_17.txt 39 ms 1792 KB
subtask_1_18.txt 38 ms 1792 KB
subtask_1_19.txt 46 ms 1792 KB
subtask_1_20.txt 65 ms 1920 KB
subtask_1_21.txt 45 ms 1792 KB
subtask_1_22.txt 56 ms 1792 KB
subtask_1_23.txt 43 ms 1792 KB
subtask_1_24.txt 52 ms 1792 KB
subtask_1_25.txt 45 ms 1792 KB
subtask_1_26.txt 58 ms 1792 KB
subtask_1_27.txt 36 ms 1792 KB
subtask_1_28.txt 36 ms 1792 KB
subtask_1_29.txt 36 ms 1792 KB
subtask_1_30.txt 37 ms 1792 KB
subtask_1_31.txt 37 ms 1792 KB
subtask_1_32.txt 37 ms 1792 KB