更好的阅读体验
\color{red}{更好的阅读体验}
更好的阅读体验
#include
using namespace std;
#define re register
const int N = 1e6 + 3;
int a[N];
void solve(){
int n, k;
cin >> n >> k;
for(re int i = 1; i <= n; i ++) cin >> a[i];
int cnt = 0;
for(re int i = 1; i <= k; i ++) if(a[i] > k) cnt ++;
cout << cnt << endl;
}
int main(){
// solve();
int _;
cin >> _;
while(_ --){
solve();
}
return 0;
}
#include
using namespace std;
#define re register
void solve(){
int n;
cin >> n;
if(n % 2 == 0){
for(re int i = 2; i <= n; i += 2) cout << i << " " << i - 1 << " ";
}
else{
cout << 1 << " ";
for(re int i = 3; i <= n; i += 2) cout << i << " " << i - 1 << " ";
}
cout << endl;
}
int main(){
// solve();
int _;
cin >> _;
while(_ --){
solve();
}
return 0;
}
int a[N]存储数组元素,set b 存储当前枚举到i之前,需要将
a
i
a_i
ai 变为
0
0
0 的
x
x
x 值i = 2开始枚举a[i]:
a[i]是否在b中,若存在,则更新a[i] = 0a[i - 1] > a[i],说明需要将a[i - 1]更新,将b.insert(a[i - 1]),且要使得i之前所有的a[j] == a[i - 1]的元素更新为
0
0
0,且在更新时,要将a[j] != 0的元素也加入b中i之前的序列一定满足不严格单调递增,在枚举结束之后,b中元素个数即为操作次数#include
using namespace std;
#define re register
const int N = 1e6 + 3;
int a[N];
set<int> b;
void solve(){
int n;
cin >> n;
for(re int i = 1; i <= n; i ++) cin >> a[i];
for(re int i = 2; i <= n; i ++){
if(b.count(a[i]) > 0) a[i] = 0;
if(a[i - 1] > a[i]){
b.insert(a[i - 1]);
a[i - 1] = 0;
for(re int j = i - 1; a[j] != 0 && j >= 1; j --){
b.insert(a[j]);
a[j] = 0;
}
}
}
cout << b.size() << endl;
b.clear();
}
int main(){
// solve();
int _;
cin >> _;
while(_ --){
solve();
}
return 0;
}
remakent题的我真是没救了,前几场着实给我打破防了,这回还好最后没放弃,继续努力吧