#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define all(x) x.begin(), x.end()
#define Neco "XORanges"
#define resp(x) sort(all(x)), x.resize(unique(all(x)) - x.begin())
#define getbit(x,i) ((x >> i)&1)
#define _left id * 2, l, mid
#define _right id * 2 + 1, mid + 1, r
#define cntbit(x) __builtin_popcountll(x)
#define fi(i, a, b) for(int i = a; i <= b; i++)
#define fid(i, a, b) for(int i = a; i >= b; i--)
#define maxn (int) 2e5 + 7
using namespace std;
const ll mod = 2; //972663749
const ll base = 911382323;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll GetRandom(ll l, ll r)
{
return uniform_int_distribution<ll> (l, r)(rng);
}
int n, q;
int a[maxn];
ll md (ll x) { return ((x % mod) + mod) % mod; }
struct BIT {
struct Node {
int Sum, Sqr, Sl;
} bit[maxn];
void update(int x, ll val) {
int w = val < 0 ? -1 : 1;
while(x < maxn) {
bit[x].Sl = md(bit[x].Sl + w);
bit[x].Sqr = md(bit[x].Sqr + 1ll * val * val);
bit[x].Sum = md(bit[x].Sum + val);
x += (x & -x);
}
}
int get(int l, int r, Node ans = {0, 0, 0}) {
--l;
ll L = l + 1, R = r;
while(l > 0) {
ans.Sl = md(ans.Sl - bit[l].Sl);
ans.Sqr = md(ans.Sqr - bit[l].Sqr);
ans.Sum = md(ans.Sum - bit[l].Sum);
l -= (l & -l);
}
while(r > 0) {
ans.Sl = md(ans.Sl + bit[r].Sl);
ans.Sqr = md(ans.Sqr + bit[r].Sqr);
ans.Sum = md(ans.Sum + bit[r].Sum);
r -= (r & -r);
}
return md(ans.Sum * (L + R) - ans.Sqr + ans.Sl * (-L * R + R - L + 1));
}
} Bit[30];
void updt(int id, int val) {
fi(i, 0, 29) if(getbit(a[id], i)) Bit[i].update(id, val * id);
}
void solve()
{
cin >> n >> q;
fi(i, 1, n) cin >> a[i], updt(i, 1);
fi(i, 1, q) {
int type, x, y;
cin >> type >> x >> y;
if(type == 1) updt(x, -1), a[x] = y, updt(x, 1);
else {
int ans = 0;
fi(i, 0, 29) ans += (1 << i) * Bit[i].get(x, y);
cout << ans << '\n';
}
}
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if(fopen(Neco".inp", "r")) {
freopen(Neco".inp", "r", stdin);
freopen(Neco".out", "w", stdout);
}
int nTest = 1;
// cin >> nTest;
while(nTest--)
{
solve();
}
return 0;
}
Compilation message
xoranges.cpp: In function 'int main()':
xoranges.cpp:106:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
106 | freopen(Neco".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
xoranges.cpp:107:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
107 | freopen(Neco".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1624 KB |
Output is correct |
2 |
Correct |
1 ms |
1624 KB |
Output is correct |
3 |
Correct |
2 ms |
1624 KB |
Output is correct |
4 |
Correct |
1 ms |
1628 KB |
Output is correct |
5 |
Correct |
1 ms |
1628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
1624 KB |
Output is correct |
2 |
Correct |
3 ms |
1624 KB |
Output is correct |
3 |
Correct |
2 ms |
1628 KB |
Output is correct |
4 |
Correct |
2 ms |
1864 KB |
Output is correct |
5 |
Correct |
2 ms |
1628 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1624 KB |
Output is correct |
2 |
Correct |
1 ms |
1624 KB |
Output is correct |
3 |
Correct |
2 ms |
1624 KB |
Output is correct |
4 |
Correct |
1 ms |
1628 KB |
Output is correct |
5 |
Correct |
1 ms |
1628 KB |
Output is correct |
6 |
Correct |
2 ms |
1624 KB |
Output is correct |
7 |
Correct |
3 ms |
1624 KB |
Output is correct |
8 |
Correct |
2 ms |
1628 KB |
Output is correct |
9 |
Correct |
2 ms |
1864 KB |
Output is correct |
10 |
Correct |
2 ms |
1628 KB |
Output is correct |
11 |
Correct |
12 ms |
3164 KB |
Output is correct |
12 |
Correct |
12 ms |
3164 KB |
Output is correct |
13 |
Correct |
11 ms |
3164 KB |
Output is correct |
14 |
Correct |
11 ms |
3164 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Runtime error |
134 ms |
65536 KB |
Execution killed with signal 9 |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1624 KB |
Output is correct |
2 |
Correct |
1 ms |
1624 KB |
Output is correct |
3 |
Correct |
2 ms |
1624 KB |
Output is correct |
4 |
Correct |
1 ms |
1628 KB |
Output is correct |
5 |
Correct |
1 ms |
1628 KB |
Output is correct |
6 |
Correct |
2 ms |
1624 KB |
Output is correct |
7 |
Correct |
3 ms |
1624 KB |
Output is correct |
8 |
Correct |
2 ms |
1628 KB |
Output is correct |
9 |
Correct |
2 ms |
1864 KB |
Output is correct |
10 |
Correct |
2 ms |
1628 KB |
Output is correct |
11 |
Correct |
12 ms |
3164 KB |
Output is correct |
12 |
Correct |
12 ms |
3164 KB |
Output is correct |
13 |
Correct |
11 ms |
3164 KB |
Output is correct |
14 |
Correct |
11 ms |
3164 KB |
Output is correct |
15 |
Runtime error |
134 ms |
65536 KB |
Execution killed with signal 9 |
16 |
Halted |
0 ms |
0 KB |
- |