QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#470671 | #5022. 【模板】线段树 | DaiRuiChen007 | 0 | 1387ms | 26048kb | C++17 | 2.9kb | 2024-07-10 15:45:58 | 2024-07-10 15:45:59 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
template<class T>
auto ary(T *a,int l,int r){
return vector<T>{a+l,a+1+r};
}
using ll=long long;
using ull=unsigned long long;
const int N=2.5e5+10;
int n,m,q,a[N],b[N],is[N];
vector<int>idx;
ll res[N],ans[N];
vector<pair<int,int>>que[N];
int pos[N],bg[N],ed[N];
vector<int>laz[N];
void rebuild(int id){
int *a=::a+bg[id],*b=::b+bg[id],len=ed[id]-bg[id]+1;
for(int i=0;i<len;++i) b[i]=a[len-i];
copy(a,a+len,b);
for(int i=0;(1<<i)<len;i++){
for(int j=0;j<len;j++){
if(j>>i&1)b[j]^=b[j^1<<i];
}
}
}
void reduce(int id){
int S=laz[id].size();
int *a=::a+bg[id],len=ed[id]-bg[id]+1;
for(int i=0;(1<<i)<=min(S,len-1);i++)if(S>>i&1){
for(int j=len-1;j>=(1<<i);j--){
a[j]^=a[j-(1<<i)];
}
}
reverse(all(laz[id]));
for(int i=0;(1<<i)<S;i++){
for(int j=S-1;j>=0;j--){
if(j>>i&1)laz[id][j^1<<i]^=laz[id][j];
}
}
for(int i=0;i<S&&i<len;i++)a[i]^=laz[id][i];
laz[id].clear();
}
int back(int id){
int d=ed[id]-bg[id];
if(laz[id].size()>d)reduce(id),rebuild(id);
int cnt=laz[id].size();
return b[cnt];
}
void update(int l,int r){
if(pos[l]==pos[r]){
reduce(pos[l]);
for(int i=r;i>l;i--)a[i]^=a[i-1];
return rebuild(pos[l]);
}
reduce(pos[r]);
for(int i=r;i>bg[pos[r]];i--)a[i]^=a[i-1];
a[bg[pos[r]]]^=back(pos[r]-1);
rebuild(pos[r]);
for(int i=pos[r]-1;i>pos[l];i--){
laz[i].push_back(back(i-1));
}
reduce(pos[l]);
for(int i=ed[pos[l]];i>l;i--)a[i]^=a[i-1];
rebuild(pos[l]);
}
int query(int i){
reduce(pos[i]),rebuild(pos[i]);
return a[i];
}
int main(){
// freopen("sgt.in","r",stdin);
// freopen("sgt.out","w",stdout);
scanf("%*d%d%d",&n,&m),q=0;
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
for(int i=1,x,y;i<=q;i++){
scanf("%d%d",&x,&y);
idx.push_back(x),is[x]=1;
if(y)que[y].push_back({x,i});
else ans[i]=a[x];
}
sort(all(idx)),idx.erase(unique(all(idx)),idx.end());
for(int x:idx)res[x]=a[x];
int B=1<<9;
for(int i=1,p=1,cnt=0;i<=n;i++){
if(is[i-1]||cnt==B)cnt=0,p++;
pos[i]=p,cnt++;
}
for(int i=1;i<=n;i++)ed[pos[i]]=i;
for(int i=n;i>=1;i--)bg[pos[i]]=i;
for(int i=1;i<=pos[n];i++)rebuild(i);
for(int i=1,op,x,y;i<=m;i++){
scanf("%d%d",&op,&x);
if(op==1){
scanf("%d",&y);
update(x,y);
}else{
printf("ans = %d\n",query(x));
}
for(int x:idx)res[x]+=back(pos[x]);
// for(auto [x,id]:que[i])ans[id]=res[x];
}
for(int i=1;i<=pos[n];i++)reduce(i);
for(int i=1;i<=n;i++)printf("%d\n",a[i]);
for(int i=1;i<=q;i++)printf("%lld\n",ans[i]);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Subtask #1:
score: 0
Wrong Answer
Test #1:
score: 0
Wrong Answer
time: 0ms
memory: 22660kb
input:
1 6 6 1 1 5 1 9 4 2 5 1 2 5 2 4 1 3 6 2 6 1 1 6
output:
ans = 9 ans = 4 ans = 12 1 0 5 4 12 0
result:
wrong output format Expected integer, but "ans" found
Subtask #2:
score: 0
Wrong Answer
Test #6:
score: 0
Wrong Answer
time: 819ms
memory: 23820kb
input:
2 249998 99999 1048488450 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 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 ...
output:
ans = 0 ans = 0 ans = 0 ans = 0 ans = 0 ans = 0 ans = 0 ans = 0 ans = 0 ans = 0 ans = 0 ans = 0 ans = 0 ans = 0 ans = 0 ans = 0 ans = 0 ans = 0 ans = 0 ans = 0 ans = 0 ans = 0 ans = 0 ans = 0 ans = 0 ans = 0 ans = 0 ans = 0 ans = 0 ans = 0 ans = 0 ans = 0 ans = 0 ans = 0 ans = 0 ans = 0 ans = 0 ans ...
result:
wrong output format Expected integer, but "ans" found
Subtask #3:
score: 0
Wrong Answer
Test #10:
score: 0
Wrong Answer
time: 780ms
memory: 23972kb
input:
3 250000 99999 1 1 1 1 1 0 1 0 1 1 0 1 0 1 1 1 1 1 1 0 1 0 1 0 1 1 1 0 0 0 0 0 1 0 1 1 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0 0 0 1 1 1 0 0 0 1 0 1 0 0 1 0 0 1 1 1 0 0 0 1 1 1 1 1 1 0 0 1 1 1 1 0 0 0 0 1 1 0 0 1 1 0 1 1 0 1 1 0 1 1 1 0 0 1 1 0 0 1 1 1 0 1 1 1 1 1 0 1 0 1 0 0 1 0 1 1 1 0 1 1 0 1 1 0 1 0 0 1 1...
output:
ans = 0 ans = 0 ans = 0 ans = 0 ans = 1 ans = 0 ans = 1 ans = 0 ans = 0 ans = 0 ans = 0 ans = 0 ans = 1 ans = 1 ans = 0 ans = 1 ans = 0 ans = 0 ans = 0 ans = 0 ans = 1 ans = 1 ans = 0 ans = 1 ans = 1 ans = 0 ans = 1 ans = 0 ans = 1 ans = 1 ans = 1 ans = 0 ans = 1 ans = 1 ans = 1 ans = 0 ans = 1 ans ...
result:
wrong output format Expected integer, but "ans" found
Subtask #4:
score: 0
Wrong Answer
Test #14:
score: 0
Wrong Answer
time: 913ms
memory: 26048kb
input:
4 249996 99997 309331355 195839266 912372930 57974187 363345291 954954162 650621300 389049294 821214285 263720748 231045308 844370953 768579771 664766522 681320982 124177317 32442094 297873605 743179832 1073656106 443742270 235746807 1054294813 974443618 422427461 307448375 1018255356 20105813 36821...
output:
ans = 611117059 ans = 866091251 ans = 300188933 ans = 0 ans = 478915924 ans = 1053588351 ans = 453142424 ans = 897441996 ans = 60971719 ans = 748656483 ans = 600408393 ans = 0 ans = 303761852 ans = 983037069 ans = 883016404 ans = 332332552 ans = 1069626159 ans = 860304528 ans = 851235295 ans = 56127...
result:
wrong output format Expected integer, but "ans" found
Subtask #5:
score: 0
Wrong Answer
Test #18:
score: 0
Wrong Answer
time: 1387ms
memory: 24312kb
input:
5 249997 99997 860563869 428592873 58576739 761578583 47999879 294581118 988847649 569566599 640106250 440172702 178219106 966598261 763325707 846927552 877923116 145156535 246778542 25949847 507939778 116507169 555239769 259969305 328955819 171606729 535970481 121608060 4437163 370976515 713807003 ...
output:
860563869 717285236 452329866 773393204 485721677 965902221 831024341 890990738 455498944 92913689 556500009 102303365 264515518 445496274 654612933 988537886 165104807 364103659 952755344 576499197 775866335 1003839403 606880290 1006459039 1005979559 588810854 592470517 765610807 123827263 86327854...
result:
wrong answer 513th numbers differ - expected: '897949217', found: '613284021'
Subtask #6:
score: 0
Skipped
Dependency #5:
0%
Subtask #7:
score: 0
Skipped
Dependency #5:
0%
Subtask #8:
score: 0
Skipped
Dependency #1:
0%