QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#819009#8704. 排队xyin0 59ms78884kbC++142.1kb2024-12-18 11:38:092024-12-18 11:38:09

Judging History

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

  • [2024-12-18 11:38:09]
  • 评测
  • 测评结果:0
  • 用时:59ms
  • 内存:78884kb
  • [2024-12-18 11:38:09]
  • 提交

answer

#include<bits/stdc++.h>
#define int long long
#define ll long long
#define pai pair<int,int>
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define pp pop_back
#define ls rt<<1
#define rs rt<<1|1
using namespace std;
const int maxn=1e6+5;
const int INF=1e18;
int read(int x=0,bool f=1,char c=0){
	while (!isdigit(c=getchar())) f=c^45;
	while (isdigit(c))
		x=(x<<1)+(x<<3)+(c^48),c=getchar();
	return f?x:-x;
}
int ans[maxn],to[maxn];
int cnt,n,Q,a[maxn],b[maxn];
struct Node{
	int o,id;
};
struct Segtree{
	int v,tag;
}tr[maxn<<2];
vector<Node>q[maxn<<1];
void down(int rt){
	if (!tr[rt].tag) return ;
	int t=tr[rt].tag;tr[rt].tag=0;
	tr[ls].v+=t;tr[ls].tag+=t;
	tr[rs].v+=t;tr[rs].tag+=t;
}
void update(int rt,int l,int r,int x,int y,int k){
	if (l>=x&&r<=y)
		return tr[rt].v+=k,tr[rt].tag+=k,void();
	if (x>y) return ;down(rt);int mid=(l+r)>>1;
	if (x<=mid) update(ls,l,mid,x,y,k);
	if (mid<y) update(rs,mid+1,r,x,y,k);
	tr[rt].v=max(tr[ls].v,tr[rs].v);
}
int get(int rt,int l,int r,int k){
	if (l==r) return l;
	down(rt);int mid=(l+r)>>1;
	if (tr[rs].v>=k) return get(rs,mid+1,r,k);
	else return get(ls,l,mid,k);
}
int query(int rt,int l,int r,int pos){
	if (l==r) return tr[rt].v;
	down(rt);int mid=(l+r)>>1;
	if (pos<=mid) return query(ls,l,mid,pos);
	else return query(rs,mid+1,r,pos);
}
signed main(){
	n=read();Q=read();
	for (int i=1;i<=n;i++)
		a[i]=read(),b[i]=read();
	for (int i=1,x,y;i<=Q;i++){
		x=read();y=read();
		q[x].pb(Node{1,i});
		q[y+1].pb(Node{0,i});
	}
	update(1,0,Q,0,0,INF);
	for (int i=1;i<=n+1;i++){
		for (auto it:q[i]){
//			if (it.o)
//			cout<<it.id<<"***\n";
			if (it.o) to[it.id]=++cnt;
			else ans[it.id]=query(1,0,Q,to[it.id]);
//			cout<<i<<"  "<<head<<"***"<<tail<<endl;
		}
		if (i<=n){
			int l=get(1,0,Q,b[i]+1)+1,r=get(1,0,Q,a[i]);
//			cout<<i<<"***"<<l<<"  "<<r<<endl;
			update(1,0,Q,l,min(r,cnt),1);
		}
	}
	for (int i=1;i<=Q;i++) printf("%lld\n",ans[i]);
}
/*
8  5
1  3
0  4
2  2
1  1
2  4
2  5
0  3

5  5
5  5
4  6
4  6
3  6
1  6
*/

詳細信息

Subtask #1:

score: 0
Wrong Answer

Test #1:

score: 0
Wrong Answer
time: 4ms
memory: 56744kb

input:

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

output:

0
0
0
0
0
0
0
0

result:

wrong answer 1st lines differ - expected: '2', found: '0'

Subtask #2:

score: 0
Time Limit Exceeded

Test #5:

score: 0
Time Limit Exceeded

input:

1 298913
1 0
3 1
3 1
3 1
3 1
3 1
1 0
1 0
3 3
1 2
1 2
3 5
3 5
1 1
1 3
1 4
3 3
1 3
1 6
3 7
3 2
3 5
3 8
3 2
1 8
3 3
1 4
3 2
3 7
1 3
3 4
1 10
3 14
3 13
1 12
3 4
1 8
1 15
1 16
3 9
3 14
3 10
3 8
3 7
1 16
1 15
3 16
3 13
1 19
3 13
3 1
3 14
1 18
1 22
3 8
1 17
3 18
3 9
1 18
3 9
3 1
1 20
3 11
3 5
3 2
3 22
1 22...

output:


result:


Subtask #3:

score: 0
Wrong Answer

Test #20:

score: 0
Wrong Answer
time: 44ms
memory: 76140kb

input:

2 298235
1 0
1 1
3 2
1 0
1 3
3 4
3 3
3 3
3 2
3 4
3 2
3 3
1 2
3 3
1 4
1 2
1 1
3 5
3 8
1 5
1 9
3 10
3 8
3 10
3 5
3 8
3 5
1 2
1 9
3 5
3 7
3 12
3 3
1 6
3 4
3 3
3 11
3 8
3 9
3 7
3 6
3 4
1 12
1 11
3 13
3 13
1 11
3 16
3 6
3 14
3 9
3 5
3 13
1 9
1 17
3 16
3 13
3 5
3 15
3 8
3 4
3 13
1 18
3 15
3 16
3 19
3 4
1 ...

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
1000000000000000000
0
0
0
0
1000000000000000000
0
0
0
0
0
0
1000000000000000000
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 lines differ - expected: '2', found: '0'

Subtask #4:

score: 0
Wrong Answer

Test #35:

score: 0
Wrong Answer
time: 59ms
memory: 78884kb

input:

3 299743
1 0
1 1
3 1
1 2
3 2
1 0
3 3
3 2
3 1
3 2
2 2 1
3 3
3 3
3 4
3 1
3 2
3 2
2 1 0
3 2
3 1
3 1
1 0
3 2
1 2
1 1
3 2
2 5 2
1 6
1 0
2 5 2
1 7
3 8
3 5
3 5
2 7 5
2 9 4
3 5
3 8
2 6 2
2 3 0
2 2 0
1 1
2 3 1
1 8
2 7 0
3 3
1 12
2 13 9
1 5
2 2 1
2 14 13
1 12
2 1 0
2 12 10
2 15 12
1 0
1 6
3 6
2 3 2
2 17 6
3 4...

output:

0
0
0
0
0
1000000000000000000
0
0
0
0
0
0
0
0
0
0
0
1000000000000000000
1000000000000000000
0
0
0
0
0
0
0
1000000000000000000
1000000000000000000
1000000000000000000
0
0
0
0
0
1000000000000000000
0
0
0
0
0
1000000000000000000
0
1000000000000000000
0
1000000000000000000
0
0
1000000000000000000
100000...

result:

wrong answer 1st lines differ - expected: '1', found: '0'

Subtask #5:

score: 0
Skipped

Dependency #1:

0%