結果
問題 | No.1493 隣接xor |
ユーザー |
![]() |
提出日時 | 2021-04-30 23:32:36 |
言語 | C++17 (gcc 13.3.0 + boost 1.87.0) |
結果 |
AC
|
実行時間 | 200 ms / 2,000 ms |
コード長 | 9,508 bytes |
コンパイル時間 | 4,066 ms |
コンパイル使用メモリ | 260,648 KB |
最終ジャッジ日時 | 2025-01-21 04:46:08 |
ジャッジサーバーID (参考情報) |
judge2 / judge2 |
(要ログイン)
ファイルパターン | 結果 |
---|---|
sample | AC * 3 |
other | AC * 27 |
ソースコード
·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';}#elsetemplate<class T> void dump(T &v){}#endifvoid 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 1solve();#elsell t; cin >> t;rep(i, 0, t-1){solve();}#endifreturn 0;}#else //INCLUDED_MAIN#include "bits/stdc++.h"#if __has_include(<atcoder/all>)#include <atcoder/all>using namespace atcoder;#endifusing 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 RALLtemplate<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; } //負もOKinline ll FLOOR(ll a,ll b){ return -CEIL(-a,b); } //負もOKstruct 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