#include <bits/stdc++.h>
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
#include <ext/pb_ds/assoc_container.hpp> //required
#include <ext/pb_ds/tree_policy.hpp> //required
using namespace __gnu_pbds; //required
using namespace std;
template <typename T> using indexed_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long
#define vi vector<int>
#define vl vector<long long>
#define vii vector<pair<int,int>>
#define vll vector<pair<long long,long long>>
#define pb push_back
#define ll long long
#define ld long double
#define nl '\n'
#define boost ios::sync_with_stdio(false)
#define mp make_pair
#define se second
#define fi first
#define fore(i, y) for(int i = 0; i < y; i++)
#define forr(i,x,y) for(int i = x;i<=y;i++)
#define forn(i,y,x) for(int i = y; i >= x; i--)
#define all(v) v.begin(),v.end()
#define sz(v) v.size()
#define clr(v,k) memset(v,k,sizeof(v))
#define rall(v) v.rbegin() , v.rend()
#define pii pair<int,int>
#define pll pair<ll , ll>
const ll MOD = 1e9 + 7;
const ll INF = 1e18 + 1;
ll gcd(ll a , ll b) {return b ? gcd(b , a % b) : a ;} // greatest common divisor (gcd)
ll lcm(ll a , ll b) {return a * (b / gcd(a , b));} // least common multiple (lcm)
// HERE IS THE SOLUTION
vl st;
void build(vi &a , int &n)
{
while(__builtin_popcount(n) != 1)
{
n++;
a.pb(-INF);
}
st.resize(2*n);
fore(i , n)
{
st[i + n] = a[i];
}
forn(i ,n - 1, 1)
{
st[i] = max(st[2*i] , st[2*i + 1]);
}
}
void update(int i , int v , int n)
{
st[i + n] = v;
for(int j = (n + i)/2;j>= 1;j/=2)
{
st[j] = max(st[2*j] , st[2*j + 1]);
}
}
int query(int node , int nodeL , int nodeR , int queryL , int queryR)
{
if(nodeL >= queryL && nodeR<= queryR)
{
return st[node];
}
if(nodeL > queryR || nodeR < queryL)
{
return -INF;
}
int mid = (nodeL + nodeR)/2;
return max(query(2*node , nodeL , mid , queryL , queryR) , query(2*node + 1 , mid + 1 , nodeR , queryL , queryR));
}
signed main()
{
cin.tie(0);
cout.tie(0);
boost;
int n , m;
cin>>n>>m;
vi s(n) , v(n);
vii A(n);
fore(i , n)
{
cin>>s[i]>>v[i];
A[i] = {s[i] , v[i]};
}
sort(all(A));
map<int ,set<int>> ls;
fore(i , n)
{
v[i] = A[i].se;
ls[v[i]].insert(i);
s[i] = A[i].fi;
}
build(v , n);
vi frame(m);
fore(i , m)
{
cin>>frame[i];
}
sort(rall(frame));
int ans = 0;
forr(i , 0 , m - 1)
{
int idx = upper_bound(all(s) , frame[i]) - s.begin();
idx--;
if(idx < 0)
{
break;
}
int mx = query(1 , 0 , n -1 , 0 , idx);
if(mx == -INF)
{
break;
}
auto lst = ls[mx].upper_bound(idx);
lst--;
update(*lst , -INF , n);
ls[mx].erase(lst);
ans++;
}
cout<<ans<<nl;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
324 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
324 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
324 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
324 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
324 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
324 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
2 ms |
460 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
1 ms |
460 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
460 KB |
Output is correct |
27 |
Correct |
1 ms |
468 KB |
Output is correct |
28 |
Correct |
1 ms |
460 KB |
Output is correct |
29 |
Correct |
2 ms |
456 KB |
Output is correct |
30 |
Correct |
1 ms |
464 KB |
Output is correct |
31 |
Correct |
1 ms |
380 KB |
Output is correct |
32 |
Correct |
1 ms |
492 KB |
Output is correct |
33 |
Correct |
1 ms |
328 KB |
Output is correct |
34 |
Correct |
1 ms |
468 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
468 KB |
Output is correct |
37 |
Correct |
1 ms |
468 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
0 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
324 KB |
Output is correct |
4 |
Correct |
0 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
212 KB |
Output is correct |
7 |
Correct |
0 ms |
212 KB |
Output is correct |
8 |
Correct |
0 ms |
212 KB |
Output is correct |
9 |
Correct |
1 ms |
212 KB |
Output is correct |
10 |
Correct |
0 ms |
212 KB |
Output is correct |
11 |
Correct |
1 ms |
212 KB |
Output is correct |
12 |
Correct |
1 ms |
324 KB |
Output is correct |
13 |
Correct |
1 ms |
212 KB |
Output is correct |
14 |
Correct |
0 ms |
324 KB |
Output is correct |
15 |
Correct |
0 ms |
212 KB |
Output is correct |
16 |
Correct |
1 ms |
212 KB |
Output is correct |
17 |
Correct |
0 ms |
212 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
0 ms |
212 KB |
Output is correct |
20 |
Correct |
2 ms |
460 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
468 KB |
Output is correct |
23 |
Correct |
1 ms |
468 KB |
Output is correct |
24 |
Correct |
1 ms |
460 KB |
Output is correct |
25 |
Correct |
1 ms |
468 KB |
Output is correct |
26 |
Correct |
1 ms |
460 KB |
Output is correct |
27 |
Correct |
1 ms |
468 KB |
Output is correct |
28 |
Correct |
1 ms |
460 KB |
Output is correct |
29 |
Correct |
2 ms |
456 KB |
Output is correct |
30 |
Correct |
1 ms |
464 KB |
Output is correct |
31 |
Correct |
1 ms |
380 KB |
Output is correct |
32 |
Correct |
1 ms |
492 KB |
Output is correct |
33 |
Correct |
1 ms |
328 KB |
Output is correct |
34 |
Correct |
1 ms |
468 KB |
Output is correct |
35 |
Correct |
1 ms |
340 KB |
Output is correct |
36 |
Correct |
1 ms |
468 KB |
Output is correct |
37 |
Correct |
1 ms |
468 KB |
Output is correct |
38 |
Correct |
109 ms |
21060 KB |
Output is correct |
39 |
Correct |
67 ms |
11736 KB |
Output is correct |
40 |
Correct |
69 ms |
11840 KB |
Output is correct |
41 |
Correct |
83 ms |
16228 KB |
Output is correct |
42 |
Correct |
60 ms |
21132 KB |
Output is correct |
43 |
Correct |
62 ms |
21080 KB |
Output is correct |
44 |
Correct |
81 ms |
21112 KB |
Output is correct |
45 |
Correct |
129 ms |
21136 KB |
Output is correct |
46 |
Correct |
78 ms |
11748 KB |
Output is correct |
47 |
Correct |
105 ms |
20780 KB |
Output is correct |
48 |
Correct |
67 ms |
11532 KB |
Output is correct |
49 |
Correct |
76 ms |
16200 KB |
Output is correct |
50 |
Correct |
55 ms |
9592 KB |
Output is correct |
51 |
Correct |
96 ms |
21116 KB |
Output is correct |
52 |
Correct |
80 ms |
21084 KB |
Output is correct |
53 |
Correct |
89 ms |
21032 KB |
Output is correct |
54 |
Correct |
83 ms |
21140 KB |
Output is correct |
55 |
Correct |
81 ms |
11708 KB |
Output is correct |
56 |
Correct |
69 ms |
20284 KB |
Output is correct |
57 |
Correct |
15 ms |
1604 KB |
Output is correct |
58 |
Correct |
36 ms |
10860 KB |
Output is correct |
59 |
Correct |
91 ms |
20356 KB |
Output is correct |
60 |
Correct |
15 ms |
1596 KB |
Output is correct |
61 |
Correct |
39 ms |
5796 KB |
Output is correct |
62 |
Correct |
133 ms |
21144 KB |
Output is correct |
63 |
Correct |
134 ms |
21140 KB |
Output is correct |
64 |
Correct |
116 ms |
21052 KB |
Output is correct |
65 |
Correct |
108 ms |
21016 KB |
Output is correct |
66 |
Correct |
123 ms |
21136 KB |
Output is correct |
67 |
Correct |
119 ms |
21144 KB |
Output is correct |
68 |
Correct |
112 ms |
21040 KB |
Output is correct |
69 |
Correct |
103 ms |
16316 KB |
Output is correct |
70 |
Correct |
100 ms |
12184 KB |
Output is correct |
71 |
Correct |
133 ms |
21140 KB |
Output is correct |
72 |
Correct |
107 ms |
11716 KB |
Output is correct |
73 |
Correct |
99 ms |
14156 KB |
Output is correct |