当前位置:网站首页>Codeforces 1638 B. odd swap sort - tree array, no, simple thinking
Codeforces 1638 B. odd swap sort - tree array, no, simple thinking
2022-06-12 13:33:00 【Tianyi City*】
The question :
Give you a length of n Array of a, If a[i]+a[i+1] Is odd , Then you can exchange a[i] and a[i+1], Ask if you can finally make the array a Non falling .
Answer key :
I didn't sleep at noon … The afternoon was sombre , Not clear thinking .
My idea is , Sort from small to large , Each number must reach the sorted position , Naturally, all the numbers smaller than him should be exchanged . Therefore, it depends on whether all the numbers less than it after each number are the same odd or even with it .
My approach is , To the current position , Check whether all the numbers less than it at the same level or even at this position have been taken .
Of course I'm very stupid here , Why should we see if we have finished taking it ? Just look at whether the odd sequence and the even sequence are incremented respectively ? I don't know what I'm doing, wasting my time
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5,M=1e9+5;
int a[N],b[N],od[N];
struct Array{
unordered_map<int,int>v;
int lowbit(int x){
return x&(-x);}
void add(int x){
for(int i=x;i<M;i+=lowbit(i))
v[i]++;
}
int ask(int x){
int ans=0;
for(int i=x;i;i-=lowbit(i))
ans+=v[i];
return ans;
}
}tr[2];
int main()
{
int t;
scanf("%d",&t);
for(int tim=1;tim<=t;tim++){
tr[0].v.clear(),tr[1].v.clear();
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++)scanf("%d",&a[i]),b[i]=a[i];
sort(b+1,b+1+n);
for(int i=1;i<=n;i++)od[i]=od[i-1]+(b[i]%2);
int f=0;
for(int i=1;i<=n;i++){
tr[a[i]%2].add(a[i]);
int p=lower_bound(b+1,b+1+n,a[i])-b;
int num=a[i]%2?od[p]:p-od[p];
if(tr[a[i]%2].ask(a[i]-1)-num+1)f=1;
}
printf("%s\n",f?"NO":"YES");
}
return 0;
}
边栏推荐
- 高通平台开发系列讲解(协议篇)QMI简单介绍及使用方法
- FFmpeg 学习指南
- Innovation training (XII) project summary
- Codeforces 1629 C. Mexico array - simple greed
- 在 Debian 10 上独立安装MySQL数据库
- Time processing in C language (conversion between string and timestamp)
- leetcode 47. Permutations II full permutations II (medium)
- Octopus network progress monthly report | may 1-May 31, 2022
- Application of bit operation in C language
- 2062: [example 1.3] movie tickets
猜你喜欢

torch_ About the geometric Mini batch

imagemagick:a gentle introduction to magick++

事件的传递和响应以及使用实例
![[WUSTCTF2020]颜值成绩查询-1](/img/dc/47626011333a0e853be87e492d8528.png)
[WUSTCTF2020]颜值成绩查询-1

成功定级腾讯T3-2,万字解析

Semantic segmentation with pytorch

Implementing tensorflow deep learning framework similarflow with numpy

import torch_ Data view of geometric

The goods are full. You must take this knowledge
颜色编码格式介绍
随机推荐
数据类型转换和条件控制语句
Redis消息队列重复消费问题
import torch_ Geometric loads some common datasets
软件构造 03 正则表达式
播放器屏幕方向方案
JVM 运行时参数
1005: estimation of the earth's population carrying capacity
Hudi key generation
事件的传递和响应以及使用实例
当字节跳动在美国输出中国式 996
成功跳槽阿里,进阶学习
Redis message queue repeated consumption
torch_geometric message passing network
创新实训(十二)项目总结
Rk3399 platform development series explanation (kernel debugging chapter) 2.50 use of systrace
It is enough to read this article. Web Chinese development
LeetCode滑动窗口刷题总结
Computational hierarchy -- the problem of large numbers multiplying decimals
Record some settings for visual studio 2019
m1 pod install pod lint 失败解决方案