#include "bits/stdc++.h"
#define MAXN 100009
#define INF 1000000007
#define mp(x,y) make_pair(x,y)
#define all(v) v.begin(),v.end()
#define pb(x) push_back(x)
#define wr cout<<"----------------"<<endl;
#define ppb() pop_back()
#define tr(ii,c) for(__typeof((c).begin()) ii=(c).begin();ii!=(c).end();ii++)
#define ff first
#define ss second
#define my_little_dodge 46
#define debug(x) cerr<< #x <<" = "<< x<<endl;
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
template<class T>bool umin(T& a,T b){if(a>b){a=b;return 1;}return 0;}
template<class T>bool umax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
PII arr[MAXN];
map<int,int>pm;
int ans[MAXN],c,vis[MAXN];
ll s[MAXN<<2],lazy[MAXN<<2];
const ll B=1e16;
void shift(int nd){
ll &ret=lazy[nd];
if(!ret)
return;
lazy[nd<<1]+=ret;s[nd<<1]+=ret;
lazy[nd<<1|1]+=ret;s[nd<<1|1]+=ret;
ret=0;
}
void inc(int l,int r,ll v,int nd,int x,int y){
//~ if(nd==1)
//~ cout<<"inc "<<l<<" "<<r<<" "<<v<<endl;
if(l>y or x>r)
return;
if(l<=x and y<=r){
s[nd]+=v;
lazy[nd]+=v;
return;
}
shift(nd);
int mid=(x+y)>>1;
inc(l,r,v,nd<<1,x,mid);
inc(l,r,v,nd<<1|1,mid+1,y);
s[nd]=min(s[nd<<1],s[nd<<1|1]);
}
void upd(int p,ll v,int nd,int x,int y){
if(x==y){
s[nd]=lazy[nd]+v;
return;
}
shift(nd);
int mid=(x+y)>>1;
if(p<=mid)
upd(p,v,nd<<1,x,mid);
else
upd(p,v,nd<<1|1,mid+1,y);
s[nd]=min(s[nd<<1],s[nd<<1|1]);
}
void add(int x,int y){
//~ cout<<"add "<<x<<" "<<y<<endl;
if(!vis[pm[y]])
upd(pm[y],y,1,1,c);
vis[pm[y]]++;
inc(pm[y],c,-x,1,1,c);
}
void rem(int x,int y){
//~ cout<<"rem "<<x<<" "<<y<<endl;
vis[pm[y]]--;
inc(pm[y],c,x,1,1,c);
if(!vis[pm[y]])
upd(pm[y],B,1,1,c);
}
void build(int nd,int x,int y){
s[nd]=B;
if(x==y)
return;
int mid=(x+y)>>1;
build(nd<<1,x,mid);
build(nd<<1|1,mid+1,y);
}
void dfs(int nd,int x,int y){
if(x==y){
if(s[nd]>=INF)
cout<<"inf ";
else
cout<<s[nd]<<" ";
return;
}
int mid=(x+y)>>1;
dfs(nd<<1,x,mid);
dfs(nd<<1|1,mid+1,y);
}
int main(){
//~ freopen("file.in", "r", stdin);
int n,q;
scanf("%d%d",&n,&q);
for(int i=1;i<=n;i++){
int u,v;
scanf("%d%d",&u,&v);
arr[i]=mp(u,v);pm[v]=1;
}
tr(it,pm)
it->ss=++c;
build(1,1,c);
int p=1;
for(int i=1;i<=n;i++){
add(arr[i].ff,arr[i].ss);
while(p<=i and s[1]<=0)
rem(arr[p].ff,arr[p].ss),p++;
//~ debug(s[1]);
ans[i]=p;
//~ cout<<p<<" "<<i<<endl;
//~ wr
//~ dfs(1,1,c);puts("");
//~ wr
}
while(q--){
int l,r;
scanf("%d%d",&l,&r);
if(ans[r]<=l)
puts("1");
else
puts("0");
}
return 0;
}
Compilation message
cambridge.cpp: In function 'int main()':
cambridge.cpp:99:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&n,&q);
~~~~~^~~~~~~~~~~~~~
cambridge.cpp:102:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&u,&v);
~~~~~^~~~~~~~~~~~~~
cambridge.cpp:122:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d%d",&l,&r);
~~~~~^~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
378 ms |
10780 KB |
Output is correct |
4 |
Correct |
4 ms |
10780 KB |
Output is correct |
5 |
Correct |
58 ms |
10780 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
15 ms |
10780 KB |
Output is correct |
4 |
Correct |
28 ms |
10780 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
2 ms |
376 KB |
Output is correct |
2 |
Correct |
2 ms |
376 KB |
Output is correct |
3 |
Correct |
378 ms |
10780 KB |
Output is correct |
4 |
Correct |
4 ms |
10780 KB |
Output is correct |
5 |
Correct |
58 ms |
10780 KB |
Output is correct |
6 |
Correct |
15 ms |
10780 KB |
Output is correct |
7 |
Correct |
28 ms |
10780 KB |
Output is correct |
8 |
Correct |
449 ms |
11168 KB |
Output is correct |
9 |
Correct |
427 ms |
11168 KB |
Output is correct |
10 |
Correct |
432 ms |
11380 KB |
Output is correct |
11 |
Correct |
59 ms |
11380 KB |
Output is correct |
12 |
Correct |
73 ms |
11380 KB |
Output is correct |
13 |
Correct |
5 ms |
11380 KB |
Output is correct |