QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#143172#5526. Jewel of Data Structure ProblemsaVeTL 1ms3396kbC++20943b2023-08-20 20:28:262023-08-20 20:28:29

Judging History

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

  • [2023-08-20 20:28:29]
  • 评测
  • 测评结果:TL
  • 用时:1ms
  • 内存:3396kb
  • [2023-08-20 20:28:26]
  • 提交

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(){
	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 = (even != n);
	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;
		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: 100
Accepted
time: 1ms
memory: 3396kb

input:

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

output:

-1
5
4
5
3
5

result:

ok 6 numbers

Test #2:

score: -100
Time Limit Exceeded

input:

2 200000
1 2
2 1
2 1
2 1
1 2
1 2
2 1
1 2
2 1
2 1
1 2
2 1
2 1
2 1
2 1
2 1
2 1
1 2
2 1
2 1
1 2
1 2
2 1
1 2
1 2
1 2
1 2
2 1
1 2
1 2
1 2
2 1
2 1
1 2
2 1
2 1
2 1
2 1
1 2
1 2
2 1
2 1
1 2
2 1
1 2
1 2
2 1
1 2
1 2
2 1
2 1
1 2
1 2
2 1
2 1
2 1
1 2
1 2
1 2
1 2
2 1
1 2
2 1
1 2
1 2
2 1
1 2
2 1
1 2
2 1
2 1
2 1
2 1...

output:

2
-1
2
-1
2
-1
2
-1
2
-1
2
-1
2
-1
2
-1
2
-1
2
-1
2
-1
2
-1
2
-1
2
-1
2
-1
2
-1
2
-1
2
-1
2
-1
2
-1
2
-1
2
-1
2
-1
2
-1
2
-1
2
-1
2
-1
2
-1
2
-1
2
-1
2
-1
2
-1
2
-1
2
-1
2
-1
2
-1
2
-1
2
-1
2
-1
2
-1
2
-1
2
-1
2
-1
2
-1
2
-1
2
-1
2
-1
2
-1
2
-1
2
-1
2
-1
2
-1
2
-1
2
-1
2
-1
2
-1
2
-1
2
-1
2
-1
2
-1
...

result: