QOJ.ac

QOJ

ID题目提交者结果用时内存语言文件大小提交时间测评时间
#143177#5526. Jewel of Data Structure ProblemsaVeWA 22ms3640kbC++201.1kb2023-08-20 20:32:192023-08-20 20:32:21

Judging History

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

  • [2023-08-20 20:32:21]
  • 评测
  • 测评结果:WA
  • 用时:22ms
  • 内存:3640kb
  • [2023-08-20 20:32:19]
  • 提交

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(){
	//3 1 2 4
	//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 = (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;
}

詳細信息

Test #1:

score: 100
Accepted
time: 1ms
memory: 3424kb

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: 0
Accepted
time: 14ms
memory: 3388kb

input:

2 200000
1 2
2 1
2 1
2 1
1 2
1 2
2 1
1 2
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
3
2
3
2
3
2
3
-1
3
-1
3
2
3
2
3
2
3
2
3
-1
3
2
3
-1
3
-1
3
-1
3
2
3
-1
3
-1
3
2
3
2
3
2
3
2
3
-1
3
2
3
2
3
2
3
-1
3
-1
3
-1
3
-1
3
2
3
2
3
2
3
2
3
-1
3
-1
3
2
3
-1
3
2
3
2
3
2
3
-1
3
-1
3
2
...

result:

ok 200000 numbers

Test #4:

score: 0
Accepted
time: 22ms
memory: 3436kb

input:

4 200000
3 1 2 4
3 2
1 3
4 2
2 1
4 2
4 2
4 3
1 3
2 1
4 3
3 4
1 3
1 2
1 3
4 3
3 1
2 4
1 4
4 3
2 1
1 3
2 4
4 2
1 3
2 1
3 2
4 1
2 1
1 4
1 3
4 3
1 2
1 4
4 1
1 3
4 2
2 3
3 4
4 2
1 4
3 1
4 1
1 4
4 1
2 3
2 4
1 2
1 2
4 1
3 4
3 4
3 4
3 1
4 3
4 1
4 3
2 3
2 4
4 3
3 2
2 3
4 2
1 2
1 2
1 2
3 2
2 3
4 1
3 4
3 4
2 3...

output:

4
-1
4
3
4
3
4
3
4
-1
4
3
4
3
4
2
4
3
4
3
4
3
4
3
4
3
4
3
4
3
4
-1
4
-1
4
2
4
3
4
3
4
2
4
2
4
3
4
3
4
-1
4
-1
4
3
4
-1
4
3
4
3
4
-1
4
-1
4
3
4
3
4
3
4
2
4
2
4
3
4
3
4
-1
4
3
4
3
4
3
4
3
4
3
4
3
4
3
4
3
4
2
4
3
4
3
4
3
4
3
4
3
4
3
4
3
4
3
4
3
4
3
4
3
4
3
4
3
4
3
4
3
4
3
4
3
4
3
4
3
4
3
4
3
4
3
4
3
4
...

result:

ok 200000 numbers

Test #5:

score: -100
Wrong Answer
time: 18ms
memory: 3640kb

input:

5 200000
5 2 4 3 1
3 2
2 5
5 3
4 3
5 4
2 1
4 1
2 4
4 5
2 4
5 1
2 3
1 3
3 4
1 4
2 5
5 4
4 1
3 1
2 3
5 2
1 4
3 4
5 2
4 2
2 3
5 4
1 2
2 4
2 5
4 5
1 2
3 4
1 2
2 1
3 2
3 4
5 2
1 3
4 1
3 1
4 1
5 3
3 5
1 5
1 3
3 4
3 1
2 4
2 4
3 2
3 2
5 2
4 1
4 5
5 1
5 4
1 5
4 5
3 2
3 5
4 1
3 2
3 2
4 3
3 4
2 5
5 1
1 3
4 3
4...

output:

4
5
4
5
4
5
4
5
4
5
4
5
4
5
4
5
4
5
4
5
4
5
3
5
4
5
4
5
4
5
4
5
4
5
4
5
4
5
4
5
4
5
4
5
4
5
4
5
4
5
4
5
3
5
4
5
3
5
4
5
4
5
4
5
4
5
4
5
4
5
4
5
4
5
4
5
4
5
4
5
4
5
4
5
4
5
4
5
4
5
4
5
3
5
4
5
4
5
4
5
4
5
4
5
3
5
4
5
4
5
3
5
4
5
4
5
4
5
3
5
3
5
4
5
4
5
4
5
4
5
4
5
4
5
3
5
4
5
4
5
4
5
4
5
4
5
4
5
4
5
...

result:

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