#include<bits/stdc++.h>
#define int long long
#define down cout<<'\n';
#define NHP ios_base::sync_with_stdio(0);cout.tie(0);cin.tie(0);
#define modwwe int t;cin>>t; while(t--)
#define bit(i,j) (i>>j&1)
#define sobit(a) __builtin_popcountll(a)
#define task "test"
#define fin(x) freopen(x".inp","r",stdin)
#define fou(x) freopen(x".ans","w",stdout)
#define pb push_back
#define checktime cerr << (double)clock() / CLOCKS_PER_SEC * 1000 << " ms";
using namespace std;
void phongbeo();
mt19937 rd(chrono::high_resolution_clock::now().time_since_epoch().count ());
const int mod2=1e9+7;
const int mod1=998244353;
struct ib
{
int a;
int b;
};
struct icd
{
int a,b;
};
struct ic
{
int a,b,c;
};
struct id
{
int a,b,c,d;
};
int n,m,s2,s4,s3,sf,k,r,dem=0,mid,s5,s6,mx,s7,s8,s9,mx2,res,dem2=0,l;
int s,i,s10,s12;
int el=29;
main()
{
#ifndef ONLINE_JUDGE
fin(task),fou(task);
#endif
NHP
//modwwe
phongbeo(),down
//checktime
}
int t[1600001];
int lazy[1600001];
int st[18][200001];
ib a[2000001];
void ff(int x)
{
for(int i=x*2;i<=x*2+1;i++)
{
t[i]+=lazy[x];
lazy[i]+=lazy[x];
}
lazy[x]=0;
}
void upd(int node,int l,int r,int l1,int r1,int z)
{
if(l>r1||r<l1) return;
if(l>=l1&&r<=r1)
{
t[node]+=z;
lazy[node]+=z;
return;
}
int mid=l+r>>1;
ff(node);
upd(node<<1,l,mid,l1,r1,z);
upd(node<<1|1,mid+1,r,l1,r1,z);
t[node]=max(t[node<<1],t[node<<1|1]);
}
vector<int> v;
void phongbeo()
{
cin>>n;
l=0;
for(int i=1;i<=n;i++)
cin>>a[i].a>>a[i].b,v.pb(a[i].a),v.pb(a[i].b);
sort(v.begin(),v.end());
for(int i=1;i<=n;i++)
a[i].a=lower_bound(v.begin(),v.end(),a[i].a)-v.begin()+1,
a[i].b=lower_bound(v.begin(),v.end(),a[i].b)-v.begin()+1;
for(int i=1;i<=n;i++)
{
while(t[1]<2&&l<=n)
{l++;
upd(1,1,n*2,a[l].a,a[l].b,1);
}
st[0][i]=l;
upd(1,1,n*2,a[i].a,a[i].b,-1);
}
for(int j=1;j<18;j++)
for(int i=1;i<=n;i++)
st[j][i]=st[j-1][st[j-1][i]];
cin>>m;
for(int i=1;i<=m;i++)
{
cin>>l>>r;
res=0;
for(int j=17;j>=0;--j)
{
if(st[j][l]<=r&&st[j][l]!=0)
res+=(1ll<<j),l=st[j][l];
}
cout<<res+1,down
}
}
Compilation message
Main.cpp:39:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
39 | main()
| ^~~~
Main.cpp: In function 'void upd(long long int, long long int, long long int, long long int, long long int, long long int)':
Main.cpp:71:16: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
71 | int mid=l+r>>1;
| ~^~
Main.cpp: In function 'void phongbeo()':
Main.cpp:82:6: warning: this 'for' clause does not guard... [-Wmisleading-indentation]
82 | for(int i=1;i<=n;i++)
| ^~~
Main.cpp:84:9: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'for'
84 | sort(v.begin(),v.end());
| ^~~~
Main.cpp: In function 'int main()':
Main.cpp:9:23: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
9 | #define fin(x) freopen(x".inp","r",stdin)
| ~~~~~~~^~~~~~~~~~~~~~~~~~~
Main.cpp:42:1: note: in expansion of macro 'fin'
42 | fin(task),fou(task);
| ^~~
Main.cpp:10:23: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
10 | #define fou(x) freopen(x".ans","w",stdout)
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~
Main.cpp:42:11: note: in expansion of macro 'fou'
42 | fin(task),fou(task);
| ^~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
2 ms |
344 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |