#include<bits/stdc++.h>
using namespace std;
const int MAXN=1e5+6;
const int INF=2e9;
const int sq=300;
struct SegmentTree
{
int node[MAXN];
int lazy[MAXN];
bool lz[MAXN];
void init()
{
memset(lz,0,sizeof(lz));
memset(lazy,0,sizeof(lazy));
memset(node,0,sizeof(node));
}
int merge(int n1,int n2)
{
return max(n1,n2);
}
void push(int idx,int l,int r)
{
if(lz[idx]==0)return;
node[idx]+=lazy[idx];
if(l!=r)
{
lz[idx*2]=1;
lz[idx*2+1]=1;
lazy[idx*2]+=lazy[idx];
lazy[idx*2+1]+=lazy[idx];
}
lazy[idx]=0;
lz[idx]=0;
}
void update(int idx,int l,int r,int ql,int qr,int val)
{
push(idx,l,r);
if(l>qr||r<ql||l>r)return;
if(l>=ql&&r<=qr)
{
lz[idx]=1;
lazy[idx]+=val;
push(idx,l,r);
return;
}
int mid=(l+r)/2;
update(idx*2,l,mid,ql,qr,val);
update(idx*2+1,mid+1,r,ql,qr,val);
node[idx]=merge(node[idx*2],node[idx*2+1]);
}
int query(int idx,int l,int r,int ql,int qr)
{
push(idx,l,r);
if(l>qr||r<ql||l>r)return -INF;
if(l>=ql&&r<=qr)return node[idx];
int mid=(l+r)/2;
return merge(query(idx*2,l,mid,ql,qr),query(idx*2+1,mid+1,r,ql,qr));
}
}tree;
int n,m;
int t[MAXN],d[MAXN];
int maxright[MAXN];
int where[MAXN];
void add(int idx)
{
tree.update(1,1,n,where[idx],where[idx],INF-d[idx]);
tree.update(1,1,n,where[idx],n,t[idx]);
}
void remove(int idx)
{
tree.update(1,1,n,where[idx],where[idx],-INF+d[idx]);
tree.update(1,1,n,where[idx],n,-t[idx]);
}
int main()
{
cin>>n>>m;
vector<pair<int,int> >v;
for(int i=1;i<=n;i++)
{
cin>>t[i]>>d[i];
v.push_back({d[i],i});
}
sort(v.begin(),v.end());
for(int i=0;i<v.size();i++)
{
where[v[i].second]=i;
}
int r=0;
tree.init();
//cout<<tree.query(1,1,n,1,n)<<endl;
tree.update(1,1,n,1,n,-INF);
//cout<<tree.query(1,1,n,1,n)<<endl;
for(int l=1;l<=n;l++)
{
while(r<=n&&tree.query(1,1,n,1,n)<0)
{
r++;
if(r<=n)add(r);
}
remove(l);
maxright[l]=r-1;
}
//for(int i=1;i<=n;i++)cout<<maxright[i]<<" ";
//cout<<endl;
for(int i=0;i<m;i++)
{
int ez,dp;
cin>>ez>>dp;
if(maxright[ez]>=dp)
{
cout<<"1\n";
}
else cout<<"0\n";
}
return 0;
}
Compilation message
cambridge.cpp: In function 'int main()':
cambridge.cpp:84:15: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
84 | for(int i=0;i<v.size();i++)
| ~^~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1260 KB |
Output is correct |
2 |
Correct |
1 ms |
1260 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1260 KB |
Output is correct |
2 |
Correct |
1 ms |
1260 KB |
Output is correct |
3 |
Runtime error |
96 ms |
8264 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1260 KB |
Output is correct |
2 |
Correct |
1 ms |
1260 KB |
Output is correct |
3 |
Correct |
168 ms |
1792 KB |
Output is correct |
4 |
Correct |
273 ms |
2284 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
1260 KB |
Output is correct |
2 |
Correct |
1 ms |
1260 KB |
Output is correct |
3 |
Runtime error |
96 ms |
8264 KB |
Execution killed with signal 11 |
4 |
Halted |
0 ms |
0 KB |
- |