QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#867002#9727. Barkley IIImeisgoodWA 1ms5960kbC++203.0kb2025-01-22 23:56:042025-01-22 23:56:04

Judging History

你现在查看的是最新测评结果

  • [2025-01-22 23:56:04]
  • 评测
  • 测评结果:WA
  • 用时:1ms
  • 内存:5960kb
  • [2025-01-22 23:56:04]
  • 提交

answer

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MAXN=1e6+5;
ll tests, n, m, a[MAXN], op, aa, bb, cc, ans, pw[63];
struct Node{
  int pos[63], l, r;
  ll sum;
  Node operator +(const Node &o)const{
    Node res;
    res.l=l;
    res.r=o.r;
    res.sum=sum|o.sum;
    for(ll i=0; i<63; i++){
      if(pos[i]==-1||o.pos[i]==-1||(pos[i]&&o.pos[i])){
        res.pos[i]=-1;
      }
      else if(pos[i]&&!o.pos[i]){
        res.pos[i]=pos[i];
      }
      else if(!pos[i]&&o.pos[i]){
        res.pos[i]=o.pos[i];
      }
      else{
        res.pos[i]=0;
      }
    }
    return res;
  }
}tmp;
struct SegTree{
  Node tr[2*MAXN];
  void Pushup(ll x){
    tr[x]=tr[x*2]+tr[x*2+1];
  }
  void Build(ll l, ll r, ll x){
    tr[x].l=l;
    tr[x].r=r;
    if(tr[x].l==tr[x].r){
      tr[x].sum=a[tr[x].l];
      for(ll i=0; i<63; i++){
        tr[x].pos[i]=((tr[x].sum&pw[i])==0)?tr[x].l:0;
      }
      return;
    }
    ll mid=(l+r)/2;
    Build(l, mid, x*2);
    Build(mid+1, r, x*2+1);
    Pushup(x);
  }
  void Update_Range(ll l, ll r, ll v, ll x){
    if(tr[x].l==tr[x].r){
      tr[x].sum&=v;
      for(ll i=0; i<63; i++){
        tr[x].pos[i]=((tr[x].sum&pw[i])==0)?tr[x].l:0;
      }
      return;
    }
    if(tr[x*2].r>=l&&(tr[x*2].sum&v)){
      Update_Range(l, r, v, x*2);
    }
    if(tr[x*2+1].l<=r&&(tr[x*2+1].sum&v)){
      Update_Range(l, r, v, x*2+1);
    }
    Pushup(x);
  }
  void Update_Point(ll pos, ll v, ll x){
    if(tr[x].l==tr[x].r){
      tr[x].sum=v;
      for(ll i=0; i<63; i++){
        tr[x].pos[i]=((tr[x].sum&pw[i])==0)?tr[x].l:0;
      }
      return;
    }
    if(tr[x*2].r>=pos){
      Update_Point(pos, v, x*2);
    }
    else{
      Update_Point(pos, v, x*2+1);
    }
    Pushup(x);
  }
  Node Query(ll l, ll r, ll x){
    if(tr[x].l>=l&&tr[x].r<=r){
      return tr[x];
    }
    Node ret;
    ret.sum=ret.l=ret.r=0;
    for(ll i=0; i<63; i++){
      ret.pos[i]=0;
    }
    if(tr[x*2].r>=l){
      ret=ret+Query(l, r, x*2);
    }
    if(tr[x*2+1].l<=r){
      ret=ret+Query(l, r, x*2+1);
    }
    return ret;
  }
}t;
int main(){
  pw[0]=1;
  for(ll i=1; i<63; i++){
    pw[i]=pw[i-1]*2;
  }
  scanf("%lld%lld", &n, &m);
  for(ll i=1; i<=n; i++){
    scanf("%lld", &a[i]);
  }
  t.Build(1, n, 1);
  while(m--){
    scanf("%lld", &op);
    if(op==1){
      scanf("%lld%lld%lld", &aa, &bb, &cc);
      t.Update_Range(aa, bb, cc, 1);
    }
    else if(op==2){
      scanf("%lld%lld", &aa, &bb);
      t.Update_Point(aa, bb, 1);
    }
    else{
      scanf("%lld%lld", &aa, &bb);
      tmp=t.Query(aa, bb, 1);
      ans=0;
      cc=-1;
      for(ll i=62; i>=0; i--){
        if(tmp.pos[i]==0){
          ans+=pw[i];
          continue;
        }
        if(tmp.pos[i]!=0&&tmp.pos[i]!=-1&&(cc==-1||cc==tmp.pos[i])){
          cc=tmp.pos[i];
          ans+=pw[i];
        }
      }
      printf("%lld\n", ans);
    }
  }
	return 0 ;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 5956kb

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: 5956kb

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: -100
Wrong Answer
time: 0ms
memory: 5960kb

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:

wrong answer 68th lines differ - expected: '0', found: '589824'