QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#756214 | #9727. Barkley III | zake# | TL | 609ms | 157388kb | C++17 | 2.5kb | 2024-11-16 19:22:32 | 2024-11-16 19:22:32 |
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, K = 63;
using ll = long long;
int n, q;
ll w[N];
ll k;
struct seg{
int tr[N];
int lb(int x){
return x & -x;
}
void assign(int p, int k){
add(p, -sum(p, p) + k);
}
void add(int p, int k){
for(int i = p; i <= n; i += lb(i)) tr[i] += k;
}
int sum(int p){
int res = 0;
for(int i = p; i; i -= lb(i)) res += tr[i];
return res;
}
int sum(int l, int r){
return sum(r) - sum(l - 1);
}
void reset(int l, int r){
if(l > r) return;
if(l == r){
assign(l, 0);
return;
}
if(!sum(l, r)) return;
int mid = l + r >> 1;
reset(l, mid), reset(mid + 1, r);
}
int query(int l, int r){
if(l == r) return l;
int mid = l + r >> 1;
if(sum(l, mid) != mid - l + 1) return query(l, mid);
return query(mid + 1, r);
}
};
seg tr[K];
void set_at(int pos, ll x){
for(k = 0; k < K; k++){
tr[k].assign(pos, (int)(x >> k & 1ll));
}
}
ll calc(int l, int r){
if(l > r) return -1;
ll res = 0;
for(k = 0; k < K; k++){
if(tr[k].sum(l, r) == 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++){
for(int i = 1; i <= n; i++){
tr[k].add(i, w[i] >> k & 1);
}
}
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].reset(l, r);
}
}
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].sum(l, r) == r - l){
int p = tr[k].query(l, r);
res = max(res, calc(l, p - 1) & calc(p + 1, r));
break;
}
}
cout << res << '\n';
}
}
}
//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
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 132732kb
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: 132572kb
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: 132656kb
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: 0ms
memory: 132604kb
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: 609ms
memory: 157388kb
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...