Skip to content

Commit 9e95f55

Browse files
authored
Update CHEFEXQ.cpp
1 parent d7a2285 commit 9e95f55

File tree

1 file changed

+115
-1
lines changed

1 file changed

+115
-1
lines changed

Codechef/DEC17/CHEFEXQ.cpp

Lines changed: 115 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,115 @@
1-
will be added tomorrow once the contest ends..
1+
#include <bits/stdc++.h>
2+
// #include "stdafx.h"
3+
// #pragma warning(disable : 4996) //_CRT_SECURE_NO_WARNINGS
4+
using namespace std;
5+
#define gc getchar_unlocked
6+
#define fo(i,n) for(i=0;i<n;i++)
7+
#define Fo(i,k,n) for(i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
8+
#define ll long long
9+
#define si(x) scanf("%d",&x)
10+
#define sl(x) scanf("%lld",&x)
11+
#define ss(s) scanf("%s",s)
12+
#define pi(x) printf("%d\n",x)
13+
#define pl(x) printf("%lld\n",x)
14+
#define ps(s) printf("%s\n",s)
15+
#define deb(x) cout << #x << "=" << x << endl
16+
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
17+
#define pb push_back
18+
#define mp make_pair
19+
#define F first
20+
#define S second
21+
#define all(x) x.begin(), x.end()
22+
#define clr(x) memset(x, 0, sizeof(x))
23+
#define sortall(x) sort(all(x))
24+
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
25+
#define PI 3.1415926535897932384626
26+
typedef pair<int, int> pii;
27+
typedef pair<ll, ll> pl;
28+
typedef vector<int> vi;
29+
typedef vector<ll> vl;
30+
typedef vector<pii> vpii;
31+
typedef vector<pl> vpl;
32+
typedef vector<vi> vvi;
33+
typedef vector<vl> vvl;
34+
int mpow(int base, int exp);
35+
void ipgraph(int m);
36+
void dfs(int u, int par);
37+
const int mod = 1000000007;
38+
const int N = 3e5, M = N;
39+
//=======================
40+
41+
vi g[N];
42+
int a[N];
43+
const int rtn = 600;
44+
int local[N], bkt[N];
45+
int mat[rtn+1][rtn+1];
46+
int dp[rtn+1][rtn+1], en[rtn+1];
47+
unordered_map<int, int> cnt[rtn+1];
48+
49+
void compute(int b){
50+
cnt[b].clear();
51+
int i;
52+
dp[b][0] = mat[b][0];
53+
Fo(i, 1, en[b]+1){
54+
dp[b][i] = mat[b][i] ^ dp[b][i-1];
55+
}
56+
Fo(i, 0, en[b]+1) cnt[b][dp[b][i]]++;
57+
}
58+
int main()
59+
{
60+
//freopen("input.txt", "r", stdin);
61+
//freopen("output.txt", "w", stdout);
62+
ios_base::sync_with_stdio(false);
63+
cin.tie(NULL);
64+
int i,n,k,j, type, x, _i = 0, q;
65+
int b = -1;
66+
67+
si(n); si(q);
68+
fo(i, n) {
69+
si(a[i]);
70+
if(i%rtn == 0){
71+
if(b>=0) compute(b);
72+
b++, _i = 0;
73+
}
74+
75+
bkt[i] = b;
76+
local[i] = _i;
77+
en[b] = _i;
78+
mat[b][_i] = a[i];
79+
_i++;
80+
}
81+
compute(b);
82+
83+
while(q--){
84+
si(type);
85+
si(i);
86+
si(x);
87+
i--;
88+
if(type == 1){
89+
//update a[i] = x;
90+
b = bkt[i];
91+
_i = local[i];
92+
mat[b][_i] = x;
93+
compute(b);
94+
}
95+
else{
96+
//query prefixes with xor = x, and end before i
97+
int b = bkt[i];
98+
int ans = 0, ptr = 0, pre = 0;
99+
while(bkt[ptr] < b){
100+
int cur_bkt = bkt[ptr];
101+
int need = x ^ pre;
102+
ans += cnt[cur_bkt][need];
103+
pre ^= dp[cur_bkt][en[cur_bkt]];
104+
ptr += rtn;
105+
}
106+
Fo(j, 0, local[i]+1){
107+
pre ^= mat[b][j];
108+
if(pre == x) ans++;
109+
}
110+
printf("%d\n", ans);
111+
}
112+
}
113+
114+
return 0;
115+
}

0 commit comments

Comments
 (0)