QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#143173 | #5526. Jewel of Data Structure Problems | aVe | WA | 21ms | 3604kb | C++20 | 989b | 2023-08-20 20:29:17 | 2023-08-20 20:29:21 |
Judging History
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(){
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 != 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: 3476kb
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: 21ms
memory: 3604kb
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 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