【题解】

  第一眼看题飞快地想到一种做法,然后假掉了。

  这道题其实是主席树的模板题来着。但是也有别的水法。

  我们可以发现每个位置的查询区间是[1,min(a[i],i-1)],所以我们可以把查询区间按照右端点排序。开一个权值树状数组记录前i个a[i]的出现情况。我们从1到n按顺序插入a[i],每个位置上都统计min(a[j],j-1)=i的j的答案。

  

 1 #include<cstdio>
 2 #include<algorithm>
 3 #define rg register
 4 #define N 200010
 5 using namespace std;
 6 int n,a[N],b[N],d[N],t[N];
 7 long long ans;
 8 inline int read(){
 9     int k=0,f=1; char c=getchar();
10     while(c<'0'||c>'9')c=='-'&&(f=-1),c=getchar();
11     while('0'<=c&&c<='9')k=k*10+c-'0',c=getchar();
12     return k*f;
13 }
14 inline void add(int x){
15     for(;x<=n;x+=(x&-x)) t[x]++;
16 }
17 inline int query(int x){
18     int ret=0; for(;x>0;x-=(x&-x)) ret+=t[x]; return ret;
19 }
20 inline bool cmp(int x,int y){
21     return d[x]<d[y];
22 }
23 int main(){
24     n=read();
25     for(rg int i=1;i<=n;i++) a[i]=min(read(),n),b[i]=i,d[i]=min(a[i],i-1);
26     sort(b+1,b+1+n,cmp);
27     for(rg int i=1,j=1;i<=n;i++){
28         add(a[i]);
29         while(d[b[j]]<i&&j<=n) j++;
30         while(j<=n&&d[b[j]]==i) ans+=i-query(b[j++]-1);
31     }
32     printf("%I64d\n",ans);
33     return 0;
34 }

View Code

转载于:https://www.cnblogs.com/DriverLao/p/8728504.html

Educational Codeforces Round 41 E. Tufurama (961E)相关推荐

  1. Educational Codeforces Round 41 (Rated for Div. 2) ABCDEF

    最近打的比较少...就只有这么点题解了. A. Tetris time limit per test 1 second memory limit per test 256 megabytes inpu ...

  2. Educational Codeforces Round 41(已补D,E)

    D. Pair Of Lines 题目大意: 给\(n\)个点,问是否存在两条直线(可以为同一条)能覆盖所有的点. 解题思路: 首先一个或者两个或者三个点都是肯定可以用两条线覆盖的. 如果点的个数大于 ...

  3. Educational Codeforces Round 41 (Rated for Div. 2)

    这个D可以参考这个B的思路 A. Tetris time limit per test 1 second memory limit per test 256 megabytes input stand ...

  4. Educational Codeforces Round 41 (Rated for Div. 2) F. k-substrings

    F. k-substrings time limit per test 4 seconds memory limit per test 256 megabytes input standard inp ...

  5. Educational Codeforces Round 90 (Rated for Div. 2)(A, B, C, D, E)

    Educational Codeforces Round 90 (Rated for Div. 2) Donut Shops 思路 分三种情况: a==c/ba == c / ba==c/b这个时候两 ...

  6. Educational Codeforces Round 24 E. Card Game Again(双指针)

    题目链接:Educational Codeforces Round 24 E. Card Game Again 题意: 给你n个数和一个数k. 现在每次可以拿掉前x个数,后y个数,剩下的数的乘积要能被 ...

  7. Educational Codeforces Round 138 (Rated for Div. 2) D

    Educational Codeforces Round 138 (Rated for Div. 2) D. Counting Arrays 题意 给定长度为nnn的数组aaa,若gcd(ai,i)= ...

  8. Educational Codeforces Round 113 (Rated for Div. 2) ABCD 解题思路

    Educational Codeforces Round 113 (Rated for Div. 2) 经典卡CCC秒DDD,可惜了 怪自己特判写错了吧,对式子找了半天问题结果根本不是式子的问题 A ...

  9. Educational Codeforces Round 112 (Rated for Div. 2)-A. PizzaForces-题解

    目录 Educational Codeforces Round 112 (Rated for Div. 2)-A. PizzaForces Problem Description Input Outp ...

最新文章

  1. 终于有人把分布式事物TCC讲明白了
  2. 梦见男朋友和别的女生逛街,第一反应亮了... | 每日趣闻
  3. linux 内核 LINUX_VERSION_CODE 和 KERNEL_VERSION 宏定义 版本信息
  4. postman 并发测试
  5. ci框架的session类,怎么使用ci的session类
  6. endl、flush、ends、unitbuf、nounitbuf区别及详解
  7. 战神4 幕后花絮 概念艺术_Java 9幕后花絮:新功能从何而来?
  8. 【c语言】棋盘游戏--三子棋
  9. PHP 实现简单的 倒计时 时分秒
  10. uni-app中的tabBar配置
  11. isbool php,PHP PHPUnit assertIsBool()用法及代码示例
  12. macOS Big Sur无法识别USB外置驱动器怎么办
  13. 邮箱大师手机版服务器异常,邮箱大师安装步骤 邮箱大师常见问题
  14. 农业银行王敬东——金融科技时代商业银行战略模式选择初探
  15. 鸿蒙系统桌面天气如何设置,怎么设置桌面时间和天气预报?
  16. 现代投资组合理论python实现
  17. c语言如何判断当前是 空字符,c语言如何判断字串中没有没有某个字元?
  18. 银行系统日终结算要多久_银行 核心系统的清算与结算 - 系统性能与软件架构 - 51Testing软件测试网 51Testing软件测试网-软件测试人的精神家园...
  19. linux装百度网盘不能运行,在Deepin系统中安装百度网盘的两种方法
  20. UFS-Net: A unified flame and smoke detection method for early detection of fire in video surveillanc

热门文章

  1. docker安装elasticsearch和kibana
  2. Spring Boot集成Elastic Search
  3. Object类和常用API
  4. 从内存分配角度分析c和java里的static 关键字.
  5. 深究AngularJS——ng-checked(回写:带真实案例代码)
  6. 伪mac android,Mac,android sdk,monkey压力测试,真机
  7. 怎么把rmd改成html,在Rmd中的htmlTable - 转换为Word docx
  8. hashcode值一样对象一定相同吗_HashMap实现原理分析(面试问题:两个hashcode相同 的对象怎么存入hashmap的)...
  9. 技术盘点:2022年云原生架构趋势解读
  10. 从基础设施到云原生应用,全方位解读阿里云原生新锐开源项目