QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#557536 | #8672. 排队 | -xcxxx- | 0 | 179ms | 78808kb | C++14 | 3.2kb | 2024-09-11 10:12:52 | 2024-09-11 10:12:53 |
Judging History
answer
#include<bits/stdc++.h>
using namespace std;
int rd() {int x=0,f=1;char c=getchar();while(!isdigit(c))f=(c=='-'?-1:f),c=getchar();while(isdigit(c))x=x*10+c-'0',c=getchar();return x*f;}
const int N=1000005,inf=0x3f3f3f3f;
int n,Q,l[N],r[N],ans[N];
vector<int> ins[N],ers[N];
struct ChristmasTree {
#define ls (p<<1)
#define rs (p<<1|1)
#define mid ((T[p].l+T[p].r)>>1)
struct node {
int l,r,mx,mn,tag;
void upd(int x) {mx+=x,mn+=x,tag+=x;}
}T[N<<2];
void pushup(int p) {
T[p].mx=max(T[ls].mx,T[rs].mx);
T[p].mn=min(T[ls].mn,T[rs].mn);
}
void pushdown(int p) {
T[ls].upd(T[p].tag);
T[rs].upd(T[p].tag);
T[p].tag=0;
}
void build(int l=1,int r=Q,int p=1) {
T[p].l=l,T[p].r=r;
T[p].mx=-inf,T[p].mn=inf;
if(l==r) return;
build(l,mid,ls);
build(mid+1,r,rs);
}
void modify(int l,int r,int p=1) {
if(T[p].l==l&&T[p].r==r) {
T[p].upd(1);
return;
}
pushdown(p);
if(r<=mid) modify(l,mid,ls);
else if(mid<l) modify(mid+1,r,rs);
else modify(l,mid,ls),modify(mid+1,r,rs);
pushup(p);
}
int qfst(int k,int p=1) {
if(T[p].mn<k) return T[p].r+1;
if(T[p].l==T[p].r) return T[p].l;
pushdown(p);
if(T[ls].mn<=k) return qfst(k,ls);
else return qfst(k,rs);
}
int qlst(int k,int p=1) {
if(T[p].mx<k) return T[p].l-1;
if(T[p].l==T[p].r) return T[p].l;
pushdown(p);
if(T[rs].mx>=k) return qlst(k,rs);
else return qlst(k,ls);
}
void insert(int pos,int p=1) {
// fprintf(stderr,"insert [%d,%d] %d\n",T[p].l,T[p].r,pos);
if(T[p].l==T[p].r) {
T[p].mx=T[p].mn=0;
return;
}
pushdown(p);
if(pos<=mid) insert(pos,ls);
else insert(pos,rs);
pushup(p);
}
void erase(int pos,int p=1) {
// fprintf(stderr,"erase [%d,%d] %d\n",T[p].l,T[p].r,pos);
if(T[p].l==T[p].r) {
T[p].mx=-inf,T[p].mn=inf;
return;
}
pushdown(p);
if(pos<=mid) erase(pos,ls);
else erase(pos,rs);
pushup(p);
}
int ask(int pos,int p=1) {
if(T[p].l==T[p].r) return T[p].mx;
pushdown(p);
if(pos<=mid) return ask(pos,ls);
else return ask(pos,rs);
}
}tree;
signed main() {
n=rd(),Q=rd();
for(int i=1;i<=n;i++) l[i]=rd(),r[i]=rd();
for(int i=1;i<=Q;i++) ins[rd()].push_back(i),ers[rd()].push_back(i);
tree.build();
for(int i=1;i<=n;i++) {
// fprintf(stderr,"i=%d\n",i);
for(int p:ins[i]) tree.insert(p);
int L=tree.qfst(r[i]),R=tree.qlst(l[i]);
// fprintf(stderr,"L=%d R=%d\n",L,R);
// for(int j=1;j<=Q;j++) cerr<<tree.ask(j)<<' ';cerr<<endl;
if(L<=R) tree.modify(L,R);
// for(int j=1;j<=Q;j++) cerr<<tree.ask(j)<<' ';cerr<<endl;
for(int p:ers[i]) {
ans[p]=tree.ask(p);
tree.erase(p);
}
}
for(int i=1;i<=Q;i++) printf("%d\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: 3ms
memory: 57096kb
input:
3 3 0 0 1 2 0 2 1 1 1 3 2 3
output:
1 1 0
result:
wrong answer 2nd numbers differ - expected: '3', found: '1'
Subtask #2:
score: 0
Wrong Answer
Test #12:
score: 0
Wrong Answer
time: 139ms
memory: 72640kb
input:
200000 200000 3 6 3 3 6 10 1 7 2 7 6 9 4 6 3 4 0 8 0 6 3 5 3 4 1 8 7 8 4 5 0 3 1 5 2 9 1 2 1 2 3 4 5 7 6 10 3 9 4 7 1 6 2 6 1 7 2 5 1 7 6 8 1 1 0 7 7 8 0 9 1 7 3 8 3 7 1 2 4 8 5 6 0 6 5 6 2 7 2 6 0 6 0 6 1 7 2 5 0 3 0 3 7 10 3 8 0 2 3 4 3 7 4 9 0 6 4 7 2 6 8 10 2 10 4 10 3 3 2 6 4 5 3 9 1 8 1 2 2 9 ...
output:
11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 11 ...
result:
wrong answer 362nd numbers differ - expected: '11', found: '10'
Subtask #3:
score: 0
Wrong Answer
Test #22:
score: 0
Wrong Answer
time: 179ms
memory: 78808kb
input:
200000 200000 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 0 0 9 0 10 0 0 0 0 0 13 0 14 0 0 0 16 0 17 0 18 0 19 0 0 0 21 0 22 0 23 0 0 0 0 0 0 0 0 0 28 0 0 0 30 0 31 0 32 0 33 0 34 0 35 0 0 0 0 0 38 0 39 0 40 0 41 0 42 0 43 0 44 0 45 0 46 0 0 0 48 0 49 0 50 0 51 0 52 0 53 0 54 0 55 0 56 0 57 0 0 0 59 0 60 0 0 0 0 ...
output:
1 1 1 2 2 1 1 9 1 9 6 7 1 3 7 16 11 15 17 5 8 4 10 4 18 2 2 26 27 43 9 1 6 13 14 35 4 17 25 24 15 30 5 35 23 16 42 24 8 18 75 8 86 52 40 1 67 20 4 2 8 26 47 5 41 55 47 39 8 20 4 18 8 78 70 50 3 31 1 13 11 23 13 71 73 30 49 2 51 44 13 19 10 18 37 46 9 55 17 15 68 6 15 102 17 53 9 86 19 152 137 137 49...
result:
wrong answer 1st numbers differ - expected: '19141', found: '1'
Subtask #4:
score: 0
Wrong Answer
Test #32:
score: 0
Wrong Answer
time: 165ms
memory: 75552kb
input:
200000 200000 0 200000 1 200000 1 200000 0 200000 0 200000 1 200000 1 200000 1 200000 0 200000 1 200000 0 200000 0 200000 1 200000 0 200000 0 200000 0 200000 0 200000 1 200000 0 200000 0 200000 1 200000 0 200000 1 200000 1 200000 1 200000 1 200000 0 200000 0 200000 1 200000 2 200000 1 200000 2 20000...
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 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 ...
result:
wrong answer 1st numbers differ - expected: '71224', found: '0'
Subtask #5:
score: 0
Skipped
Dependency #1:
0%
Subtask #6:
score: 0
Skipped
Dependency #5:
0%