QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#557633#8672. 排队piggy1230 111ms27760kbC++203.8kb2024-09-11 10:37:322024-09-11 10:37:32

Judging History

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

  • [2024-09-11 10:37:32]
  • 评测
  • 测评结果:0
  • 用时:111ms
  • 内存:27760kb
  • [2024-09-11 10:37:32]
  • 提交

answer

#include <bits/stdc++.h>
#define ll long long
using namespace std;

struct B{
	ll l,r,id;
}p[1000005],q[1000005];

struct node{
	ll tag,mx;
}tree[4000005];
ll ans[4000005];

ll getpos(ll root,ll l,ll r,ll v,ll tg=0){
	if (l==r){
		if (tree[root].tag+tg+tree[root].mx>v)return l+1;
		return l;
	}
	ll mid=(l+r)>>1;
	tg+=tree[root].tag;
	if (tree[root<<1].mx+tg+tree[root<<1].tag>v)return getpos(root<<1|1,mid+1,r,v,tg);
	else return getpos(root<<1,l,mid,v,tg);
}

void add(ll root,ll l,ll r,ll L,ll R){
	if (L>R)return;
	if (L<=l&&r<=R){
		tree[root].tag++;
		return;
	}
	ll mid=(l+r)>>1;
	if (L<=mid)add(root<<1,l,mid,L,R);
	if (R>mid)add(root<<1|1,mid+1,r,L,R);
	tree[root].mx=max(tree[root<<1].mx,tree[root<<1|1].mx);
}

ll query(ll root,ll l,ll r,ll pos){
	if (l==r)return tree[root].mx+tree[root].tag;
	ll mid=(l+r)>>1;
	if (pos<=mid)return tree[root].tag+query(root<<1,l,mid,pos);
	else return tree[root].tag+query(root<<1|1,mid+1,r,pos);
}

int main(){
	cin.tie(0);cout.tie(0);
	ios::sync_with_stdio(false);
	ll n,Q;
	cin >> n >> Q;
	for (ll i=1;i<=n;i++){
		cin >> p[i].l >> p[i].r;
	}
	for (ll i=1;i<=Q;i++){
		cin >> q[i].l >> q[i].r;
		q[i].id=i;
	}
	sort(q+1,q+1+Q,[](B a,B b){
		return a.r<b.r;
	});
	ll tp=0;
	for (ll i=1;i<=n;i++){
		ll lp=getpos(1,1,n,p[i].r),rp=getpos(1,1,n,p[i].l-1)-1;
		assert(rp==n);
		add(1,1,n,lp,min(rp,i));
		while (tp+1<=Q&&q[tp+1].r==i)++tp,ans[q[tp].id]=query(1,1,n,q[tp].l);
	}
	for (ll i=1;i<=Q;i++)cout<< ans[i]<<"\n";
	return 0;
}

/*
                                                                
 ■■■■■     ■■      ■■■     ■■■   ■    ■     ■     ■■■■    ■■■■  
 ■   ■■    ■■     ■  ■■   ■  ■■  ■    ■    ■■     ■  ■■  ■■  ■  
 ■    ■    ■■    ■    ■  ■    ■   ■  ■    ■■■    ■■  ■■  ■   ■■ 
 ■    ■    ■■    ■    ■  ■    ■   ■  ■     ■■    ■   ■■      ■■ 
 ■    ■    ■■    ■       ■         ■■      ■■        ■■      ■  
 ■   ■■    ■■    ■  ■■■  ■  ■■■    ■■      ■■       ■■     ■■■  
 ■■■■■     ■■    ■    ■  ■    ■    ■■      ■■      ■■        ■■ 
 ■         ■■    ■    ■  ■    ■    ■■      ■■     ■■          ■ 
 ■         ■■    ■    ■  ■    ■    ■■      ■■     ■      ■   ■■ 
 ■         ■■    ■■  ■■  ■■  ■■    ■■      ■■    ■       ■■  ■■ 
 ■         ■■      ■■■■    ■■■■    ■■      ■■    ■■■■■■   ■■■■  
*/

详细

Subtask #1:

score: 0
Runtime Error

Test #1:

score: 0
Runtime Error

input:

3 3
0 0
1 2
0 2
1 1
1 3
2 3

output:


result:


Subtask #2:

score: 0
Runtime Error

Test #12:

score: 0
Runtime Error

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:


result:


Subtask #3:

score: 0
Wrong Answer

Test #22:

score: 0
Wrong Answer
time: 111ms
memory: 27760kb

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:

19141
39288
14841
58655
15427
4999
26338
93250
2826
78084
64070
55481
2565
15173
24866
57627
35887
51335
67552
44940
27730
24781
54502
26903
73199
7553
3836
41740
67889
104576
43522
3766
13007
31659
17264
85349
16595
28681
64012
56457
23856
47820
22752
86123
37679
44828
88810
36305
15843
33728
10005...

result:

wrong answer 20th numbers differ - expected: '44939', found: '44940'

Subtask #4:

score: 0
Runtime Error

Test #32:

score: 0
Runtime Error

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:


result:


Subtask #5:

score: 0
Skipped

Dependency #1:

0%

Subtask #6:

score: 0
Skipped

Dependency #5:

0%