|
本帖最后由 WYT 于 2025-4-7 21:07 编辑
include<bits/stdc++.h>
using namespace std;
int main(){
int tot = 1;
int n,m;
list<int>::iterator it,it1,it#2; while(cin >> n >> m){
list<int> arr;
for(int i = 0;i < n;i++){
arr.push_back(i + 1);
}
int op,n1,n2;
for(int i = 0;i < m;i++){
cin >> op;
if(op == 1){
cin >> n1 >> n2;
it1 = find(arr.begin(),arr.end(),n1);
it2 = find(arr.begin(),arr.end(),n2);
it = it1;
advance(it,1);
if(it == it2) continue;
else{
int t = *it1;
arr.erase(it1);
arr.insert(it2,t);
}
}else if(op == 2){
cin >> n1 >> n2;
it1 = find(arr.begin(),arr.end(),n1);
it2 = find(arr.begin(),arr.end(),n2);
it = it2;
it++;
if(it1 == it){
continue;
}else{
int t = *it1;
arr.erase(it1);
arr.insert(++it2,t);
}
}else if(op == 3){
cin >>n1 >> n2;
it1 = find(arr.begin(),arr.end(),n1);
it2 = find(arr.begin(),arr.end(),n2);
int t = *it1;
*it1 = *it2;
*it2 = t;
}else{
reverse(arr.begin(),arr.end());
}
}
long long k = 1,ans = 0;
for(it = arr.begin();it != arr.end();it++,k++){
if(k % 2 == 1) ans += *it;
}
cout << "Case " << tot++ << ": " << ans << endl;
}
return 0;
} 被警告了重发=^= |
|