#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);
}
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] = max(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
matryoshka.cpp: In function 'int main()':
matryoshka.cpp:66:17: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
66 | scanf("%d%d", &a[i].FF, &a[i].SS);
| ~^
| |
| int*
| %lld
matryoshka.cpp:71:17: warning: format '%d' expects argument of type 'int*', but argument 2 has type 'long long int*' [-Wformat=]
71 | scanf("%d%d", &q[i].FF, &q[i].SS);
| ~^
| |
| int*
| %lld
matryoshka.cpp:63:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
63 | scanf("%d%d", &n, &m);
| ~~~~~^~~~~~~~~~~~~~~~
matryoshka.cpp:66:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
66 | scanf("%d%d", &a[i].FF, &a[i].SS);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
matryoshka.cpp:71:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
71 | scanf("%d%d", &q[i].FF, &q[i].SS);
| ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
444 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
3 |
Incorrect |
0 ms |
336 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
444 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
3 |
Incorrect |
0 ms |
336 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
444 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
3 |
Incorrect |
0 ms |
336 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
444 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
3 |
Incorrect |
0 ms |
336 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |