QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#143178#5526. Jewel of Data Structure ProblemsaVeWA 0ms3476kbC++201.1kb2023-08-20 20:34:472023-08-20 20:34:51

Judging History

你现在查看的是最新测评结果

  • [2023-08-20 20:34:51]
  • 评测
  • 测评结果:WA
  • 用时:0ms
  • 内存:3476kb
  • [2023-08-20 20:34:47]
  • 提交

answer

#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<long long, long long> pll;
typedef pair<int,int> pii;
typedef vector<long long> vl;
typedef vector<int> vi;
int main(){
	//5 2 4 3 1
	//3 2
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, q;
	cin>>n>>q;
	int arr[n+1],even = 0, sorted = 0;
	for(int i = 1; i <= n; i++){
		cin>>arr[i];
		if(arr[i] % 2 == i % 2) even++;
		if(arr[i] == i)	sorted++;
	}
	int now = (n-even)%2;
//	cout<<even<<" "<<sorted<<" "<<now<<endl;
	while(q--){
		int a, b;
		cin>>a>>b;
		if(arr[a] % 2 == a % 2)	even--;
		if(arr[b] % 2 == b % 2) even--;
		if(arr[a] == a)	sorted--;
		if(arr[b] == b)	sorted--;
		swap(arr[a], arr[b]);
		if(arr[a] % 2 == a % 2)	even++;
		if(arr[b] % 2 == b % 2) even++;
		if(arr[a] == a)	sorted++;
		if(arr[b] == b)	sorted++;
		
		now ^= 1;
//		cout<<even<<" "<<sorted<<" "<<now<<endl;
		if(now)	cout<<n<<"\n";
		else if(even != n)	cout<<n-1<<"\n";
		else if(sorted != n)	cout<<n-2<<"\n";
		else cout<<-1<<"\n";
	}
	return 0;
}

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 0
Wrong Answer
time: 0ms
memory: 3476kb

input:

5 6
2 1 3 4 5
1 2
1 2
1 4
2 1
3 5
1 3

output:

5
4
5
3
5
3

result:

wrong answer 1st numbers differ - expected: '-1', found: '5'