题目链接

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的更多相关文章

  1. atcoder C - Snuke and Spells(模拟+思维)

    题目链接:http://agc017.contest.atcoder.jp/tasks/agc017_c 题解:就是简单的模拟一下就行.看一下代码就能理解 #include <iostream& ...

  2. AGC017C Snuke and Spells(巧妙的线段覆盖模型)

    题目大意: 给出n个球,每个球上都有数字,然后每次都进行如下操作 如果当前的球总共有k个,那么就把球上数字为k的所有球都消除掉 注意到,并不是每种情况都可以全部消光,所以你可以选择若干球,把它们标号改 ...

  3. 题解 [AGC017C] Snuke and Spells

    题目传送门 Description 有 \(n\) 个球排在一起,每个球有颜色 \(a_i\),若当前有 \(k\) 个球,则会将所有 \(a_i=k\) 的球删掉.有 \(m\) 次查询,每次将 \ ...

  4. AtCoder arc061C Snuke's Subway Trip

    大意: 给你一张无向图,边有种类. 当你第一次/重新进入某种边时费用 + 1 在同一种边之间行走无费用. 求 1 到 n 的最小费用. 嗯...乍一看有一个很直观的想法:记录每个点的最短路的上一条边的 ...

  5. AtCoder ARC061E Snuke's Subway Trip 最短路

    目录 Catalog Solution: (有任何问题欢迎留言或私聊 && 欢迎交流讨论哦 Catalog Problem:传送门  Portal  原题目描述在最下面.  \(n(1 ...

  6. AtCoder Grand Contest 017 题解

    A - Biscuits 题目: 给出 \(n\) 个物品,每个物品有一个权值. 问有多少种选取方式使得物品权值之和 \(\bmod\space 2\) 为 \(p\). \(n \leq 50\) ...

  7. AtCoder Grand Contest 017 (VP)

    contest link Official Editorial 比赛体验--之前做题的时候感觉 AtCoder 挺快的,现在打了VP之后发现还是会挂的--而且不是加载缓慢或者载不出来,直接给你一个无法 ...

  8. AtCoder Grand Contest 017

    noi前橙名计划失败.全程搞C而gg…… A - Biscuits 题意:背包,求价值为奇/偶的方案数. #include<cstdio> #include<queue> #i ...

  9. 【AtCoder】AGC017

    在此处输入标题 标签(空格分隔): 未分类 A - Biscuits dp[i][0/1]表示当前和是偶数还是奇数,直接转移即可 #include <bits/stdc++.h> #def ...

随机推荐

  1. (电脑重置之后)win10在桌面点右键鼠标一直转圈;无法点击桌面图标;

    昨天重置系统之后,发现了这个毛病.桌面任务栏都能正常点击,就是一到桌面,无法点击桌面上面的图标(刚开机的时候还可以点).想新建文件夹来着,一点右键,鼠标即开始转圈圈.本来以为自己能好,结果第二天了还这 ...

  2. 埋在 MYSQL 数据库应用中的17个关键问题!

    Mysql的使用非常普遍,跟mysql有关的话题也非常多,如性能优化.高可用性.强一致性.安全.备份.集群.横向扩展.纵向扩展.负载均衡.读写分离等.要想掌握其中的精髓,可得花费不少功力,虽然目前流行 ...

  3. mybatis postgresql insert后返回自增id

    在使用mybatis + postgresql,我们有时在插入数据时需要返回自增id的值,此时在插入时,可以按照以下例子来编写mapper文件 <insert id="insertUs ...

  4. v-bind:value="diy" 添加到 <input type="button" /> 中可以,添加到<button />中不可以,diy是data中的数据

    v-bind:value="diy" 添加到 <input type="button" /> 中可以, 添加到<button />中不可 ...

  5. 1.K近邻算法

    (一)K近邻算法基础 K近邻(KNN)算法优点 思想极度简单 应用数学知识少(近乎为0) 效果好 可以解释机器学习算法使用过程中的很多细节问题 更完整的刻画机器学习应用的流程 图解K近邻算法 上图是以 ...

  6. 浙大数据结构课后习题 练习一 7-1 Maximum Subsequence Sum (25 分)

    Given a sequence of K integers { N​1​​, N​2​​, ..., N​K​​ }. A continuous subsequence is defined to ...

  7. Java模板引擎性能对比

    模板引擎性能对比 从Github上翻到对JSP.Thymeleaf 3.Velocity 1.7.Freemarker 2.3.23几款主流模板的性能对比,总体上看,Freemarker.Veloci ...

  8. 标准C语言(6)

    数组名称不可以代表任何存储区(数组名称不可以被赋值),数组名称可以代表数组里第一个存储区的地址 /* * 数组练习 * */ #include <stdio.h> #include < ...

  9. 【python基础】字符串方法汇总

    一.声明 0-多个字符组成的有序序列; 二.特点 1. 字符串是一个不可变的数据类型 2.字符串是有序的 三.索引 下标:'abcde' 1.从左到右, 0, 1,2, ... 2.从右到左, 索引值 ...

  10. mybatis-plus generator使用

    pom配置 <dependency> <groupId>com.baomidou</groupId> <artifactId>mybatis-plus- ...