首页 > 小猫排队
头像 周康禧
发表于 2025-12-22 18:32:12
倒着算出每一个可以换的位置是第几分钟,然后如果在这个位置的离开之前就可以换到这个位置,就是取这个位置下标,如果大于这个位置的离开时间,那么换过来的时候已经不存在这个位置了,ans初始化n+1,因为可能所有的a[i]都不能交换 void solve(){ int n; cin>& 展开全文
头像 olone
发表于 2025-12-22 11:55:00
#include<bits/stdc++.h> using namespace std; const int N=2e5+5; int n,k; int a[N]; int pre[N]; int main() { cin>>n; for(int i= 展开全文
头像 Jakeap
发表于 2025-12-22 11:57:09
两种方法:(第二种也就是没注释的借鉴了题解中大佬的代码,用的vector容器中back()和pop_back())方法一:直接用数组模拟:数组大小开到n+1从1开始,最后一个存啾啾的可爱值。双指针l和r循环,r代表的是啾啾当前所在的位置,每次去找往r前面比啾啾可爱值更大的将其替换为啾啾,如果r< 展开全文
头像 cyccy
发表于 2025-12-22 19:55:04
#include<bits/stdc++.h> using namespace std; using i64 = long long; /* 找到所有可交换的位置 若最终可以交换到这个位置,一定有该位置下标(1-index) >= 交换次数 显然具有单调性,二分答案找到这个位置输 展开全文
头像 彭显汧
发表于 2025-12-22 20:39:08
#include<iostream> #include<algorithm> using namespace std; const int N=200020; int n,hh=0,tt=-1; long long w,dq[N]; int main() { scan 展开全文
头像 MaoPaoMiao
发表于 2025-12-22 20:46:52
#include <bits/stdc++.h> using namespace std; signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); int n; cin >> 展开全文
头像 IA3000
发表于 2025-12-22 03:11:25
#include <iostream> using namespace std; const int N= 2e5+5; int stk[N],t,a[N]; int nxt[N]; int main() { int n; cin>>n; n++ 展开全文
头像 YunBaichuan
发表于 2025-12-22 10:27:51
思路:按照题意,用双指针进行模拟即可 代码: import sys input = lambda: sys.stdin.readline().strip() import math inf = 10 ** 18 def I(): return input() def II(): 展开全文
头像 quchen666
发表于 2025-12-22 13:14:47
#include <bits/stdc++.h> using namespace std; const int N = 3e5+10; int a[N]; int n; int main() { ios::sync_with_stdio(false); cin.tie(0 展开全文
头像 9shdqm13
发表于 2025-12-22 13:33:09
没看到题解用pq写的,感觉这样写比较方便。 #include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> a(n+1); 展开全文