| 比赛 |
2026.8.26 |
评测结果 |
TTWWWWWWTTTTTTTTTTTT |
| 题目名称 |
interval |
最终得分 |
0 |
| 用户昵称 |
__0w0__ |
运行时间 |
31.600 s |
| 代码语言 |
C++ |
内存使用 |
5.44 MiB |
| 提交时间 |
2026-08-26 12:02:06 |
显示代码纯文本
#include<bits/stdc++.h>
using namespace std;
int n,Q,c;
int a[250001],b[250001];
priority_queue<int,vector<int>,greater<int> >q,p;
int main(){
freopen("intervallavretni.in","r",stdin);
freopen("intervallavretni.out","w",stdout);
cin>>n>>Q;
c=1;
for(int i=1;i<=n;i++){
cin>>a[i]>>b[i];
c&=(a[i]==1);
}
for(int i=1;i<=Q;i++){
int l,r,f=0;
cin>>l>>r;
if(c){
cout<<"0 ";
continue;
}
for(int j=l;j<=r;j++){
q.push(a[j]);
p.push(b[j]);
}
int bb=p.top(),jb=1;
int aa=q.top(),ja=1;
while(!q.empty()){
aa=q.top();
bb=q.top();
ja=jb=1;
p.pop();
q.pop();
if(q.empty()&&p.empty()&&aa!=bb){
cout<<0<<' ';
f=1;
break;
}
while(q.top()==aa){
ja++;
q.pop();
}
while(p.top()==bb){
jb++;
p.pop();
}
if(ja>jb){
int c=ja-jb;
while(c--){
q.push(aa+1);
}
}else continue;
}
if(f)continue;
else cout<<"1 ";
}
fclose(stdin);
fclose(stdout);
return 0;
}