This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
const LL llinf=9000000000000000000;
const int inf=2000000000;
struct SEGMENT_TREE
{
LL initial=-llinf;
int x;
struct NODE{
int st, fin;
LL q;
}tree[1600100];
LL f(LL a, LL b){return max(a, b);}
void init(int point, int num){
if(num==1)tree[point].st=tree[point].fin=++x;
if(num<=1)return;
init(point*2, num-num/2);
init(point*2+1, num/2);
tree[point].st=tree[point*2].st;
tree[point].fin=tree[point*2+1].fin;
}
void update(int point, int num, LL qu){
if(tree[point].st==tree[point].fin){
tree[point].q=qu;
return;
}
if(num<=tree[point*2].fin)update(point*2, num, qu);
else update(point*2+1, num, qu);
tree[point].q=f(tree[point*2].q, tree[point*2+1].q);
}
LL query(int point, int a, int b){
if(tree[point].st>=a&&tree[point].fin<=b)return tree[point].q;
if(tree[point].st>b||tree[point].fin<a)return initial;
return f(query(point*2, a, b), query(point*2+1, a, b));
}
void init(int num){init(1, num);}
void update(int num, LL qu){update(1, num, qu);}
LL query(int a, int b){return query(1, a, b);}
}seg;
int n, q;
pll point[200010], query[200010];
LL ans[200010];
vector<LL> idx;
vector<pair<pair<LL, int>, pair<LL, int>> > qu;
int main()
{
scanf("%d %d", &n, &q);
for(int i=1; i<=n; i++){
scanf("%lld %lld", &point[i].F, &point[i].S);
idx.pb(point[i].F);
qu.pb(mp(mp(point[i].S, 1), mp(-point[i].F, 0)));
}
seg.init(n+q+10);
for(int i=1; i<=q; i++){
scanf("%lld %lld", &query[i].F, &query[i].S);
idx.pb(query[i].F);
qu.pb(mp(mp(query[i].S, 2), mp(query[i].F, i)));
}
sort(all(idx));
sort(all(qu));
for(auto Q:qu){
if(Q.F.S==1){
int temp=lower_bound(all(idx), -Q.S.F)-idx.begin()+1;
seg.update(temp, seg.query(temp, n+q+10)+1);
}
else{
int temp=lower_bound(all(idx), Q.S.F)-idx.begin()+1;
ans[Q.S.S]=seg.query(temp, n+q+10);
}
}
for(int i=1; i<=q; i++)printf("%lld\n", ans[i]);
}
Compilation message (stderr)
matryoshka.cpp: In function 'int main()':
matryoshka.cpp:55:10: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%d %d", &n, &q);
~~~~~^~~~~~~~~~~~~~~~~
matryoshka.cpp:57:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld", &point[i].F, &point[i].S);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
matryoshka.cpp:63:14: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
scanf("%lld %lld", &query[i].F, &query[i].S);
~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# | 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... |