QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#120489 | #6608. Descent of Dragons | shr_ | WA | 2ms | 9460kb | C++14 | 2.3kb | 2023-07-06 19:22:47 | 2023-07-06 19:22:50 |
Judging History
answer
# include <bits/stdc++.h>
using namespace std;
int n,m;
struct operation { int opt,l,r,x;} op[500010];
struct Persistent_SegmentTree {
int l,r,cnt,ro[500010];
struct node { int son[2];} f[20000010];
int get_newnode_() { cnt++, f[cnt].son[0]=f[cnt].son[1]=0; return cnt;}
int build_(int l,int r) {
int x=get_newnode_();
if (l==r) return x;
int mid=(l+r)>>1;
f[x].son[0]=build_(l,mid), f[x].son[1]=build_(mid+1,r);
return x;
}
int copy_(int x,int y,int l,int r,int lpos,int rpos) {
if (lpos<=l&&r<=rpos) return y;
if (!y) return 0;
int k=get_newnode_(); f[k].son[0]=f[x].son[0], f[k].son[1]=f[x].son[1];
int mid=(l+r)>>1;
if (lpos<=mid) f[k].son[0]=copy_(f[k].son[0],f[y].son[0],l,mid,lpos,rpos);
if (mid<rpos) f[k].son[1]=copy_(f[k].son[1],f[y].son[1],mid+1,r,lpos,rpos);
return k;
}
bool check_(int x,int l,int r,int lpos,int rpos) {
if (!x) return false;
if (lpos<=l&&r<=rpos) return true;
bool ans=0;
int mid=(l+r)>>1;
if (lpos<=mid) ans|=check_(f[x].son[0],l,mid,lpos,rpos);
if (mid<rpos) ans|=check_(f[x].son[1],mid+1,r,lpos,rpos);
return ans;
}
void init_(int _l,int _r) { l=_l, r=_r, cnt=0, memset(ro,0,sizeof(ro));}
void build_(int a) { ro[a]=build_(l,r);}
void copy_(int a,int b,int l,int r) { ro[a]=copy_(ro[a],ro[b],this -> l,this -> r,l,r);}
bool check_(int a,int l,int r) { return check_(ro[a],this -> l,this -> r,l,r);}
} pst;
int main() {
// freopen("in.in","r",stdin);
// freopen("out.out","w",stdout);
scanf("%d%d",&n,&m);
for (int i=1;i<=m;i++) {
scanf("%d",&op[i].opt);
if (op[i].opt==1) scanf("%d%d%d",&op[i].l,&op[i].r,&op[i].x);
else scanf("%d%d",&op[i].l,&op[i].r);
}
vector<int> ans;
pst.init_(1,n), pst.build_(0);
for (int i=1;i<=m;i++) {
if (op[i].opt==1) pst.copy_(op[i].x+1,op[i].x,op[i].l,op[i].r);
else {
int l=1,r=m+1;
while (l<r) {
int mid=(l+r)>>1;
if (pst.check_(mid,op[i].l,op[i].r)) l=mid+1;
else r=mid;
}
ans.push_back(l-1);
}
}
for (auto o : ans) printf("%d\n",o);
fprintf(stderr,"%lf\n",clock()/1.0/CLOCKS_PER_SEC);
return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 2ms
memory: 8348kb
input:
5 5 1 3 5 0 1 1 4 1 1 1 5 2 2 2 2 2 4 5
output:
0 3
result:
ok 2 number(s): "0 3"
Test #2:
score: -100
Wrong Answer
time: 0ms
memory: 9460kb
input:
1000 1000 2 234 913 1 693 735 47 1 702 959 94 2 273 286 1 814 896 47 1 560 566 15 1 46 699 97 2 494 527 1 721 879 68 1 87 437 26 1 163 938 15 1 816 912 58 2 284 670 2 713 763 1 49 542 13 1 669 874 41 2 795 855 1 601 962 93 1 413 747 50 1 528 710 73 2 255 435 1 329 871 86 1 24 236 48 1 22 48 41 1 29 ...
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 1 0 0 1 0 1 0 0 0 0 0 2 2 0 2 0 0 0 0 2 0 2 2 2 2 2 2 2 2 2 2 0 0 2 0 0 0 3 3 3 0 0 0 1 1 1 3 2 2 2 2 3 1 3 2 2 3 3 2 2 1 3 2 3 3 3 3 3 3 3 2 2 3 3 2 3 2 1 3 3 2 1 3 3 3 1 1 2 2 3 3 1 1 3 3 2 2 2 3 3 3 2 3 2 2 3 3 2 3 1 3 3 2 3 4 4 4 4 2 4 2 4 4 4 ...
result:
wrong answer 117th numbers differ - expected: '2', found: '3'