当前位置:网站首页>教育Codeforces轮41(额定Div。2)大肠Tufurama
教育Codeforces轮41(额定Div。2)大肠Tufurama
2022-08-10 12:56:00 【Snow_raw】
Educational Codeforces Round 41 (Rated for Div. 2) E. Tufurama
题意: 一共有 n n n Season TV,There are TV shows every season a i a_i ai 集,有一天, Polycarp Want to search for the first 7 7 7 季第 3 3 3 集时,Discovery can only search for the first 3 3 3 季第 7 7 7 集.It was later discovered upon interrogation,如果搜索 x x x 季 y y y 集,Once it has appeared before y y y 季 x x x set then x x x 季 y y y The set can never be searched,给出 n n n Season TV series and the number of episodes per season, Ask how many episodes exist but we couldn't search ?
思路: Because the number of episodes in each season will be less than the current one a i a_i ai quarterly contribution,例如 a 1 = 8 a_1=8 a1=8,那么如果 2 − 8 2-8 2−8 Season exists 1 1 1 Sets will not be searchable then 1 1 1 集.那么第 1 1 1 Ji's contribution to the answer is that 8 − 2 + 1 = 7 8-2+1=7 8−2+1=7 But if there are a few seasons without episodes 1 1 1 集,Then there will be no contribution,Then don't add it.So we can open a priority queue to store all numbers with the first key,The second key value is stored in the subscript.Once currently enumerated i i i greater than the value of the top element of the heap,Then put the second key of the top element of the heap in the tree array − 1 -1 −1 ,当用树状数组 a s k ask ask When the contribution of this element is naturally subtracted,直接开一个 b b b Sorted array is equivalent to priority queue.
代码:
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int>PII;
const int N = 2e5+10;
int a[N];
PII b[N];
int tr[N];
int n;
int lowbit(int x){
return x&-x;}
void add(int x,int v){
for(int i=x;i<=n;i+=lowbit(i))tr[i]+=v;
}
int ask(int x){
int ans=0;
for(int i=x;i;i-=lowbit(i))ans+=tr[i];
return ans;
}
signed main(){
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
cin>>n;
for(int i=1;i<=n;i++){
cin>>a[i];b[i]={
a[i],i};}
sort(b+1,b+1+n);
int cnt=1;
int ans=0;
for(int i=1;i<=n;i++){
while(cnt<=n&&b[cnt].first<i){
add(b[cnt].second,-1);
cnt++;
}
ans+=ask(min(i-1,a[i]));
add(i,1);
}
cout<<ans<<endl;
return 0;
}
边栏推荐
- 协程与任务
- Data Analysis of Time Series (5): Simple Prediction Method
- Dining (网络流)
- An enhanced dynamic packet buffer management. The core part of the paper
- Excel function formulas - HLOOKUP function
- 47Haproxy Cluster
- 面试美团被问到了Redis,搞懂这几个问题,让你轻松吊打面试官
- LeetCode 237. Delete a node in a linked list
- Chapter9 : De Novo Molecular Design with Chemical Language Models
- “68道 Redis+168道 MySQL”精品面试题(带解析)
猜你喜欢
You have a Doubaqiong thesaurus, please check it
iTextSharp操作PDF
「企业架构」应用架构概述
Chapter9 : De Novo Molecular Design with Chemical Language Models
Custom filters and interceptors implement ThreadLocal thread closure
How to cultivate the design thinking of ui designers?
金山云要飘到哪里?
自定义过滤器和拦截器实现ThreadLocal线程封闭
一文详解 implementation api embed
LeetCode中等题之搜索二维矩阵
随机推荐
【集合】HashSet和ArrayList的查找Contains()时间复杂度
娄底干细胞制备实验室建设须知要求
leetcode/两个链表的第一个重合节点
一文详解 implementation api embed
Crypto Gaming: The Future of Gaming
百度用户产品流批一体的实时数仓实践
郭晶晶家的象棋私教,好家伙是个机器人
Alibaba Cloud Jia Zhaohui: Cloud XR platform supports Bizhen Technology to present a virtual concert of national style sci-fi
10 款更先进的开源命令行工具
ASP.NET Core依赖注入系统学习教程:ServiceDescriptor(服务注册描述类型)
Mysql—— 内连接、左连接、右连接以及全连接查询
【iOS】面试整理
2022年8月中国数据库排行榜:openGauss重夺榜眼,PolarDB反超人大金仓
iTextSharp 使用详解
「网络架构」网络代理第一部分: 代理概述
Color map and depth map to point cloud
47Haproxy集群
爱可可AI前沿推介(8.10)
日记16
LeetCode简单题之合并相似的物品