深圳网站设计兴田德润信任高,搜索引擎优化时营销关键词,视频编辑sdk,北京专业网站制作介绍传送门 文章目录题意#xff1a;思路#xff1a;题意#xff1a;
给你nnn个数#xff0c;每个数初始方向是向右#xff0c;每次可以交换相邻两个位置并且将这两个位置的方向调换#xff0c;问这个序列的最终状态能否是非递减且方向都向右。 n≤1e5,ai≤1e5n\le1e5,a_i\l…传送门
文章目录题意思路题意
给你nnn个数每个数初始方向是向右每次可以交换相邻两个位置并且将这两个位置的方向调换问这个序列的最终状态能否是非递减且方向都向右。 n≤1e5,ai≤1e5n\le1e5,a_i\le1e5n≤1e5,ai≤1e5
思路
考虑每个位置只能操作偶数次所以对于aia_iai的初始位置在偶数和奇数的个数一定等于排序之后在偶数或奇数的位置个数所以统计一下排个序即可。
不知道为什么我一直在想树状数组真是数据结构学魔怔了。
// Problem: C. AquaMoon and Strange Sort
// Contest: Codeforces - Codeforces Round #732 (Div. 2)
// URL: https://codeforces.com/contest/1546/problem/C
// Memory Limit: 256 MB
// Time Limit: 1000 ms
//
// Powered by CP Editor (https://cpeditor.org)//#pragma GCC optimize(Ofast,no-stack-protector,unroll-loops,fast-math)
//#pragma GCC target(sse,sse2,sse3,ssse3,sse4.1,sse4.2,avx,avx2,popcnt,tunenative)
//#pragma GCC optimize(2)
#includecstdio
#includeiostream
#includestring
#includecstring
#includemap
#includecmath
#includecctype
#includevector
#includeset
#includequeue
#includealgorithm
#includesstream
#includectime
#includecstdlib
#includerandom
#includecassert
#define X first
#define Y second
#define L (u1)
#define R (u1|1)
#define pb push_back
#define mk make_pair
#define Mid ((tr[u].ltr[u].r)1)
#define Len(u) (tr[u].r-tr[u].l1)
#define random(a,b) ((a)rand()%((b)-(a)1))
#define db puts(---)
using namespace std;//void rd_cre() { freopen(d://dp//data.txt,w,stdout); srand(time(NULL)); }
//void rd_ac() { freopen(d://dp//data.txt,r,stdin); freopen(d://dp//AC.txt,w,stdout); }
//void rd_wa() { freopen(d://dp//data.txt,r,stdin); freopen(d://dp//WA.txt,w,stdout); }typedef long long LL;
typedef unsigned long long ULL;
typedef pairint,int PII;const int N1000010,mod1e97,INF0x3f3f3f3f;
const double eps1e-6;int n;
int a[N];
mapint,intmp1,mp2;bool check() {for(int i1;in;i) {if(i%21) mp1[a[i]]--;else mp2[a[i]]--;}for(auto x:mp1) if(x.Y) return false;for(auto x:mp2) if(x.Y) return false;return true;
}int main()
{
// ios::sync_with_stdio(false);
// cin.tie(0);int _; scanf(%d,_);while(_--) {scanf(%d,n);for(int i1;in;i) scanf(%d,a[i]);mp1.clear(); mp2.clear();for(int i1;in;i) {if(i%21) mp1[a[i]];else mp2[a[i]];}sort(a1,a1n);puts(check()? YES:NO);}return 0;
}
/**/