QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#120359 | #6608. Descent of Dragons | ballad | WA | 1ms | 3600kb | C++20 | 1.5kb | 2023-07-06 17:04:11 | 2023-07-06 17:04:14 |
Judging History
answer
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
const int N=5e5+10;
int rt[N],tot;
struct node{
int val,ls,rs;
}stree[N*40];
int clone(int x){
stree[++tot]=stree[x];
return tot;
}
#define ls(x) (stree[x].ls)
#define rs(x) (stree[x].rs)
#define mid ((l+r)>>1)
void pushup(int x){
stree[x].val=stree[ls(x)].val+stree[rs(x)].val;
return;
}
int build(int x, int l, int r){
x=clone(x);
if (l==r){
stree[x].val=1;return x;
}ls(x)=build(ls(x),l,mid);
rs(x)=build(rs(x),mid+1,r);
return pushup(x),x;
}
int change(int x, int y, int l, int r, int cl, int cr){
if (!x) return x;
if (!y) y=clone(y);
if (cl<=l&&r<=cr) return x;
if (cl<=mid) ls(y)=change(ls(x),ls(y),l,mid,cl,cr);
if (cr>mid) rs(y)=change(rs(x),rs(y),mid+1,r,cl,cr);
return pushup(y),y;
}
int query(int x, int l, int r, int ql, int qr){
if (!x) return 0;
if (ql<=l&&r<=qr) return stree[x].val;
if (qr<mid) return query(ls(x),l,mid,ql,qr);
if (ql>mid) return query(rs(x),mid+1,r,ql,qr);
return query(ls(x),l,mid,ql,qr)+query(rs(x),mid+1,r,ql,qr);
}
int main(){
ios::sync_with_stdio(0);
cin.tie(nullptr);cout.tie(nullptr);
int n,q;cin>>n>>q;rt[0]=build(rt[0],1,n);
for (int i=1;i<=q;i++){
int opt,l,r,k;cin>>opt>>l>>r;
if (opt==1){
cin>>k;rt[k+1]=change(rt[k],rt[k+1],1,n,l,r);
}else{
int L=0,R=i;
while (L<=R){
int m=(L+R)>>1;
if (query(rt[m],1,n,l,r)) L=m+1;
else R=m-1;
}cout<<R<<endl;
}
}return 0;
}
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 3396kb
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: 1ms
memory: 3600kb
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 3 2 2 3 3 1 3 2 3 3 3 3 3 1 3 2 3 3 3 3 3 3 3 3 2 3 3 3 3 2 3 3 3 2 1 3 3 3 1 1 3 2 3 3 1 1 3 3 2 3 3 3 3 3 3 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 74th numbers differ - expected: '2', found: '3'