This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#pragma GCC optimize("Ofast,unroll-loops")
#pragma GCC optimize("conserve-stack")
#include<bits/stdc++.h>
//#define int long long
#define ll long long
#define down cout<<'\n';
#define debug cout<<" cucuucucuuu",down
#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".out","w",stdout)
#define pb push_back
#define checktime cerr << (double)clock() / CLOCKS_PER_SEC * 1000 << " ms";
using namespace std;
#define getchar_unlocked getchar
inline int scan()
{
char c = getchar_unlocked();
int x = 0;
while (c < '0' || c > '9')
{
c = getchar_unlocked();
}
while (c >= '0' && c <= '9')
{
x = (x << 1) + (x << 3) + c - '0';
c = getchar_unlocked();
}
return x;
}
void phongbeo();
const int inf = 1e18;
const int mod2 = 1e9 + 7;
const int mod1 = 998244353;
struct icd
{
long double a;
int b;
};
struct ib
{
int a;
int b;
};
struct ic
{
int a, b, c;
};
struct id
{
int a, b, c, d;
};
struct ie
{
int a, b, c, d, e;
};
int n, m, s1, s2, s4, s3, sf, k, s5, s6, mx, s7, s8, s9, mx2, res, dem2 = 0, dem = 0, s33, dem3, dem4, l, r, mid, l2, r2, center;
int i, s10, s12,k1,k2,k3,s11,t,lim,w;
int kk;
int el = 19;
main()
{
if(fopen(task".inp","r"))
{
fin(task);
fou(task);
}
NHP
/// cin>>s1;
///modwwe
phongbeo();
// checktime
}
ib a[200001];
ic b[200001];
int ans[200001];
vector<int> v;
bool cmp(ib a,ib b)
{
if(a.b==b.b) return a.a>b.a;
return a.b<b.b;
}
bool cmp2(ic a,ic b)
{
return a.b<b.b;
}
struct seg
{
ib t[800001];
void upd(int node,int l,int r,int l1,int x)
{
if(l==r)
{
t[node].a+=x;
if(t[node].a!=0) t[node].b=l;
else t[node].b=0;
return;
}
int mid=l+r>>1;
if(l1<=mid)
upd(node<<1,l,mid,l1,x);
else upd(node<<1|1,mid+1,r,l1,x);
t[node].b=max(t[node<<1].b,t[node<<1|1].b);
t[node].a=t[node<<1].a+t[node<<1|1].a;
}
int get(int node,int l,int r,int l1,int r1)
{
if(l>r1||r<l1) return 0;
if(l>=l1&&r<=r1) return t[node].b;
int mid=l+r>>1;
return max(get(node<<1,l,mid,l1,r1),get(node<<1|1,mid+1,r,l1,r1));
}
int get2(int node,int l,int r,int l1,int r1 )
{
if(l1>r1) return 0;
if(l>r1||r<l1) return 0;
if(l>=l1&&r<=r1) return t[node].a;
int mid=l+r>>1;
return get2(node<<1,l,mid,l1,r1)+get2(node<<1|1,mid+1,r,l1,r1);
}
} st;
void upd(int x)
{
s3=st.get(1,1,n,1,a[x].a-1);
if(s3!=0)
st.upd(1,1,n,s3,-1);
st.upd(1,1,n,a[x].a,1) ;
}
void phongbeo()
{
cin>>n>>m;
for(int i=1; i<=n; i++)
cin>>a[i].a>>a[i].b,v.pb(a[i].a);
sort(a+1,a+1+n,cmp);
sort(v.begin(),v.end());
v.erase(unique(v.begin(),v.end()),v.end());
for(int i=1; i<=n; i++)
a[i].a=lower_bound(v.begin(),v.end(),a[i].a)-v.begin()+1;
for(int i=1; i<=m; i++)
cin>>b[i].a>>b[i].b,b[i].c=i;
sort(b+1,b+1+m,cmp2);
l=1;
n=v.size();
for(int i=1; i<=m; i++)
{
while(l<=n&&a[l].b<=b[i].b)
{
upd(l);
l++;
}
s2=lower_bound(v.begin(),v.end(),b[i].a)-v.begin()+1;
ans[b[i].c]=st.get2(1,1,n,s2,n);
}
for(int i=1; i<=m; i++)
cout<<ans[i],down
}
Compilation message (stderr)
matryoshka.cpp:37:17: warning: overflow in conversion from 'double' to 'int' changes value from '1.0e+18' to '2147483647' [-Woverflow]
37 | const int inf = 1e18;
| ^~~~
matryoshka.cpp:69:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
69 | main()
| ^~~~
matryoshka.cpp: In member function 'void seg::upd(int, int, int, int, int)':
matryoshka.cpp:107:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
107 | int mid=l+r>>1;
| ~^~
matryoshka.cpp: In member function 'int seg::get(int, int, int, int, int)':
matryoshka.cpp:118:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
118 | int mid=l+r>>1;
| ~^~
matryoshka.cpp: In member function 'int seg::get2(int, int, int, int, int)':
matryoshka.cpp:126:18: warning: suggest parentheses around '+' inside '>>' [-Wparentheses]
126 | int mid=l+r>>1;
| ~^~
matryoshka.cpp: In function 'int main()':
matryoshka.cpp:13:23: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
13 | #define fin(x) freopen(x".inp","r",stdin)
| ~~~~~~~^~~~~~~~~~~~~~~~~~~
matryoshka.cpp:73:9: note: in expansion of macro 'fin'
73 | fin(task);
| ^~~
matryoshka.cpp:14:23: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
14 | #define fou(x) freopen(x".out","w",stdout)
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~
matryoshka.cpp:74:9: note: in expansion of macro 'fou'
74 | fou(task);
| ^~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |