結果

問題 No.1493 隣接xor
ユーザー sapphire__15sapphire__15
提出日時 2021-04-30 22:27:56
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 146 ms / 2,000 ms
コード長 4,963 bytes
コンパイル時間 1,272 ms
コンパイル使用メモリ 133,460 KB
実行使用メモリ 15,136 KB
最終ジャッジ日時 2023-09-26 06:39:30
合計ジャッジ時間 5,328 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
4,380 KB
testcase_01 AC 1 ms
4,376 KB
testcase_02 AC 1 ms
4,380 KB
testcase_03 AC 145 ms
14,864 KB
testcase_04 AC 145 ms
14,712 KB
testcase_05 AC 143 ms
14,924 KB
testcase_06 AC 144 ms
14,836 KB
testcase_07 AC 144 ms
14,860 KB
testcase_08 AC 142 ms
15,136 KB
testcase_09 AC 145 ms
15,036 KB
testcase_10 AC 145 ms
14,940 KB
testcase_11 AC 146 ms
14,712 KB
testcase_12 AC 143 ms
15,032 KB
testcase_13 AC 87 ms
5,512 KB
testcase_14 AC 36 ms
5,396 KB
testcase_15 AC 1 ms
4,380 KB
testcase_16 AC 2 ms
4,380 KB
testcase_17 AC 1 ms
4,376 KB
testcase_18 AC 2 ms
4,376 KB
testcase_19 AC 1 ms
4,376 KB
testcase_20 AC 64 ms
8,900 KB
testcase_21 AC 72 ms
9,480 KB
testcase_22 AC 48 ms
7,212 KB
testcase_23 AC 67 ms
9,116 KB
testcase_24 AC 140 ms
14,940 KB
testcase_25 AC 47 ms
7,184 KB
testcase_26 AC 78 ms
9,832 KB
testcase_27 AC 32 ms
6,304 KB
testcase_28 AC 131 ms
14,820 KB
testcase_29 AC 82 ms
9,932 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <cmath>
#include <complex>
#include <functional>
#include <cassert>
#include <stack>
#include <numeric>
#include <iomanip>
#include <limits>
#include <random>
#include <unordered_map>

typedef int64_t ll;
typedef std::pair<int, int> Pii;
typedef std::pair<ll, ll> Pll;
typedef std::pair<double, double> Pdd;

#define rip(_i, _n, _s) for (int _i = (_s); _i < (int)(_n); _i++)
#define all(_l) _l.begin(), _l.end()
#define rall(_l) _l.rbegin(), _l.rend()
#define MM << " " <<

template<typename _T>
using MaxHeap = std::priority_queue<_T>;
template<typename _T>
using MinHeap = std::priority_queue<_T, std::vector<_T>, std::greater<_T>>;

template<typename _T>
inline bool chmax(_T &_l, const _T _b) {
    if (_l < _b) {
        _l = _b;
        return true;
    }
    return false;
}
template<typename _T>
inline bool chmin(_T &_l, const _T _b) {
    if (_l > _b) {
        _l = _b;
        return true;
    }
    return false;
}

template<typename _T>
void vdeb(const std::vector<_T> &bb) {
    for (unsigned int i = 0;i < bb.size();i++) {
        if (i == bb.size() - 1) std::cout << bb[i];
        else std::cout << bb[i] << ' ';
    }
    std::cout << '\n';
}
template<typename _T>
void vdeb(const std::vector<std::vector<_T>> &bb) {
    for (unsigned int i = 0;i < bb.size();i++) {
        // std::cout << i << ' ';
        vdeb(bb[i]);
    }
    std::cout << '\n';
}

struct modint {
    long long num;
    const static long long p = 1000000007;
    static long long pow(long long n, long long k) {//n^k(mod p)
        long long ret = 1;
        while(k) {
            if(k&1) ret = ret * n % p;
            n = n * n % p;
            k >>= 1;
        }
        return ret;
    }
    // a*A + b*B = 1
    static void euclid(long long &a, long long &b) { // a>=b A*b+B*(a-a/b*b)=1
        if (a == 1) {
            a = 1;
        }
        else {
            long long A = b, B = a % b;
            euclid(A, B);
            b = (A - (p + a / b) % p * B % p + p) % p;
            a = B;
        }
    }
    static long long rev(const long long n) {// n*x-p*y=1
        //long long q = p;
        //euclid(p, n, p);
        //return n % q;
        return pow(n,p-2);
    }
    modint() {
        num = 0;
    }
    modint(long long x) {
        num = (x%p+p) % p;
    }
    modint inv() const{return rev(num);}
    modint operator-() const{return modint(p-num);}
    modint& operator+=(const modint &other){
        num = (num + other.num) % p;
        return *this;
    }
    modint& operator-=(const modint &other){
        num = (num - other.num + p) % p;
        return *this;
    }
    modint& operator*=(const modint &other){
        num = (num * other.num) % p;
        return *this;
    }
    modint& operator/=(const modint &other){
        (*this) *= other.inv();
        return *this;
    }
    modint& operator+=(const long long &other){
        num = (num + other) % p;
        return *this;
    }
    modint& operator-=(const long long &other){
        num = (num - other + p) % p;
        return *this;
    }
    modint& operator*=(const long long &other){
        num = (num * other) % p;
        return *this;
    }
    modint& operator/=(const long long &other){
        (*this) *= rev(other);
        return *this;
    }
    modint& operator++(){return *this += 1;}
    modint& operator--(){return *this -= 1;}
    modint& operator=(const long long &other){return (*this) = modint(other);}
    modint operator+(const modint &other) const{return modint(*this) += other;}
    modint operator-(const modint &other) const{return modint(*this) -= other;}
    modint operator*(const modint &other) const{return modint(*this) *= other;}
    modint operator/(const modint &other) const{return modint(*this) /= other;}
    modint operator+(const long long &other) const{return modint(*this) += other;}
    modint operator-(const long long &other) const{return modint(*this) -= other;}
    modint operator*(const long long &other) const{return modint(*this) *= other;}
    modint operator/(const long long &other) const{return modint(*this) /= other;}
    bool operator==(const modint &other) const{return num == other.num;}
};
std::istream& operator>>(std::istream &is, modint x) {
    is >> x.num;
    return is;
}
std::ostream& operator<<(std::ostream &os, const modint &x){
    os << x.num;
    return os;
}

using namespace std;

int main() {
    int n; cin >> n;
    vector<int> da(n);
    rip(i,n,0) cin >> da[i];
    // bool flg = true;
    // rip(i,n,0) flg = flg & (da[i] == 0);
    // if(flg) {
    //     cout << n << endl;
    //     return 0;
    // }
    unordered_map<int, modint> mp;
    vector<modint> dp(n+1);
    int xo = 0;
    modint su(1);
    rip(i,n,0) {
        xo ^= da[i];
        dp[i+1] += su - mp[xo];
        mp[xo] += dp[i+1];
        su += dp[i+1];
    }
    cout << mp[xo] << endl;
}
0