# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
518318 | LptN21 | Matryoshka (JOI16_matryoshka) | C++14 | 283 ms | 11168 KiB |
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>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false), cin.tie(NULL);
#define PI acos(-1.0)
#define eps 1e-9
#define FF first
#define SS second
// VECTOR (6)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define sz(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define uniq(v) sort(all( (v) )), (v).resize( unique(all( (v) )) - (v).begin() );
// BIT (6)
#define CNTBIT(x) __builtin_popcountll(x)
#define ODDBIT(x) __builtin_parityll(x)
#define MASK(i) (1LL<<(i))
#define BIT(x, i) (((x)>>(i))&1)
#define SUBSET(big, small) (((big)&(small))==(small))
#define MINBIT(x) (x)&(-x)
//typedef
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, int> ii;
/* CODE BELOW */
const int N = 200000 + 7, M = 1e9 + 7;
const int oo = 1e9 + 7;
const int MOD = 1e9 + 7;
int n, m, k, t;
ii a[N], q[N];
int ans[N], idx[N];
int c[N], mx = 0;
int fen[N];
void update(int p, int v) {
for(;p<=n;p+=p&-p) {
fen[p] = max(fen[p], v);
}
}
int query(int p) {
int ans = 0;
for(;p>0;p-=p&-p) {
ans = max(ans, fen[p]);
}
return ans;
}
bool cmp(int x, int y) {
if(q[x].FF != q[y].FF) {
return q[x].FF < q[y].FF;
}
return q[x].SS < q[y].SS;
}
signed main() {
//freopen("test.inp", "r", stdin);
//freopen("test.out", "w", stdout);
//fastIO;
scanf("%d%d", &n, &m);
vector<int> rrh;
for(int i=1;i<=n;i++) {
scanf("%d%d", &a[i].FF, &a[i].SS);
rrh.pb(a[i].SS); a[i].SS*= -1;
}
sort(a+1, a+n+1); uniq(rrh);
for(int i=1;i<=m;i++) {
scanf("%d%d", &q[i].FF, &q[i].SS);
idx[i] = i;
}
sort(idx+1, idx+m+1, cmp);
for(int j=m, i=n;i>=0;i--) {
while(j>0&&q[idx[j]].FF>a[i].FF) {
int tmp = ub(all(rrh), q[idx[j]].SS) - rrh.begin();
ans[idx[j]] = query(tmp); j--;
}
if(i == 0) break;
a[i].SS = lb(all(rrh), -a[i].SS) - rrh.begin() + 1;
int k = ub(c+1, c+mx+1, a[i].SS) - c;
c[k] = a[i].SS; mx = max(mx, k);
update(a[i].SS, k);
}
for(int i=1;i<=m;i++) {
printf("%d\n", ans[i]);
}
return 0;
}
Compilation message (stderr)
# | 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... |