QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#558379#8672. 排队Ayaya0 1ms7648kbC++142.3kb2024-09-11 15:46:132024-09-11 15:46:13

Judging History

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

  • [2024-09-11 15:46:13]
  • 评测
  • 测评结果:0
  • 用时:1ms
  • 内存:7648kb
  • [2024-09-11 15:46:13]
  • 提交

answer

#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<unordered_map>
#include<vector>
#include<bitset>
#include<queue>
#include<set>
#include<map>
#include<ctime>
#include<random>
#include<numeric>
using namespace std;
#define ll long long
#define ull unsigned long long
#define lc (x<<1)
#define rc (x<<1|1)
#define pii pair<int,int>
#define mkp make_pair
#define fi first
#define se second
#define cout (cerr<<">> ",cout)
const int Mx=1000005,p=998244353;
int read(){
	char ch=getchar();
	int Alice=0,Aya=1;
	while(ch<'0'||ch>'9'){
		if(ch=='-') Aya=-Aya;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
		Alice=(Alice<<3)+(Alice<<1)+(ch^48),ch=getchar();
	return (Aya==1?Alice:-Alice);
}
int n,m;
struct Seg{
	int l,r;
}a[Mx],d[Mx];
class SegTree{
	private:
		struct Node{
			int l,r;
			int mn;
			int tag;
		};
		Node t[Mx<<2];
		void PushUp(int x){
			t[x].mn=min(t[lc].mn,t[rc].mn);
		}
		void Apply(int x,int k){
			t[x].tag+=k;
			t[x].mn+=k;
		}
		void PushDown(int x){
			Apply(lc,t[x].tag),Apply(rc,t[x].tag);
			t[x].tag=0;
		}
	public:
		void Build(int x,int l,int r){
			t[x].l=l,t[x].r=r;
			if(l==r){
				t[x].mn=-(l==n+1);
				return;
			}
			int mid=((l+r)>>1);
			Build(lc,l,mid),Build(rc,mid+1,r);
			PushUp(x);
		}
		void Modify(int x,int L,int R){
			int l=t[x].l,r=t[x].r;
			if(l==L&&r==R){
				Apply(x,1);
				return;
			}
			PushDown(x);
			int mid=((l+r)>>1);
			if(R<=mid) Modify(lc,L,R);
			else if(L>mid) Modify(rc,L,R);
			else Modify(lc,L,mid),Modify(rc,mid+1,R);
			PushUp(x);
		}
		int Qry(int x,int k){
			int l=t[x].l,r=t[x].r;
			if(l==r){
				if(t[x].mn>k) exit(114514);
				return l;
			}
			PushDown(x);
			if(t[lc].mn>k) return Qry(rc,k);
			else return Qry(lc,k);
		}
};
SegTree tr;
signed main(){
	n=read(),m=read();
	for(int i=1;i<=n;i++){
		a[i].l=read(),a[i].r=read();
	}
	tr.Build(1,1,n+1);
	for(int i=1;i<=n;i++){
		int L=tr.Qry(1,a[i].r),R=min(i,tr.Qry(1,a[i].l-1)-1);
		d[i]={L,R};
		tr.Modify(1,L,R);
	}
	for(int Id=1,l,r;Id<=m;Id++){
		l=read(),r=read();
		int res=0;
		for(int i=l;i<=r;i++){
			if(l>=d[i].l&&l<=d[i].r) res++;
		}
		cout<<res<<endl;
	}
	return 0;
}
/*
Hello!!
Sample:

-------------------
*/


Details

Tip: Click on the bar to expand more detailed information

Subtask #1:

score: 0
Runtime Error

Test #1:

score: 10
Accepted
time: 1ms
memory: 7648kb

input:

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

output:

1
3
1

result:

ok 3 number(s): "1 3 1"

Test #2:

score: 0
Runtime Error

input:

5000 5000
5 10
3 9
3 8
2 7
2 5
3 6
1 5
0 2
7 8
2 10
0 3
3 6
4 6
1 6
4 8
7 8
2 7
3 4
4 9
7 8
2 9
2 5
3 6
0 5
6 7
1 2
2 4
2 10
1 5
7 9
6 9
2 3
9 10
5 5
2 9
3 3
2 7
2 4
0 6
0 3
1 7
7 7
4 8
2 9
4 8
0 10
1 8
1 1
2 7
5 9
1 7
1 7
1 4
2 4
1 4
2 9
1 7
4 7
3 8
1 3
4 6
1 5
1 6
0 0
3 9
4 7
2 8
1 8
1 2
7 8
2 7
2...

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
Time Limit Exceeded

Test #22:

score: 0
Time Limit Exceeded

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
44939
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:


Subtask #4:

score: 0
Time Limit Exceeded

Test #32:

score: 0
Time Limit Exceeded

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:

71224
21392
65746
47218
62293
29293
146310
136621
165312
81582
25124
120262
104926
12518
90915
31784
50073
15588
1517
106447
92329
71506
16694
4846
38213
34902
133281
98867
697
26263
6631
173459
61316
71682
15564
112191
125788
15305
41840
30379
24107
17435
10898
115177
22279
37582
101778
120170
1264...

result:


Subtask #5:

score: 0
Skipped

Dependency #1:

0%

Subtask #6:

score: 0
Skipped

Dependency #5:

0%