AtCoder AGC017C Snuke and Spells
题目链接
https://atcoder.jp/contests/agc017/tasks/agc017_c
题解
很久前不会做看了题解,现在又看了一下,只想说,这种智商题真的杀我。。。
转化成如果现在有\(x\)个\(y\), 我们给区间\([y-x+1,y]\)都\(+1\),那么答案就是区间内\(0\)的个数。。
于是就很好\(O(n)\)维护了。。然而我真的想不到。。。
代码
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#define llong long long
#define ldouble long double
#define uint unsigned int
#define ullong unsigned long long
#define udouble unsigned double
#define uldouble unsigned long double
#define modinc(x) {if(x>=P) x-=P;}
#define pii pair<int,int>
#define piii pair<pair<int,int>,int>
#define piiii pair<pair<int,int>,pair<int,int> >
#define pli pair<llong,int>
#define pll pair<llong,llong>
#define Memset(a,x) {memset(a,x,sizeof(a));}
using namespace std;
const int N = 2e5;
int cnt[N+2];
int a[N+2];
int num[N+2];
int n,q,ans;
int main()
{
scanf("%d%d",&n,&q);
for(int i=1; i<=n; i++) {scanf("%d",&a[i]); cnt[a[i]]++;}
for(int i=1; i<=n; i++)
{
for(int j=max(i-cnt[i]+1,0); j<=i; j++) num[j]++;
}
for(int i=1; i<=n; i++) if(num[i]==0) ans++;
for(int i=1; i<=q; i++)
{
int x,y; scanf("%d%d",&x,&y);
cnt[a[x]]--; if(a[x]-cnt[a[x]]>0) {num[a[x]-cnt[a[x]]]--; if(num[a[x]-cnt[a[x]]]==0) ans++;}
a[x] = y;
if(y-cnt[y]>0) {if(num[y-cnt[y]]==0) ans--; num[y-cnt[y]]++;} cnt[y]++;
printf("%d\n",ans);
}
return 0;
}
AtCoder AGC017C Snuke and Spells的更多相关文章
- atcoder C - Snuke and Spells(模拟+思维)
题目链接:http://agc017.contest.atcoder.jp/tasks/agc017_c 题解:就是简单的模拟一下就行.看一下代码就能理解 #include <iostream& ...
- AGC017C Snuke and Spells(巧妙的线段覆盖模型)
题目大意: 给出n个球,每个球上都有数字,然后每次都进行如下操作 如果当前的球总共有k个,那么就把球上数字为k的所有球都消除掉 注意到,并不是每种情况都可以全部消光,所以你可以选择若干球,把它们标号改 ...
- 题解 [AGC017C] Snuke and Spells
题目传送门 Description 有 \(n\) 个球排在一起,每个球有颜色 \(a_i\),若当前有 \(k\) 个球,则会将所有 \(a_i=k\) 的球删掉.有 \(m\) 次查询,每次将 \ ...
- AtCoder arc061C Snuke's Subway Trip
大意: 给你一张无向图,边有种类. 当你第一次/重新进入某种边时费用 + 1 在同一种边之间行走无费用. 求 1 到 n 的最小费用. 嗯...乍一看有一个很直观的想法:记录每个点的最短路的上一条边的 ...
- AtCoder ARC061E Snuke's Subway Trip 最短路
目录 Catalog Solution: (有任何问题欢迎留言或私聊 && 欢迎交流讨论哦 Catalog Problem:传送门 Portal 原题目描述在最下面. \(n(1 ...
- AtCoder Grand Contest 017 题解
A - Biscuits 题目: 给出 \(n\) 个物品,每个物品有一个权值. 问有多少种选取方式使得物品权值之和 \(\bmod\space 2\) 为 \(p\). \(n \leq 50\) ...
- AtCoder Grand Contest 017 (VP)
contest link Official Editorial 比赛体验--之前做题的时候感觉 AtCoder 挺快的,现在打了VP之后发现还是会挂的--而且不是加载缓慢或者载不出来,直接给你一个无法 ...
- AtCoder Grand Contest 017
noi前橙名计划失败.全程搞C而gg…… A - Biscuits 题意:背包,求价值为奇/偶的方案数. #include<cstdio> #include<queue> #i ...
- 【AtCoder】AGC017
在此处输入标题 标签(空格分隔): 未分类 A - Biscuits dp[i][0/1]表示当前和是偶数还是奇数,直接转移即可 #include <bits/stdc++.h> #def ...
随机推荐
- 2019牛客暑期多校训练营(第五场)G - subsequeue 1 (一题我真的不会的题)
layout: post title: 2019牛客暑期多校训练营(第五场)G - subsequeue 1 (一题我真的不会的题) author: "luowentaoaa" c ...
- MateBook 换内存条
欢迎关注微信公众号:猫的尾巴有墨水 为啥要拆MateBook D笔记本? 最近这个Windows 10更新后,内存暴增,每次禁用windows update和同步服务模块后,依然不能彻底解决内存爆炸的 ...
- 基于Hadoop伪分布式集群搭建Spark
一.前置安装 1)JDK 2)Hadoop伪分布式集群 二.Scala安装 1)解压Scala安装包 2)环境变量 SCALA_HOME = C:\ProgramData\scala-2.10.6 P ...
- 三维数点的CDQ分治板子
int n, k, tot; struct _ {int x,r,f;} a[N]; struct __ { int type; ll x,y; bool operator < (const _ ...
- 基于IdentityServer4的声明的授权
## 概述 基于Asp.net Core 1.1 ,使用IdentityServer4认证与授权. ## 参考资料 [微软教程](https://docs.microsoft.com/zh-cn/as ...
- mybatis的if
<select id="findList" resultType="BndExport"> SELECT <include refid=&qu ...
- adb进阶知识,如何过滤只查看某一个app的日志
前面大概学习了adb基础,但是adb的存在,在测试人员中究竟有什么必要,以及看log时,那么多的log,让我们看个屁啊,所以这一次,我决定一定要把adb这件事情搞清楚. 1.先来看最感兴趣的adb ...
- multipart/form-data请求与文件上传的细节
<!DOCTYPE html><html><head lang="en"> <meta charset="UTF-8" ...
- 学习.NET中的AppDomain
学习.NET中的AppDomain 什么是AppDomain?AppDomain是一组程序集的逻辑容器,AppDomain是为了提供隔离而设计的.它提供了保护.配置和终止其中每一个应用程序的隔离 Ap ...
- 虚拟机Linux下扩展硬盘的方法
[原文链接]:http://blog.csdn.net/tianlesoftware/article/details/5642883 装虚拟机时空间划小了,于是又加了5G的空间,折腾了半天,挂上去了. ...