0%

ABC-382-C - Kaiten Sushi

思路讲解

1
2
3
4
5
6
struct cmp{
bool operator()(const pll &a,const pll &b) const {
return a.fi>b.fi;
}
};
multiset<pll,cmp> B;

给multiset的cmp记得加const,否则有可能CE

1
2
3
4
5
6
7
8
9
for(multiset<pll>::iterator it=B.begin();it!=B.end();){
if(it->first<A[i]){
break;
}
multiset<pll>::iterator next_it=next(it);
ans[it->second]=i;
B.erase(it);
it=next_it;
}

然后erase()只能传入iterator,不能够传入reverse_iterator

AC代码

https://atcoder.jp/contests/abc382/submissions/62419496

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Problem: C - Kaiten Sushi
// Contest: AtCoder - AtCoder Beginner Contest 382
// URL: https://atcoder.jp/contests/abc382/tasks/abc382_c
// Memory Limit: 1024 MB
// Time Limit: 2000 ms
// by znzryb
//
// Powered by CP Editor (https://cpeditor.org)

#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define ROF(i, a, b) for (int i = a; i >= b; --i)
#define all(x) x.begin(),x.end()
#define CLR(i,a) memset(i,a,sizeof(i))
#define fi first
#define se second
#define pb push_back

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef array<ll,3> arr;
typedef double DB;
const ll MAXN=static_cast<ll>(2e5)+10,INF=static_cast<ll>(5e18)+3;

ll N,M,A[MAXN];
// pll B[MAXN];
struct cmp{
bool operator()(const pll &a,const pll &b) const {
return a.fi>b.fi;
}
};
multiset<pll,cmp> B;
ll ans[MAXN];

int main()
{
ios::sync_with_stdio(false);
cin.tie(0);cout.tie(0);
cin>>N>>M;
FOR(i, 1, N){
cin>>A[i];
}
FOR(i, 1, M){
ll b;
cin>>b;
B.insert({b,i});
}
FOR(i,1,M){
ans[i]=-1;
}

FOR(i,1,N){
for(multiset<pll>::iterator it=B.begin();it!=B.end();){
if(it->first<A[i]){
break;
}
multiset<pll>::iterator next_it=next(it);
ans[it->second]=i;
B.erase(it);
it=next_it;
}
}
FOR(i,1,M){
cout<<ans[i]<<'\n';
}
return 0;
}
/*
AC
https://atcoder.jp/contests/abc382/submissions/62419496
*/

心路历程(WA,TLE,MLE……)