QOJ.ac
QOJ
ID | 题目 | 提交者 | 结果 | 用时 | 内存 | 语言 | 文件大小 | 提交时间 | 测评时间 |
---|---|---|---|---|---|---|---|---|---|
#761983 | #9727. Barkley III | fhq_treap | WA | 8ms | 132148kb | C++14 | 4.9kb | 2024-11-19 12:05:10 | 2024-11-19 12:05:10 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mit map<int,int>::iterator
#define sit set<int>::iterator
#define itrm(g,x) for(mit g=x.begin();g!=x.end();g++)
#define itrs(g,x) for(sit g=x.begin();g!=x.end();g++)
#define ltype int
#define rep(i,j,k) for(ltype(i)=(j);(i)<=(k);(i)++)
#define rap(i,j,k) for(ltype(i)=(j);(i)<(k);(i)++)
#define per(i,j,k) for(ltype(i)=(j);(i)>=(k);(i)--)
#define pii pair<int,int>
#define fi first
#define se second
#define mpr make_pair
#define pb push_back
#define fastio ios::sync_with_stdio(false)
#define check(x) if(x>=mod) x-=mod
const int inf=0x3f3f3f3f,mod=1000000007;
const double pi=3.1415926535897932,eps=1e-6;
void chmax(int &x,int y){if(x < y) x = y;}
void chmin(int &x,int y){if(x > y) x = y;}
int qpow(int x,int y){
int ret = 1;
while(y) {
if(y & 1) ret = (ll)ret * x % mod;
x = (ll)x * x % mod;
y >>= 1;
}
return ret;
}
typedef pair<ll,ll> pll;
void read(int &x){
x = 0;char ch = getchar();
while(!isdigit(ch))ch = getchar();
while(isdigit(ch))x=x*10+(ch-'0'),ch=getchar();
}
void read(ll &x){
x = 0;char ch = getchar();
while(!isdigit(ch))ch = getchar();
while(isdigit(ch))x=x*10+(ch-'0'),ch=getchar();
}
int n,q;ll a[1000005];
pll merge(pll x,pll y){
return mpr(x.fi | y.fi, x.se | y.se | (x.fi & y.fi));
}
const ll full = (1ULL << 63) - 1;
struct segtree{
int n;pll dat[8000005];ll tag[8000005];
void build(int nn)
{
n=1;
while(n<=nn) n<<=1;
rep(i,1,::n) dat[i + n - 1] = mpr(full ^ a[i], 0);
per(i,n-2,0) {
dat[i] = merge(dat[(i << 1) + 1], dat[(i << 1) + 2]);
}
rep(i,0,2 * n) tag[i] = full;
//for(int i=0;i<n;i++) dat[i]=inf;
}
void push(int x,int l,int r){
dat[x].fi |= (full ^ tag[x]);
if(r - l > 1) dat[x].se |= (full ^ tag[x]);
if(r - l > 1) {tag[(x << 1) + 1] &= tag[x];tag[(x << 1) + 2] &= tag[x];}
tag[x] = full;
}
void update(int a,int b,int x){update(0,0,n,a,b+1,x);}
pll update(int k,int l,int r,int a,int b,ll x){
push(k, l, r);
if(r<=a||b<=l) return dat[k];
//printf("%d %d %d %d %d\n",k,l,r,a,b);
if(a<=l&&r<=b){
tag[k] = x;
push(k, l, r);
return dat[k];
}
dat[k]=merge(update((k<<1)+1,l,(l+r)>>1,a,b,x),update((k<<1)+2,(l+r)>>1,r,a,b,x));
return dat[k];
}
void change(int x,ll v){change(0,0,n,x,v);}
pll change(int k,int l,int r,int x,ll v){
push(k, l, r);
if(x<l||x>=r) return dat[k];
//printf("%d %d %d %d %d\n",k,l,r,a,b);
if(r - l == 1){
dat[k] = mpr(full ^ v, 0);
return dat[k];
}
dat[k]=merge(change((k<<1)+1,l,(l+r)>>1,x,v),change((k<<1)+2,(l+r)>>1,r,x,v));
return dat[k];
}
pll query(int l,int r){
return query(l,r+1,0,0,n);
}
pll query(int a,int b,int k,int l,int r){
push(k, l, r);
if(r<=a||b<=l) return mpr(0,0);
if(a<=l&&r<=b) return dat[k];
return merge(query(a,b,(k<<1)+1,l,(l+r)>>1),query(a,b,(k<<1)+2,(l+r)>>1,r));
}
int bsearch(int k,int l,int r,int a,int b,ll bit){
push(k, l, r);
if(r <= a || b <= l) return -1;
if(r - l == 1) {
if(!(dat[k].fi & bit)) return -1;
return l;
}
if(a <= l && r <= b) {
if(!(dat[k].fi & bit)) return -1;
}
int ret = bsearch((k << 1) + 1, l, (l + r) >> 1, a, b, bit);
if(ret != -1) return ret;
return bsearch((k << 1) + 2, (l + r) >> 1, r, a, b, bit);
}
int bsearch(int l,int r,ll bit){
return bsearch(0, 0, n, l, r + 1, bit);
}
}seg;
int main()
{
read(n);read(q);
rep(i,1,n) read(a[i]);
seg.build(n);
rep(i,1,q) {
int op;read(op);
if(op == 1) {
int l,r;ll x;
read(l);read(r);read(x);
seg.update(l, r, x);
}
if(op == 2) {
int x;ll v;
read(x);read(v);
seg.change(x, v);
}
if(op == 3) {
int l,r;
read(l);read(r);
auto res = seg.query(l, r);
ll good = res.fi & (full ^ res.se);
if(n == 10) printf("%lld\n",good);
ll high = -1;
per(i,62,0) if(good & (1ll << i)) {high = 1ll << i;break;}
if(high == -1) {
printf("%lld\n",full ^ res.fi);
continue;
}
int pos = seg.bsearch(l, r, high);
auto L = seg.query(l, pos - 1), R = seg.query(pos + 1, r);
ll ans = full;
if(pos != l) ans &= (full ^ L.fi);
if(pos != r) ans &= (full ^ R.fi);
printf("%lld\n",ans);
}
}
return 0;
}
詳細信息
Test #1:
score: 100
Accepted
time: 8ms
memory: 130988kb
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: -100
Wrong Answer
time: 0ms
memory: 132148kb
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:
415043666432753952 1568091718842717482 536870912 536870912 288 537919776 8620447023302952690 8795942500783873690
result:
wrong answer 1st lines differ - expected: '1568091718842717482', found: '415043666432753952'