期望:100 + 50 + 30 = 180

实际:0 + 50 + 30 =80

期望:100   实际:0

数值有负数,边界应该设为-0x7f       此处 gg

/*
期望的分:50+
*/
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define MAXN 100010
using namespace std;
int n,tot,ans;
int f[MAXN];
int num[MAXN],w[MAXN],a[MAXN];
int lchild[MAXN],rchild[MAXN];
int read(){
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
void pre(int now){
if(now==) return ;
num[++tot]=now;
if(rchild[now]) pre(rchild[now]);
if(lchild[now]) pre(lchild[now]);
}
int main(){
//freopen("lpp.in","r",stdin);
freopen("point.in","r",stdin);
freopen("point.out","w",stdout);
n=read();
for(int i=;i<=n;i++) w[i]=read();
for(int i=;i<=n;i++){
lchild[i]=read();
rchild[i]=read();
}
pre();
for(int i=;i<=n;i++) a[i]=w[num[i]];
memset(f,-0x7f,sizeof(f));
for(int i=;i<=n;i++){
if(a[i]>f[ans]) f[++ans]=a[i];
else{
int x=lower_bound(f+,f++ans,a[i])-f;
f[x]=a[i];
}
}
printf("%d\n",ans);
}
/*
10
-77 -24 21 6 -4 -69 -1 -19 76 -1
5 2
7 8
0 0
6 9
10 4
0 3
0 0
0 0
0 0
0 0
*/

100

/*
期望:50+;
*/
#include<queue>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int n;
long long ans;
int a[],b[];
int read(){
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
void work(int l,int r){
if(l==r) return;
int mid=(l+r)/;
work(l,mid);
work(mid+,r);
int i=l,j=mid+;
int nb=;
while(i<=mid||j<=r){
if(i>mid) b[++nb]=a[j++];
else if(j>r) b[++nb]=a[i++];
else{
if(a[i]<a[j]) b[++nb]=a[i++];
else{
b[++nb]=a[j++];
ans+=mid-i+;
}
}
}
for(i=l;i<=r;++i) a[i]=b[i-l+];
}
int main(){
//freopen("lpp.in","r",stdin);
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
n=read();
if(n==){
int x=read();int y=read();
if(x>y) swap(x,y);
printf("%d\n",(y-x)*-);
}
else if(n==){
int x1=read();int y1=read();
int x2=read();int y2=read();
if(x1>y1) swap(x1,y1);
if(x2>y2) swap(x2,y2);
if(x1==x2&&y1==y2){ printf("0\n");return ; }
if(x1<x2&&y1>y2||x2<x1&&y2>y1){ printf("%d\n",(y1-x1)*-+(y2-x2)*-);return ;}
if(x2>y1||x1>y2){ printf("%d\n",(y1-x1)*-+(y2-x2)*-);return ;}
if(y1==x2||y2==x1){ printf("%d\n",(y1-x1)*-+(y2-x2)*--);return ;}
if(x2>x1&&x2<y1){ printf("%d\n",(y1-x1)*-+(y2-x2)*---(y1-x2));return ;}
if(x1>x2&&x1<y2){ printf("%d\n",(y1-x1)*-+(y2-x2)*---(y2-x1));return ;}
}
else{
for(int i=;i<=;i++) a[i]=i;
for(int i=;i<=n;i++){
int x=read();int y=read();
swap(a[x],a[y]);
}
work(,);
printf("%d\n",ans);
}
}

50分暴力

/*
分成三部分讨论
第一部分:讨论修改位置的数对答案的贡献
第二部分:讨论修改部分的区间对答案的贡献。
第三部分:讨论余下未修改的对答案的贡献。
可以发现,第一部分用树状数组暴力求逆序对维护。第二部分前缀和差分维护,第三部分的贡献为0.
*/
#include<queue>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int n,m;
long long ans;
int x[],y[],pos[];
int date[],T[],sum[];
int read(){
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int lowbit(int x){
return x&(-x);
}
void add(int x){
for(int i=x;i<=n*;i+=lowbit(i)) T[i]++;
}
long long query(int x){
long long bns=;
for(int i=x;i;i-=lowbit(i)) bns+=T[i];
return bns;
}
int main(){
freopen("a.in","r",stdin);
freopen("a.out","w",stdout);
n=read();
for(int i=;i<=n;i++){
x[i]=read();
y[i]=read();
date[i]=x[i];date[i+n]=y[i];
pos[i]=i;pos[i+n]=i+n;
}
sort(date+,date++*n);
int num=unique(date+,date++*n)-date-;
for(int i=;i<=num;i++) sum[i]=sum[i-]+date[i]-date[i-]-;
for(int i=;i<=n;i++){
x[i]=lower_bound(date+,date++num,x[i])-date;
y[i]=lower_bound(date+,date++num,y[i])-date;
swap(pos[x[i]],pos[y[i]]);
}
for(int i=num;i>=;i--){
ans+=query(pos[i]);
ans+=abs(sum[pos[i]]-sum[i]);
add(pos[i]);
}
printf("%I64d",ans);
}

100

/*
期望:30
*/
#include<queue>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int n,q,tot;
int dad[],num[];
int to[],net[],head[];
int col[],vis[],into[];
struct nond{
int l,r,col,vi;
}v[];
int read(){
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
void add(int u,int v){
to[++tot]=v;net[tot]=head[u];head[u]=tot;
}
void bfs(int s,int a,int b){
queue<int>que;
if(col[s]==a) col[s]=b;
que.push(s);vis[s]=;
while(!que.empty()){
int now=que.front();
que.pop();
for(int i=head[now];i;i=net[i])
if(!vis[to[i]]){
if(col[to[i]]==a) col[to[i]]=b;
if(col[to[i]]==col[s]){
vis[to[i]]=;
que.push(to[i]);
}
}
}
}
int main(){
//freopen("lpp.in","r",stdin);
freopen("simulator.in","r",stdin);
freopen("simulator.out","w",stdout);
n=read();q=read();
for(int i=;i<=n;i++) col[i]=read();
for(int i=;i<n;i++){
int u=read();
int v=read();
add(u,v);add(v,u);
into[u]++;into[v]++;
}
if(n<=){
for(int i=;i<=q;i++){
int a=read();int b=read();
memset(vis,,sizeof(vis));
int num=;
for(int j=;j<=n;j++)
if(!vis[j]){
bfs(j,a,b);
num++;
}
printf("%d\n",num);
}
}
}

30分暴力

/*
我们考虑优化合并操作,我们发现把x变成y和把y变成x得到的答案是相同的,
所以我们在合并的时候以及更改颜色的时候都是把颜色少的改成颜色多的,并
且维护每种颜色实际的vector是哪个,然后就相当于启发式合并。
每个点的复杂度是他的度数乘以它被统计答案的次数,
最差情况下每个点也只会被统计logN次答案,那么复杂度就是logN *
等于2NlogN
*/
#include<vector>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int n,q,tot,ans;
int id[];
int col[],size[],dad[];
int to[],net[],head[];
vector<int>vec[];
int read(){
int x=,f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
void add(int u,int v){
to[++tot]=v;net[tot]=head[u];head[u]=tot;
}
void dfs(int now){
for(int i=head[now];i;i=net[i])
if(dad[now]!=to[i]){
dad[to[i]]=now;
dfs(to[i]);
if(col[to[i]]!=col[now]) ans++;
}
}
void change1(int now){
for(int i=head[now];i;i=net[i])
if(col[to[i]]!=col[now]) ans--;
}
void change2(int now){
for(int i=head[now];i;i=net[i])
if(col[to[i]]!=col[now]) ans++;
}
int main(){
freopen("simulator.in","r",stdin);
freopen("simulator.out","w",stdout);
n=read();q=read();
for(int i=;i<=n;i++){
id[i]=i;
col[i]=read();
size[col[i]]++;
vec[col[i]].push_back(i);
}
for(int i=;i<n;i++){
int u=read();
int v=read();
add(u,v);add(v,u);
}
add(,);add(,);col[]=;
dfs();//cout<<ans;
for(int i=;i<=q;i++){
int a=read();int b=read();
int xn=id[a],yn=id[b];
if(size[xn]<=size[yn]){
for(int j=;j<vec[xn].size();j++){
change1(vec[xn][j]);
vec[yn].push_back(vec[xn][j]);
}
for(int j=;j<vec[xn].size();j++) col[vec[xn][j]]=yn;
for(int j=;j<vec[xn].size();j++) change2(vec[xn][j]);
size[yn]+=size[xn];
size[xn]=;id[b]=yn;
vec[xn].clear();
}
else{
for(int j=;j<vec[yn].size();j++){
change1(vec[yn][j]);
vec[xn].push_back(vec[yn][j]);
}
for(int j=;j<vec[yn].size();j++) col[vec[yn][j]]=xn;
for(int j=;j<vec[yn].size();j++) change2(vec[yn][j]);
size[xn]+=size[yn];
size[yn]=;
id[b]=xn;id[a]=;
vec[yn].clear();
}
printf("%d\n",ans);
}
}
/*
6 3
1 2 1 1 1 2
1 2
1 3
2 4
2 5
5 6 */

100

2018 11.2 PION模拟赛的更多相关文章

  1. 2018.11.7 PION 模拟赛

    期望:100 + 80 + 75 = 255 实际:0 + 80 + 60 = 140 唉~一天比一天犯的错误智障,感觉noip要凉啊... 吓得我赶紧吃几颗药补补脑子. 奶一下大佬: lgj AK ...

  2. 2018.11.6 PION 模拟赛

    期望:100 + 40 + 50 = 190 实际:60 + 10 + 50 = 120 考得好炸啊!!T1数组开小了炸掉40,T2用 int 读入 long long ,int存储 long lon ...

  3. 2018.11.5 PION模拟赛

    期望:30 + 40 + 50 = 120 实际:30 + 50 + 40 = 120 ‘’ 思路:最重要的是发现 是完全没有用的,然后这个题目就可以转成DP来做. /* 期望的分:30 */ #in ...

  4. 2018.11.3 PION模拟赛

    期望:100    实际:100 #include<cstdio> #include<cstring> #include<iostream> #include< ...

  5. 2018 11.1 PION 模拟赛

    期望:250  100+100+50 实际:210   80+100+30 期望:100   实际:80 最后:两个点T了.可能是求逆元的方法太慢了,也可能是闲的又加了一个快速乘的原因. #inclu ...

  6. 11.7 NOIP模拟赛

    目录 2018.11.7 NOIP模拟 A 序列sequence(two pointers) B 锁lock(思路) C 正方形square(埃氏筛) 考试代码 B C 2018.11.7 NOIP模 ...

  7. 11/1 NOIP 模拟赛

    11.1 NOIP 模拟赛 期望得分:50:实际得分:50: 思路:暴力枚举 + 快速幂 #include <algorithm> #include <cstring> #in ...

  8. EZ 2018 06 17 NOIP2018 模拟赛(十九)

    这次的题目难得的水,但是由于许多哲学的原因,第二题题意表述很迷. 然后是真的猜题意了搞了. 不过这样都可以涨Rating我也是服了. Upt:链接莫名又消失了 A. 「NOIP2017模拟赛11.03 ...

  9. EZ 2018 06 10 NOIP2018 模拟赛(十八)

    好久没写blog&&比赛题解了,最近补一下 这次还是很狗的,T3想了很久最后竟然连并查集都忘写了,然后T2map莫名爆炸. Rating爆减......链接不解释 好了我们开始看题. ...

随机推荐

  1. vijos 1053 Easy sssp

    描述 输入数据给出一个有N(2 <= N <= 1,000)个节点,M(M <= 100,000)条边的带权有向图. 要求你写一个程序, 判断这个有向图中是否存在负权回路. 如果从一 ...

  2. IOS OS X 中集中消息的传递机制

    1 KVO (key-value Observing) 是提供对象属性被改变是的通知机制.KVO的实现实在Foundation中,很多基于 Foundation 的框架都依赖与它.如果只对某一个对象的 ...

  3. PHP一句话后门过狗姿势万千之理论篇

    写在前面: 过狗相关的资料网上也是有很多,所以在我接下来的文章中,可能观点或者举例可能会与网上部分雷同,或者表述不够全面. 但是我只能说,我所传达给大家的信息,是我目前所掌握或者了解的,不能保证所有人 ...

  4. Python 中print 和return 的区别

    1.print() print()函数的作用是输出数据到控制台,就是打印在你能看到的界面上. 2.return return语句[表达式]退出函数,选择性地向调用方返回一个表达式.不带参数值的retu ...

  5. js实现复制input的value到剪切板

    <button class="button-code button-copy">复制链接</button><script> $(".b ...

  6. 小程序request请求 POST请求参数传递不到后台

    wx.request({ url: 'https://xxx.com/xxxx.php', data: { 'jscode': code }, method: 'POST', header: { &q ...

  7. 【收藏】史上最全的浏览器 CSS & JS Hack 手册

    浏览器渲染页面的方式各不相同,甚至同一浏览器的不同版本(“杰出代表”是 IE)也有差异.因此,浏览器兼容成为前端开发人员的必备技能.如果有一份浏览器 Hack 手册,那查询起来就方便多了.这篇文章就向 ...

  8. 关于C/C++的一些思考(5)

    运算符重载函数的限制: 五个不能实现重载的符号:".", ".*", "::", "?", "sizeof&q ...

  9. centos7 rsync+inotify软件实现集群服务的数据备份(一)

    一.rsync软件的说明: 1.1 什么是rsync rsync是一个远程数据同步工具,可通过LAN/WAN快速同步多台主机间的文件.它使用所谓的“Rsync演算法”来使本地和远程两个主机之间的文件达 ...

  10. (2) LVS负载均衡:VS_TUN和VS_DR的arp问题

    1. ARP协议简介 ARP(Address Resolution Protocol)协议称为地址解析协议,用于将主机IP地址解析为主机的MAC地址,即IP-->MAC之间一一映射. RARP协 ...