QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#756110 | #9727. Barkley III | zake# | TL | 1075ms | 197188kb | C++17 | 3.5kb | 2024-11-16 19:04:43 | 2024-11-16 19:04:44 |
Judging History
answer
#include<bits/stdc++.h>
//#define int long long
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
using namespace std;
void solve();
signed main() {
fast
int t = 1;
// cin >> t;
while (t--) solve();
}
const int N = 1e6 + 10;
using ll = long long;
int n, q;
ll w[N];
ll k;
struct seg{
int tr[N << 2];
void pu(int u){
int &o = tr[u], l = tr[u << 1], r = tr[u << 1 | 1];
o = l + r;
}
void build(int u, int l, int r){
if(l == r){
tr[u] = w[l] >> k & 1;
}
else{
int mid = l + r >> 1;
build(u << 1, l, mid), build(u << 1 | 1, mid + 1, r);
pu(u);
}
}
void change(int u, int p, int k, int L, int R){
if(L == R){
tr[u] = k;
return;
}
int mid = L + R >> 1;
if(p <= mid) change(u << 1, p, k, L, mid);
else change(u << 1 | 1, p, k, mid + 1, R);
pu(u);
}
void modify(int u, int l, int r, int L, int R){
if(tr[u] == 0) return;
if(L == R){
tr[u] = 0;
return;
}
int mid = L + R >> 1;
if(l <= mid) modify(u << 1, l, r, L, mid);
if(r > mid) modify(u << 1 | 1, l, r, mid + 1, R);
pu(u);
}
int query_sum(int u, int l, int r, int L, int R){
if(l <= L && R <= r){
return tr[u];
}
int mid = L + R >> 1;
int res = 0;
if(l <= mid) res += query_sum(u << 1, l, r, L, mid);
if(r > mid) res += query_sum(u << 1 | 1, l, r, mid + 1, R);
return res;
}
int query(int u, int l, int r, int L, int R){
if(l <= L && R <= r){
if(tr[u] == R - L + 1) return 0;
if(L == R) return L;
int mid = L + R >> 1;
return query(u << 1, l, r, L, mid) + query(u << 1 | 1, l, r, mid + 1, R);
}
int mid = L + R >> 1;
int res = 0;
if(l <= mid) res += query(u << 1, l, r, L, mid);
if(r > mid) res += query(u << 1 | 1, l, r, mid + 1, R);
return res;
}
};
const int K = 63;
seg tr[K];
void set_at(int pos, ll x){
for(k = 0; k < K; k++){
tr[k].change(1, pos, (int)(x >> k & 1ll), 1, n);
}
}
ll calc(int l, int r){
if(l > r) return -1;
ll res = 0;
for(k = 0; k < K; k++){
if(tr[k].query_sum(1, l, r, 1, n) == r - l + 1) res += 1ll << k;
}
return res;
}
void solve() {
cin >> n >> q;
for(int i = 1; i <= n; i++) cin >> w[i];
for(k = 0; k < K; k++) tr[k].build(1, 1, n);
while(q--){
int op; cin >> op;
if(op == 1){
int l, r; ll x; cin >> l >> r >> x;
for(k = 0; k < K; k++){
if(x >> k & 1) continue;
tr[k].modify(1, l, r, 1, n);
}
}
else if(op == 2){
int s; ll x; cin >> s >> x;
set_at(s, x);
}
else{
int l, r; cin >> l >> r;
ll res = calc(l, r);
if(r - l + 1 == 1){
cout << res << '\n';
continue;
}
for(k = K - 1; k >= 0; k--){
if(tr[k].query_sum(1, l, r, 1, n) == r - l){
int p = tr[k].query(1, l, r, 1, n);
res = max(res, calc(l, p - 1) & calc(p + 1, r));
break;
}
}
cout << res << '\n';
}
}
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 132688kb
input:
5 9 7 7 7 6 7 3 1 5 2 1 3 3 1 5 3 1 3 1 1 2 3 3 1 3 2 2 8 3 1 3 3 1 2
output:
7 6 7 3 3 8
result:
ok 6 lines
Test #2:
score: 0
Accepted
time: 0ms
memory: 132688kb
input:
10 10 6760061359215711796 1568091718842717482 1568091718842717482 1568091718842717482 5232472783634052627 8795942500783873690 1568091718842717482 1568091718842717482 1568091718842717482 1568091718842717482 1 3 5 7587422031989082829 3 6 10 1 7 8 5197616143400216932 2 4 2518604563805514908 2 2 4533959...
output:
1568091718842717482 35184908959744 176025477579040 8795942500783873690
result:
ok 4 lines
Test #3:
score: 0
Accepted
time: 0ms
memory: 132688kb
input:
100 100 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 625967318191814868 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072360993 4263579105072...
output:
576531121047601152 1 576460752303423488 4263579105072360993 1306043896232411137 4263579105072360993 576531121047601152 633397148123136 0 1153488865559840256 1152922054496880128 1730020640668059136 3533641810948498945 67108864 1730020640668059136 0 633397148123136 1729382296723653632 0 17300206406680...
result:
ok 78 lines
Test #4:
score: 0
Accepted
time: 3ms
memory: 132720kb
input:
1000 1000 3368486440884437410 3368486440884437410 3368486440884437410 3368486440884437410 3368486440884437410 3368486440884437410 3368486440884437410 3368486440884437410 3368486440884437410 3368486440884437410 3368486440884437410 3639580211161047627 3368486440884437410 3368486440884437410 3368486440...
output:
3368486440884437410 3368486440884437410 3368486440884437410 2251799981457408 0 0 3368486440884437410 0 3326828075601101216 592509842556584322 0 0 0 0 0 0 37154696925806592 0 0 0 3368486440884437410 0 0 3368486440884437410 0 578998425140330496 0 0 134217728 0 3368486440884437410 2306405959167115264 0...
result:
ok 732 lines
Test #5:
score: 0
Accepted
time: 1075ms
memory: 197188kb
input:
100000 100000 4364025563773184234 7745126251050571359 5111681002836044963 7745126251050571359 7745126251050571359 7745126251050571359 7745126251050571359 7745126251050571359 7745126251050571359 7745126251050571359 7745126251050571359 7745126251050571359 7222555899134537718 7745126251050571359 686495...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4613942216556019776 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 ...
result:
ok 75105 lines
Test #6:
score: -100
Time Limit Exceeded
input:
1000000 1000000 5485203341817263234 5485203341817263234 5485203341817263234 5485203341817263234 5485203341817263234 5485203341817263234 5485203341817263234 5485203341817263234 5485203341817263234 5485203341817263234 5485203341817263234 5485203341817263234 5485203341817263234 5485203341817263234 5485...
output:
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 8796093022208 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 576460754450907136 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...