結果

問題 No.1493 隣接xor
ユーザー hamamuhamamu
提出日時 2021-04-30 23:32:36
言語 C++17
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 163 ms / 2,000 ms
コード長 9,508 bytes
コンパイル時間 4,255 ms
コンパイル使用メモリ 274,760 KB
実行使用メモリ 21,992 KB
最終ジャッジ日時 2024-07-19 03:42:35
合計ジャッジ時間 8,427 ms
ジャッジサーバーID
(参考情報)
judge3 / judge2
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 2 ms
5,248 KB
testcase_01 AC 2 ms
5,376 KB
testcase_02 AC 2 ms
5,376 KB
testcase_03 AC 154 ms
21,988 KB
testcase_04 AC 153 ms
21,988 KB
testcase_05 AC 156 ms
21,988 KB
testcase_06 AC 158 ms
21,984 KB
testcase_07 AC 160 ms
21,988 KB
testcase_08 AC 161 ms
21,992 KB
testcase_09 AC 156 ms
21,988 KB
testcase_10 AC 158 ms
21,988 KB
testcase_11 AC 163 ms
21,860 KB
testcase_12 AC 157 ms
21,988 KB
testcase_13 AC 40 ms
10,856 KB
testcase_14 AC 29 ms
10,980 KB
testcase_15 AC 2 ms
5,376 KB
testcase_16 AC 2 ms
5,376 KB
testcase_17 AC 2 ms
5,376 KB
testcase_18 AC 1 ms
5,376 KB
testcase_19 AC 1 ms
5,376 KB
testcase_20 AC 67 ms
12,776 KB
testcase_21 AC 79 ms
14,184 KB
testcase_22 AC 51 ms
10,980 KB
testcase_23 AC 66 ms
13,156 KB
testcase_24 AC 142 ms
21,216 KB
testcase_25 AC 50 ms
10,724 KB
testcase_26 AC 86 ms
14,948 KB
testcase_27 AC 31 ms
8,160 KB
testcase_28 AC 134 ms
20,064 KB
testcase_29 AC 87 ms
15,456 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

using namespace std;
#if !defined(INCLUDED_MAIN)
#define INCLUDED_MAIN
#include __FILE__


template <class T> struct CumulativeSumG{
	ll s=0,e=-1;  vector<T> c;
	CumulativeSumG(){}
	CumulativeSumG(vector<T> &v): e(v.size()-1),c(e+2) { Ini(v); }
	CumulativeSumG(vector<T> &v,ll S,ll E): s(S),e(E),c(e-s+2){ Ini(v); }
	void init(vector<T> &v){ e=v.size()-1; c.resize(e+2); Ini(v); }
	void init(vector<T> &v,ll S,ll E){ s=S; e=E; c.resize(e-s+2); Ini(v); }
	void add(T x) { e++; c.push_back(c.back() + x); }
	T operator()(ll l,ll r){ return c[max(min(e,r),s-1)+1-s]-c[min(max(s,l),e+1)-s]; }
	void Ini(vector<T> &v) { rep(i,s,e) c[i+1-s] = c[i-s] + v[i]; }
};
using CumulativeSum = CumulativeSumG<mll>;
/*
CumulativeSum cm(ini); //iniの累積和準備
CumulativeSum cm(ini,4,10); //ini[4]~ini[10]の累積和準備
cm.add(93); //末尾に93を追加準備(上の続きならini[11]=93と見なして累積和準備)
ll sm=cm(5,9); //ini[5]~ini[9]の和
ll sm=cm(4,2); //定義外は0埋めと見なす&逆順は正負反転するだけで落ちない
*/

#if defined(_DEBUG)
ll dumpW = 5;
template<class T> void dump(vector<T> &v){
	rep(i,0,sz(v)-1) { cerr << ((i==0)?"[":" ") << setw(dumpW) << v[i]; }  cerr << "]";
}
void dump(vll &v){
	rep(i,0,sz(v)-1) {
		cerr << ((i==0)?"[":" ") << setw(dumpW);
		if (v[i] == INF) cerr << "INF";
		else if (v[i] == -INF) cerr << "-INF";
		else                   cerr << v[i];
	}  cerr << "]";
}
template<class T> void dump(vector<vector<T>> &v){
	ll N=(ll)v.size();  string d[2][2]={{" ", "["},  {"\n", "]\n"}};
	rep(i,0,N-1) { cerr << d[0][i==0];  dump(v[i]);  cerr << d[1][i==N-1]; }
}
template<class T> void dump(vector<vector<vector<T>>> &v){
	ll N=(ll)v.size();  string d[2]={"  <", "[ <"};
	rep(i,0,N-1) { cerr << d[i==0] << i << ">\n"; dump(v[i]); }  cerr << "]\n";
}
template<class T> void dump(vector<vector<vector<vector<T>>>> &v){
	ll N=(ll)v.size();  string d[2]={"  ---<", "[ ---<"};
	rep(i,0,N-1) { cerr << d[i==0] << i << ">---\n"; dump(v[i]); }  cerr << "]\n";
}
template<class T> void dump(vector<vector<vector<vector<vector<T>>>>> &v){
	ll N=(ll)v.size();  string d[2]={"  ======<", "[ ======<"};
	rep(i,0,N-1) { cerr << d[i==0] << i << ">======\n"; dump(v[i]); }  cerr << "]\n";
}
template<class T,class S> void dump(map<T,S> &m){
	for (auto e: m) cout << e.first << " : " << e.second << '\n';
}
#else
template<class T> void dump(T &v){}
#endif

void solve()
{
	ll n;
	cin >> n;

	vector<ll> a;
	rep(i,0,n-1){ ll a__; cin>>a__; a.push_back(a__); }

	vll b=a;
	rep(i,1,n-1){
		b[i]^=b[i-1];
	}

	vmll dp_(n);
	auto dp = [&](ll i)->mll&{
		static mll dmy=0;
		return dp_[i];
	};
	dp(0)=1;
	CumulativeSum cm(dp_,0,0);
	map<ll,ll> mp;

	rep(i,0,n-2){
		ll val=b[i];
		ll idx;
		if (mp.count(val)==0){
			idx=-1;
		}
		else{
			idx=mp[val];
		}
		dp(i+1)=cm(idx+1,i);

		mp[val]=i;
		cm.add(dp(i+1));
	}
	mll ans=sum(dp_);

	cout << ans << '\n';

	//dump(dp_);

	return;
}


int main(){
#if 1
	solve();
#else
	ll t;  cin >> t;
	rep(i, 0, t-1){
		solve();
	}
#endif
	return 0;
}



#else //INCLUDED_MAIN
#include "bits/stdc++.h"
#if __has_include(<atcoder/all>)
#include <atcoder/all>
using namespace atcoder;
#endif
using     ll=long long;     using   dd=double;     
using    vll=vector<   ll>; using  vdd=vector< dd>;
using   vvll=vector<  vll>; using vvdd=vector<vdd>;
using  vvvll=vector< vvll>; using vvvdd=vector<vvdd>;
using vvvvll=vector<vvvll>;
using   pll=pair<ll,ll>;  using   tll=tuple<ll,ll,ll>; using   qll=tuple<ll,ll,ll,ll>;
using  vpll=vector< pll>; using  vtll=vector< tll>;    using  vqll=vector< qll>;
using vvpll=vector<vpll>; using vvtll=vector<vtll>;    using vvqll=vector<vqll>;
constexpr ll INF = 1LL << 60;
struct Fast{ Fast(){ cin.tie(0); ios::sync_with_stdio(false); cout<<fixed<<setprecision(numeric_limits<double>::max_digits10); } } fast;
#define REPS(i, S, E) for (ll i = (S); i <= (E); i++)
#define REP(i, N) REPS(i, 0, (N)-1)
#define DEPS(i, S, E) for (ll i = (E); i >= (S); i--)
#define DEP(i, N) DEPS(i, 0, (N)-1)
#define EXPAND( x ) x//VS用おまじない
#define overload3(_1,_2,_3,name,...) name
#define overload4(_1,_2,_3,_4,name,...) name
#define overload5(_1,_2,_3,_4,_5,name,...) name
#define rep3(i, S, E)    for (ll i = (S); i <= (E); i++)
#define rep4(i, S, E, t) for (ll i = (S); i <= (E); i+=(t))
#define rep(...) EXPAND(overload4(__VA_ARGS__,rep4,rep3,_,_)(__VA_ARGS__))
#define dep3(i, E, S)    for (ll i = (E); i >= (S); i--)
#define dep4(i, E, S, t) for (ll i = (E); i >= (S); i-=(t))
#define dep(...) EXPAND(overload4(__VA_ARGS__, dep4, dep3,_,_)(__VA_ARGS__))
#define each2(e,v) for (auto && e:v)
#define each3(a,b,v) for (auto &&[a,b]:v)
#define each4(a,b,c,v) for (auto &&[a,b,c]:v)
#define each5(a,b,c,d,v) for (auto &&[a,b,c,d]:v)
#define each(...) EXPAND(overload5(__VA_ARGS__,each5,each4,each3,each2,_)(__VA_ARGS__))
#define ALL1(v)     (v).begin(),     (v).end()
#define ALL2(v,E)   (v).begin(),     (v).begin()+((E)+1)
#define ALL3(v,S,E) (v).begin()+(S), (v).begin()+((E)+1)
#define ALL(...) EXPAND(overload3(__VA_ARGS__, ALL3, ALL2, ALL1)(__VA_ARGS__))
#define all ALL
#define RALL1(v)     (v).rbegin(),     (v).rend()
#define RALL2(v,E)   (v).rbegin(),     (v).rbegin()+((E)+1)
#define RALL3(v,S,E) (v).rbegin()+(S), (v).rbegin()+((E)+1)
#define RALL(...) EXPAND(overload3(__VA_ARGS__, RALL3, RALL2, RALL1)(__VA_ARGS__))
#define rall RALL
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true; }return false; }
template<class T> inline T MaxE(vector<T>&v,ll S,ll E){ T m=v[S]; rep(i,S,E)chmax(m,v[i]); return m; }
template<class T> inline T MinE(vector<T>&v,ll S,ll E){ T m=v[S]; rep(i,S,E)chmin(m,v[i]); return m; }
template<class T> inline T MaxE(vector<T> &v) { return MaxE(v,0,(ll)v.size()-1); }
template<class T> inline T MinE(vector<T> &v) { return MinE(v,0,(ll)v.size()-1); }
template<class T> inline auto maxe(T &&v,ll S,ll E){ return *max_element(ALL(v,S,E)); }
template<class T> inline auto maxe(T &&v){ return *max_element(ALL(v)); }
template<class T> inline auto mine(T &&v,ll S,ll E){ return *min_element(ALL(v,S,E)); }
template<class T> inline auto mine(T &&v){ return *min_element(ALL(v)); }
template<class T> inline T Sum(vector<T> &v,ll S,ll E){ T s=T(); rep(i,S,E)s+=v[i]; return s; }
template<class T> inline T Sum(vector<T> &v) { return Sum(v,0,v.size()-1); }
template<class T,class U=typename remove_reference<T>::type::value_type>
    inline U sum(T &&v,ll S,ll E) {return accumulate(all(v,S,E),U());}
template<class T> inline auto sum(T &&v) {return sum(v,0,v.end()-v.begin()-1);}
template<class T> inline ll sz(T &v){ return (ll)v.size(); }
inline ll CEIL(ll a,ll b){ return (a<0) ? -(-a/b) : (a+b-1)/b; } //負もOK
inline ll FLOOR(ll a,ll b){ return -CEIL(-a,b); } //負もOK

struct mll{
	static ll MOD;
	ll val;
	mll(ll v = 0): val(v % MOD){ if (val < 0) val += MOD; }
	mll operator - () const { return -val; }
	mll operator + (const mll &b) const { return val + b.val; }
	mll operator - (const mll &b) const { return val - b.val; }
	mll operator * (const mll &b) const { return val * b.val; }
	mll operator / (const mll &b) const { return mll(*this) /= b; }
	mll operator + (ll b) const { return *this + mll(b); }
	mll operator - (ll b) const { return *this - mll(b); }
	mll operator * (ll b) const { return *this * mll(b); }
	friend mll operator + (ll a,const mll &b) { return b + a; }
	friend mll operator - (ll a,const mll &b) { return -b + a; }
	friend mll operator * (ll a,const mll &b) { return b * a; }
	friend mll operator / (ll a,const mll &b) { return mll(a)/b; }
	mll &operator += (const mll &b) { val=(val+b.val)%MOD; return *this; }
	mll &operator -= (const mll &b) { val=(val+MOD-b.val)%MOD; return *this; }
	mll &operator *= (const mll &b) { val=(val*b.val)%MOD; return *this; }
	mll &operator /= (const mll &b) {
		ll c=b.val,d=MOD,u=1,v=0;
		while (d){
			ll t = c / d;
			c -= t * d; swap(c,d);
			u -= t * v; swap(u,v);
		}
		val = val * u % MOD;
		if (val < 0) val += MOD;
		return *this;
	}
	mll &operator += (ll b) { return *this += mll(b); }
	mll &operator -= (ll b) { return *this -= mll(b); }
	mll &operator *= (ll b) { return *this *= mll(b); }
	mll &operator /= (ll b) { return *this /= mll(b); }
	bool operator == (const mll &b) const { return val == b.val; }
	bool operator != (const mll &b) const { return val != b.val; }
	bool operator == (ll b) const { return *this == mll(b); }
	bool operator != (ll b) const { return *this != mll(b); }
	friend bool operator == (ll a,const mll &b) { return mll(a) == b.val; }
	friend bool operator != (ll a,const mll &b) { return mll(a) != b.val; }
	friend ostream &operator << (ostream &os,const mll &a) { return os << a.val; }
	friend istream &operator >> (istream &is,mll &a) { return is >> a.val; }
	static mll Combination(ll a,ll b){
		chmin(b,a-b);
		if (b<0) return mll(0);
		mll c = 1;
		rep(i,0,b-1) c *= a-i;
		rep(i,0,b-1) c /= i+1;
		return c;
	}
};
ll mll::MOD = 1000000007LL;// 998244353LL;//1000000007LL;
using vmll = std::vector<mll>;
using vvmll = std::vector<vmll>;
using vvvmll = std::vector<vvmll>;
using vvvvmll = std::vector<vvvmll>;
using vvvvvmll = std::vector<vvvvmll>;

#endif //INCLUDED_MAIN
0