QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#857096 | #9727. Barkley III | Zawos | TL | 19ms | 6528kb | C++20 | 2.9kb | 2025-01-15 07:57:05 | 2025-01-15 07:57:07 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = a; i < b; i++)
#define all(x) x.begin(), x.end()
using vi = vector<int>;
using ii = pair<int, int>;
using vii = vector<ii>;
using ll = long long;
using vll = vector<ll>;
const int LG = 63;
void solve() {
int n, q; cin >> n >> q;
vll nums(n); rep(i, 0, n) cin >> nums[i];
vector<set<int>> on(LG), off(LG);
rep(i, 0, n) {
rep(j, 0, LG)
if (nums[i] & (1ll << j))
on[j].insert(i);
else
off[j].insert(i);
}
while (q--) {
int op; cin >> op;
if (op == 1) {
int l, r; ll x; cin >> l >> r >> x;
l--; r--;
rep(i, 0, LG) {
if (!(x & (1ll << i))) {
auto nx = on[i].lower_bound(l);
while (nx != on[i].end() && *nx <= r) {
off[i].insert(*nx);
nx = next(nx);
on[i].erase(prev(nx));
}
}
}
}else if (op == 2){
int pos; ll x; cin >> pos >> x;
pos--;
rep(i, 0, LG) {
on[i].erase(pos);
off[i].erase(pos);
if (x & (1ll << i))
on[i].insert(pos);
else
off[i].insert(pos);
}
}else {
int l, r; cin >> l >> r;
l--; r--;
if (l == r) {
cout << "0\n";
continue;
}
ll ans = 0;
int remove = -1;
for (int i = LG - 1; i >= 0; i--) {
auto firstOff = off[i].lower_bound(l);
if (firstOff == off[i].end() || *firstOff > r) {
ans |= 1ll << i;
}else {
auto secondOff = next(firstOff);
if (secondOff == off[i].end() || *secondOff > r) {
remove = *firstOff;
break;
}
}
}
if (remove != -1) {
ans = 0;
rep(i, 0, LG) {
auto firstOff = off[i].lower_bound(l);
if (firstOff == off[i].end() || *firstOff > r) {
ans |= 1ll << i;
}else if (*firstOff == remove) {
auto secondOff = next(firstOff);
if (secondOff == off[i].end() || *secondOff > r) {
ans |= 1ll << i;
}
}
}
}
cout << ans << "\n";
}
}
}
int main() {
ios_base::sync_with_stdio(false); cin.tie(0);
int t = 1; //cin >> t;
while (t--)
solve();
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3712kb
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: 1ms
memory: 3840kb
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: 1ms
memory: 4096kb
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: 19ms
memory: 6528kb
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: -100
Time Limit Exceeded
input:
100000 100000 4364025563773184234 7745126251050571359 5111681002836044963 7745126251050571359 7745126251050571359 7745126251050571359 7745126251050571359 7745126251050571359 7745126251050571359 7745126251050571359 7745126251050571359 7745126251050571359 7222555899134537718 7745126251050571359 686495...