1109A - Sasha and a Bit of Relax - CodeForces Solution


dp implementation *1600

Please click on ads to support us..

C++ Code:

// #pragma optimization_level 3
// #pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#include <bits/stdc++.h>
#define fastio() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define  PI              3.141592653589793238462
#define mset(x,val)     memset(x,val,sizeof(x))
#define  f               first
#define  s               second
#define  pb             push_back
#define  mp             make_pair
#define  sym(s)          s = "#" + s + "#";
#define  all(x)          (x).begin(), (x).end()
#define  alll(x,n)       x+1, x+n+1
#define  newl            cout<<"\n";
#define  foo(i,a,n)      for(ll i = (a); i <= n; i++)
#define  deb1(a)         cout<<a<<"deb1\n";
#define  deb2(a,b)       cout<<a<<" deb2 "<<b<<"\n";
#define  deb3(a,b,c)     cout<<a<<" deb3 "<<b<<" "<<c<<"\n";
#define  deb4(a,b,c,d)   cout<<a<<" deb4 "<<b<<" "<<c<<" "<<d<<"\n";
#define  debp(a)         cout<<a.f<<" "<<a.s<<"\n";
#define  debv(a)         for(auto it: a)cout<<it<<" ";newl;
#define  debm(a)         for(auto it: a)cout<<"{"<<it.f<<","<<it.s<<"}, ";newl;
#define  deb1d(a,n)      foo(i,1,n)cout<<a[i]<<" ";newl;
#define  deb2d(a,n,m)    foo(i,1,n){foo(j,1,m){cout<<a[i][j]<<" ";}newl;}
typedef long long ll;
typedef unsigned long long ull;
typedef long double lld;

int dx[] = { -1, 0, 1, 0};
int dy[] = {0, 1, 0, -1};

using namespace std;
using ll              =  long long;
using ld              =  long double;
const ll   MOD       =  1e+9 + 7;
const ll   mod        =  1e+9 + 7 ;
const ll   INF        =  LLONG_MAX;
const int  N          =  (int)2e+5 + 8;

#ifndef ONLINE_JUDGE
#define debug(x) cerr << #x <<" "; _print(x); cerr << endl;
#else
#define debug(x)
#endif

void _print(ll t) {cerr << t;}
void _print(int t) {cerr << t;}
void _print(string t) {cerr << t;}
void _print(char t) {cerr << t;}
void _print(lld t) {cerr << t;}
void _print(double t) {cerr << t;}
void _print(ull t) {cerr << t;}

template <class T, class V> void _print(pair <T, V> p);
template <class T> void _print(vector <T> v);
template <class T> void _print(set <T> v);
template <class T, class V> void _print(map <T, V> v);
template <class T> void _print(multiset <T> v);
template <class T, class V> void _print(pair <T, V> p) {cerr << "{"; _print(p.ff); cerr << ","; _print(p.ss); cerr << "}";}
template <class T> void _print(vector <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(set <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T> void _print(multiset <T> v) {cerr << "[ "; for (T i : v) {_print(i); cerr << " ";} cerr << "]";}
template <class T, class V> void _print(map <T, V> v) {cerr << "[ "; for (auto i : v) {_print(i); cerr << " ";} cerr << "]";}

/*---------------------------------------------------------------------------------------------------------------------------*/

ll madd(ll a, ll b) { return (a + b) % mod;}
ll msub(ll a, ll b) {return (((a - b) % mod) + mod) % mod;}
ll mmul(ll a, ll b) {return ((a % mod) * (b % mod)) % mod;}
ll mpow(ll base, ll exp) {
    ll res = 1;
    while (exp) {
        if (exp % 2 == 1) {
            res = (res * base) % mod;
        }
        exp >>= 1;
        base = (base * base) % mod;
    }
    return res;
}
ll minv(ll base) {return mpow(base, mod - 2);}
ll mdiv(ll a, ll b) {return mmul(a, minv(b));}

/*---------------------------------------------------------------------------------------------------------------------------*/

void MAIN(ll tc)
{
    ll n; cin >> n;
    vector<ll> vec(n + 1);
    map<ll, ll> mpe, mpo;
    ll ans = 0, x = 0;
    mpe[0] = 1;
    for (ll i = 1; i <= n; i++)
    {
        cin >> vec[i];
        x = x ^ vec[i];

        if (i % 2 == 1)
        {
            ans += mpo[x];
            mpo[x]++;
        }
        else
        {
            ans += mpe[x];
            mpe[x]++;
        }
        debug(i)
        debug(ans)
    }

    cout << ans;


}


int main()
{

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

#ifndef ONLINE_JUDGE
    freopen("Error.txt", "w", stderr);
#endif
//freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
    fastio();
    cout << fixed << setprecision(15);

    int test__cases = 1;
    // cin >> test__cases;
    for (int i = 1; i <= test__cases; i++) {
        MAIN(i);
        cout << "\n";
    }

#ifndef ONLINE_JUDGE
    cerr << "Time taken : " << (float)clock() / CLOCKS_PER_SEC << " secs " << endl;
#endif

}



Comments

Submit
0 Comments
More Questions

620A - Professor GukiZ's Robot
1342A - Road To Zero
1520A - Do Not Be Distracted
352A - Jeff and Digits
1327A - Sum of Odd Integers
1276A - As Simple as One and Two
812C - Sagheer and Nubian Market
272A - Dima and Friends
1352C - K-th Not Divisible by n
545C - Woodcutters
1528B - Kavi on Pairing Duty
339B - Xenia and Ringroad
189A - Cut Ribbon
1182A - Filling Shapes
82A - Double Cola
45A - Codecraft III
1242A - Tile Painting
1663E - Are You Safe
1663D - Is it rated - 3
1311A - Add Odd or Subtract Even
977F - Consecutive Subsequence
939A - Love Triangle
755A - PolandBall and Hypothesis
760B - Frodo and pillows
1006A - Adjacent Replacements
1195C - Basketball Exercise
1206A - Choose Two Numbers
1438B - Valerii Against Everyone
822A - I'm bored with life
9A - Die Roll