QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#854211 | #9727. Barkley III | ucup-team2796# | TL | 1454ms | 17440kb | C++23 | 17.4kb | 2025-01-11 22:33:28 | 2025-01-11 22:33:29 |
Judging History
answer
#line 1 "library/Template/template.hpp"
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rrep(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define ALL(v) (v).begin(), (v).end()
#define UNIQUE(v) sort(ALL(v)), (v).erase(unique(ALL(v)), (v).end())
#define SZ(v) (int)v.size()
#define MIN(v) *min_element(ALL(v))
#define MAX(v) *max_element(ALL(v))
#define LB(v, x) int(lower_bound(ALL(v), (x)) - (v).begin())
#define UB(v, x) int(upper_bound(ALL(v), (x)) - (v).begin())
using uint = unsigned int;
using ll = long long int;
using ull = unsigned long long;
using i128 = __int128_t;
using u128 = __uint128_t;
const int inf = 0x3fffffff;
const ll INF = 0x1fffffffffffffff;
template <typename T> inline bool chmax(T &a, T b) {
if (a < b) {
a = b;
return 1;
}
return 0;
}
template <typename T> inline bool chmin(T &a, T b) {
if (a > b) {
a = b;
return 1;
}
return 0;
}
template <typename T, typename U> T ceil(T x, U y) {
assert(y != 0);
if (y < 0)
x = -x, y = -y;
return (x > 0 ? (x + y - 1) / y : x / y);
}
template <typename T, typename U> T floor(T x, U y) {
assert(y != 0);
if (y < 0)
x = -x, y = -y;
return (x > 0 ? x / y : (x - y + 1) / y);
}
template <typename T> int popcnt(T x) {
return __builtin_popcountll(x);
}
template <typename T> int topbit(T x) {
return (x == 0 ? -1 : 63 - __builtin_clzll(x));
}
template <typename T> int lowbit(T x) {
return (x == 0 ? -1 : __builtin_ctzll(x));
}
template <class T, class U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
os << "P(" << p.first << ", " << p.second << ")";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {
os << "{";
for (int i = 0; i < vec.size(); i++) {
os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
}
os << "}";
return os;
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &map_var) {
os << "{";
for (auto itr = map_var.begin(); itr != map_var.end(); itr++) {
os << "(" << itr->first << ", " << itr->second << ")";
itr++;
if (itr != map_var.end())
os << ", ";
itr--;
}
os << "}";
return os;
}
template <typename T> ostream &operator<<(ostream &os, const set<T> &set_var) {
os << "{";
for (auto itr = set_var.begin(); itr != set_var.end(); itr++) {
os << *itr;
++itr;
if (itr != set_var.end())
os << ", ";
itr--;
}
os << "}";
return os;
}
#ifdef LOCAL
#define show(...) _show(0, #__VA_ARGS__, __VA_ARGS__)
#else
#define show(...) true
#endif
template <typename T> void _show(int i, T name) {
cerr << '\n';
}
template <typename T1, typename T2, typename... T3>
void _show(int i, const T1 &a, const T2 &b, const T3 &...c) {
for (; a[i] != ',' && a[i] != '\0'; i++)
cerr << a[i];
cerr << ":" << b << " ";
_show(i + 1, a, c...);
}
#line 2 "library/Utility/fastio.hpp"
#include <unistd.h>
namespace fastio {
static constexpr uint32_t SZ = 1 << 17;
char ibuf[SZ];
char obuf[SZ];
char out[100];
// pointer of ibuf, obuf
uint32_t pil = 0, pir = 0, por = 0;
struct Pre {
char num[10000][4];
constexpr Pre() : num() {
for (int i = 0; i < 10000; i++) {
int n = i;
for (int j = 3; j >= 0; j--) {
num[i][j] = n % 10 | '0';
n /= 10;
}
}
}
} constexpr pre;
inline void load() {
memmove(ibuf, ibuf + pil, pir - pil);
pir = pir - pil + fread(ibuf + pir - pil, 1, SZ - pir + pil, stdin);
pil = 0;
if (pir < SZ)
ibuf[pir++] = '\n';
}
inline void flush() {
fwrite(obuf, 1, por, stdout);
por = 0;
}
void rd(char &c) {
do {
if (pil + 1 > pir)
load();
c = ibuf[pil++];
} while (isspace(c));
}
void rd(string &x) {
x.clear();
char c;
do {
if (pil + 1 > pir)
load();
c = ibuf[pil++];
} while (isspace(c));
do {
x += c;
if (pil == pir)
load();
c = ibuf[pil++];
} while (!isspace(c));
}
template <typename T> void rd_real(T &x) {
string s;
rd(s);
x = stod(s);
}
template <typename T> void rd_integer(T &x) {
if (pil + 100 > pir)
load();
char c;
do
c = ibuf[pil++];
while (c < '-');
bool minus = 0;
if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
if (c == '-') {
minus = 1, c = ibuf[pil++];
}
}
x = 0;
while ('0' <= c) {
x = x * 10 + (c & 15), c = ibuf[pil++];
}
if constexpr (is_signed<T>::value || is_same_v<T, i128>) {
if (minus)
x = -x;
}
}
void rd(int &x) {
rd_integer(x);
}
void rd(ll &x) {
rd_integer(x);
}
void rd(i128 &x) {
rd_integer(x);
}
void rd(uint &x) {
rd_integer(x);
}
void rd(ull &x) {
rd_integer(x);
}
void rd(u128 &x) {
rd_integer(x);
}
void rd(double &x) {
rd_real(x);
}
void rd(long double &x) {
rd_real(x);
}
template <class T, class U> void rd(pair<T, U> &p) {
return rd(p.first), rd(p.second);
}
template <size_t N = 0, typename T> void rd_tuple(T &t) {
if constexpr (N < std::tuple_size<T>::value) {
auto &x = std::get<N>(t);
rd(x);
rd_tuple<N + 1>(t);
}
}
template <class... T> void rd(tuple<T...> &tpl) {
rd_tuple(tpl);
}
template <size_t N = 0, typename T> void rd(array<T, N> &x) {
for (auto &d : x)
rd(d);
}
template <class T> void rd(vector<T> &x) {
for (auto &d : x)
rd(d);
}
void read() {}
template <class H, class... T> void read(H &h, T &...t) {
rd(h), read(t...);
}
void wt(const char c) {
if (por == SZ)
flush();
obuf[por++] = c;
}
void wt(const string s) {
for (char c : s)
wt(c);
}
void wt(const char *s) {
size_t len = strlen(s);
for (size_t i = 0; i < len; i++)
wt(s[i]);
}
template <typename T> void wt_integer(T x) {
if (por > SZ - 100)
flush();
if (x < 0) {
obuf[por++] = '-', x = -x;
}
int outi;
for (outi = 96; x >= 10000; outi -= 4) {
memcpy(out + outi, pre.num[x % 10000], 4);
x /= 10000;
}
if (x >= 1000) {
memcpy(obuf + por, pre.num[x], 4);
por += 4;
} else if (x >= 100) {
memcpy(obuf + por, pre.num[x] + 1, 3);
por += 3;
} else if (x >= 10) {
int q = (x * 103) >> 10;
obuf[por] = q | '0';
obuf[por + 1] = (x - q * 10) | '0';
por += 2;
} else
obuf[por++] = x | '0';
memcpy(obuf + por, out + outi + 4, 96 - outi);
por += 96 - outi;
}
template <typename T> void wt_real(T x) {
ostringstream oss;
oss << fixed << setprecision(15) << double(x);
string s = oss.str();
wt(s);
}
void wt(int x) {
wt_integer(x);
}
void wt(ll x) {
wt_integer(x);
}
void wt(i128 x) {
wt_integer(x);
}
void wt(uint x) {
wt_integer(x);
}
void wt(ull x) {
wt_integer(x);
}
void wt(u128 x) {
wt_integer(x);
}
void wt(double x) {
wt_real(x);
}
void wt(long double x) {
wt_real(x);
}
template <class T, class U> void wt(const pair<T, U> val) {
wt(val.first);
wt(' ');
wt(val.second);
}
template <size_t N = 0, typename T> void wt_tuple(const T t) {
if constexpr (N < std::tuple_size<T>::value) {
if constexpr (N > 0) {
wt(' ');
}
const auto x = std::get<N>(t);
wt(x);
wt_tuple<N + 1>(t);
}
}
template <class... T> void wt(tuple<T...> tpl) {
wt_tuple(tpl);
}
template <class T, size_t S> void wt(const array<T, S> val) {
auto n = val.size();
for (size_t i = 0; i < n; i++) {
if (i)
wt(' ');
wt(val[i]);
}
}
template <class T> void wt(const vector<T> val) {
auto n = val.size();
for (size_t i = 0; i < n; i++) {
if (i)
wt(' ');
wt(val[i]);
}
}
void print() {
wt('\n');
}
template <class Head, class... Tail> void print(Head &&head, Tail &&...tail) {
wt(head);
if (sizeof...(Tail))
wt(' ');
print(forward<Tail>(tail)...);
}
void __attribute__((destructor)) _d() {
flush();
}
} // namespace fastio
using fastio::flush;
using fastio::print;
using fastio::read;
inline void first(bool i = true) {
print(i ? "first" : "second");
}
inline void Alice(bool i = true) {
print(i ? "Alice" : "Bob");
}
inline void Takahashi(bool i = true) {
print(i ? "Takahashi" : "Aoki");
}
inline void yes(bool i = true) {
print(i ? "yes" : "no");
}
inline void Yes(bool i = true) {
print(i ? "Yes" : "No");
}
inline void No() {
print("No");
}
inline void YES(bool i = true) {
print(i ? "YES" : "NO");
}
inline void NO() {
print("NO");
}
inline void Yay(bool i = true) {
print(i ? "Yay!" : ":(");
}
inline void Possible(bool i = true) {
print(i ? "Possible" : "Impossible");
}
inline void POSSIBLE(bool i = true) {
print(i ? "POSSIBLE" : "IMPOSSIBLE");
}
/**
* @brief Fast IO
*/
#line 3 "sol.cpp"
#line 2 "library/DataStructure/disjointsparsetable.hpp"
template<typename T,T (*f)(T,T)>struct DisjointSparseTable{
vector<vector<T>> buf;
vector<int> height;
DisjointSparseTable(const vector<T>& a){
int n=a.size(),LG=0;
while((1<<LG)<=n)LG++;
buf.assign(LG,vector<T>(n));
height.assign(1<<LG,0);
rep(i,2,1<<LG)height[i]=height[i>>1]+1;
rep(i,0,n)buf[0][i]=a[i];
rep(lg,1,LG){
int add=1<<lg;
for(int j=0;j<n;j+=(add<<1)){
int pos=min(j+add,n);
buf[lg][pos-1]=a[pos-1];
for(int k=pos-2;k>=j;k--)buf[lg][k]=f(a[k],buf[lg][k+1]);
if(n<=pos)break;
buf[lg][pos]=a[pos];
for(int k=pos+1;k<min(pos+add,n);k++)buf[lg][k]=f(buf[lg][k-1],a[k]);
}
}
}
T query(int L,int R){
if(L>=--R)return buf[0][L];
return f(buf[height[L^R]][L],buf[height[L^R]][R]);
}
};
/**
* @brief Disjoint Sparse Table
*/
#line 2 "library/DataStructure/lazysegtree.hpp"
template <typename M, typename N, M (*f)(M, M), M (*g)(M, N), N (*h)(N, N),
M (*m1)(), N (*n1)()>
class LazySegmentTree {
int n, sz, height;
vector<M> data;
vector<N> lazy;
void update(int k) {
data[k] = f(data[k * 2], data[k * 2 + 1]);
}
void apply(int k, N x) {
data[k] = g(data[k], x);
if (k < sz)
lazy[k] = h(lazy[k], x);
}
void down(int k) {
apply(k * 2, lazy[k]);
apply(k * 2 + 1, lazy[k]);
lazy[k] = n1();
}
public:
LazySegmentTree(int n = 0) : LazySegmentTree(vector<M>(n, m1())) {}
LazySegmentTree(const vector<M> &a) : n(SZ(a)) {
sz = 1, height = 0;
while (sz < (int)a.size())
sz <<= 1, height++;
data.assign(2 * sz, m1());
lazy.assign(sz, n1());
rep(i, 0, a.size()) data[sz + i] = a[i];
for (int i = sz - 1; i; i--)
update(i);
}
M operator[](int k) const {
k += sz;
rrep(i, 1, height + 1) down(k >> i);
return data[k];
}
vector<M> get() {
rep(k, 1, sz) down(k);
return {data.begin() + sz, data.begin() + sz + n};
}
void set(int k, M x) {
k += sz;
for (int i = height; i; i--)
down(k >> i);
data[k] = x;
for (int i = 1; i <= height; i++)
update(k >> i);
}
void update(int L, int R, N x) {
if (L >= R)
return;
L += sz, R += sz;
for (int i = height; i; i--) {
if (((L >> i) << i) != L)
down(L >> i);
if (((R >> i) << i) != R)
down((R - 1) >> i);
}
int lb = L, rb = R;
while (L < R) {
if (L & 1)
apply(L++, x);
if (R & 1)
apply(--R, x);
L >>= 1;
R >>= 1;
}
L = lb, R = rb;
for (int i = 1; i <= height; i++) {
if (((L >> i) << i) != L)
update(L >> i);
if (((R >> i) << i) != R)
update((R - 1) >> i);
}
}
M query(int L, int R) {
if (L >= R)
return m1();
L += sz, R += sz;
for (int i = height; i; i--) {
if (((L >> i) << i) != L)
down(L >> i);
if (((R >> i) << i) != R)
down((R - 1) >> i);
}
M lb = m1(), rb = m1();
while (L < R) {
if (L & 1)
lb = f(lb, data[L++]);
if (R & 1)
rb = f(data[--R], rb);
L >>= 1;
R >>= 1;
}
return f(lb, rb);
}
template <class F> int max_right(int L, F ch) {
if (L == n)
return n;
L += sz;
rrep(i, 1, height + 1) down(L >> i);
M sum = m1();
do {
while (L % 2 == 0)
L >>= 1;
if (!ch(f(sum, data[L]))) {
while (L < sz) {
down(L);
L <<= 1;
if (ch(f(sum, data[L])))
sum = f(sum, data[L++]);
}
return L - sz;
}
sum = f(sum, data[L++]);
} while ((L & -L) != L);
return n;
}
template <class F> int min_left(int R, F ch) {
if (R == 0)
return 0;
R += sz;
rrep(i, 1, height + 1) down((R - 1) >> i);
M sum = m1();
do {
R--;
while (R > 1 and (R & 1))
R >>= 1;
if (!ch(f(data[R], sum))) {
while (R < sz) {
down(R);
R = (R * 2 + 1);
if (ch(f(data[R], sum))) {
sum = f(data[R--], sum);
}
}
return R + 1 - sz;
}
sum = f(data[R], sum);
} while ((R & -R) != R);
return 0;
}
};
/**
* @brief Lazy Segment Tree
*/
#line 6 "sol.cpp"
i128 op(int a, int b) {
return min(a + b, 2);
}
using P = pair<int, i128>;
P f(P a, P b) {
i128 ret = 0;
rep(bit, 0, 63) {
ret |= op(a.second >> (bit * 2) & 3, b.second >> (bit * 2) & 3)
<< (bit * 2);
}
return {a.first + b.first, ret};
}
// 作用:and
P g(P a, ll b) {
i128 ret = a.second;
rep(bit, 0, 63) if (!(b >> bit & 1)) {
ret &= ~(i128(3) << (bit * 2));
ret |= i128(min(2, a.first)) << (bit * 2);
}
return {a.first, ret};
}
ll h(ll a, ll b) {
return a & b;
}
P m1() {
return {0, 0};
}
ll n1() {
return INT64_MAX;
}
ll F(ll a, ll b) {
return a & b;
}
ll G(ll a, ll b) {
return a & b;
}
ll H(ll a, ll b) {
return a & b;
}
int main() {
int n, Q;
read(n, Q);
vector<ll> a(n);
read(a);
LazySegmentTree<P, ll, f, g, h, m1, n1> seg(n);
LazySegmentTree<ll, ll, F, G, H, n1, n1> seg2(n);
rep(i, 0, n) {
i128 x = 0;
rep(bit, 0, 63) if (!(a[i] >> bit & 1)) x |= i128(1) << (bit * 2);
seg.set(i, {1, x});
seg2.set(i, a[i]);
}
while (Q--) {
int type;
read(type);
if (type == 1) {
int L, R;
ll x;
read(L, R, x);
L--;
seg.update(L, R, x);
seg2.update(L, R, x);
} else if (type == 2) {
int s;
ll y;
read(s, y);
s--;
i128 x = 0;
rep(bit, 0, 63) if (!(y >> bit & 1)) x |= i128(1) << (bit * 2);
seg.set(s, {1, x});
seg2.set(s, y);
} else {
int L, R;
read(L, R);
L--;
auto [_, sub] = seg.query(L, R);
int tar = -1;
rrep(bit, 0, 63) {
int cnt = (sub >> (bit * 2)) & 3;
if (cnt == 1) {
tar = bit;
break;
}
}
if (tar == -1) {
ll ret = 0;
rep(bit, 0, 63) {
int cnt = (sub >> (bit * 2)) & 3;
if (cnt == 0)
ret |= 1LL << bit;
}
print(ret);
continue;
}
// detect remove elem
auto ch = [&](P x) -> bool {
return (x.second >> (tar * 2) & 3) == 0;
};
int pos = seg.max_right(L, ch);
show(L, R, tar, pos);
assert(pos < R);
ll ret = (1LL << 63) - 1;
if (L < pos)
ret &= seg2.query(L, pos);
if (pos + 1 < R)
ret &= seg2.query(pos + 1, R);
print(ret);
}
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 0ms
memory: 3584kb
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: 3704kb
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: 4008kb
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: 6ms
memory: 4144kb
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: 1454ms
memory: 17440kb
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...