Tufurama CodeForces - 961E】的更多相关文章

Tufurama CodeForces - 961E 题意:有一部电视剧有n季,每一季有ai集.问有多少对i,j存在第i季第j集也同时存在第j季第i集. 思路:核心问题还是统计对于第i季,你要统计第i行(存在多少数量,要大于i). 线段树的维护相对而言比较暴力,树状数组的话,一开始全是1,一旦某个数过小,就会导致不构成贡献,移除就好. 线段树 #include<cstdio> #include<iostream> #include<algorithm> #include…
题面 One day Polycarp decided to rewatch his absolute favourite episode of well-known TV series "Tufurama". He was pretty surprised when he got results only for season 7 episode 3 with his search query of "Watch Tufurama season 3 episode 7 on…
961E - Tufurama 思路: 线段树或者分块 遍历 1 - n - 1,求 区间[i + 1, min(a[i], n)]大于等于 i 的个数,累加起来 线段树: #include<bits/stdc++.h> using namespace std; #define LL long long #define pb push_back #define ls rt << 1, l, m #define rs rt << 1 | 1, m + 1, r #defi…
传送门 一眼主席树sbsbsb题(%%%树状数组大佬们). 简化题意:求满足x<y,y≤ax,x≤ayx<y,y\le a_x,x\le a_yx<y,y≤ax​,x≤ay​的(x,y)(x,y)(x,y)数量. 那么直接用主席树模拟题意就行了.(写完发现权值线段树就行了但是懒得改了) 代码: #include<bits/stdc++.h> #define ri register int using namespace std; typedef long long ll; i…
转自:https://blog.csdn.net/my_sunshine26/article/details/79831362 题目大意: i从1开始 基本思路: 完全没思路,所以上来就二分,果不其然卡死在了第7个样例,然后认为是贪心,苦思冥想未果,然后就看了答案. 说是主席树模板题,但是可以用巧方法过了,大部分用的都是树状数组好像,然后想了想也没想出来用树状数组能好到那里去, 然后参考了下答案思路,嗯,这绝对不是我能想到的,难受,就很难受. 正确思路: 1.先记录满足i<=a[j]的最大下标i…
题意: 给出一个n个数的序列,求有几对(i,j)满足a[i]>=j&&a[j]>=i,(i,j)和(j,i)只能算一对. 考虑第i个数会有几个j(j<i)满足条件,首先a[i]>=j就是查询的区间就是[1,a[i]],a[j]>i也就是查询区间[1,a[i]]中有几个a[j]>=i. 岂不主席树?注意去重就行了. //by zykykyk #include<cstdio> #include<ctime> #include<i…
挺巧妙的数据结构题(不过据说这是一种套路? E. Tufurama One day Polycarp decided to rewatch his absolute favourite episode of well-known TV series "Tufurama". He was pretty surprised when he got results only for season 7 episode 3 with his search query of "Watch…
[题解] 第一眼看题飞快地想到一种做法,然后假掉了. 这道题其实是主席树的模板题来着.但是也有别的水法. 我们可以发现每个位置的查询区间是[1,min(a[i],i-1)],所以我们可以把查询区间按照右端点排序.开一个权值树状数组记录前i个a[i]的出现情况.我们从1到n按顺序插入a[i],每个位置上都统计min(a[j],j-1)=i的j的答案. #include<cstdio> #include<algorithm> #define rg register #define N…
Educational Codeforces Round 41 (Rated for Div. 2) E. Tufurama (CDQ分治 求 二维点数) time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output One day Polycarp decided to rewatch his absolute favourite epi…
Discription One day Polycarp decided to rewatch his absolute favourite episode of well-known TV series "Tufurama". He was pretty surprised when he got results only for season 7 episode 3 with his search query of "Watch Tufurama season 3 epi…