当前位置:网站首页>Educational Codeforces Round 41 (Rated for Div. 2) E. Tufurama
Educational Codeforces Round 41 (Rated for Div. 2) E. Tufurama
2022-08-10 12:05:00 【Snow_raw】
Educational Codeforces Round 41 (Rated for Div. 2) E. Tufurama
题意: 一共有 n n n 季电视剧,每季电视剧有 a i a_i ai 集,有一天, Polycarp 想要搜索第 7 7 7 季第 3 3 3 集时,发现只能搜索到第 3 3 3 季第 7 7 7 集。后来经讯问发现,如果搜索 x x x 季 y y y 集,一旦前面出现过 y y y 季 x x x 集那么 x x x 季 y y y 集永远无法搜索到,给出 n n n 季电视剧以及每季的集数, 问有多少集是存在但我们搜索不到的 ?
思路: 因为每一季的集数都会对小于当前 a i a_i ai 的季产生贡献,例如 a 1 = 8 a_1=8 a1=8,那么如果 2 − 8 2-8 2−8 季存在 1 1 1 集那么都会搜索不到第 1 1 1 集。那么第 1 1 1 季对答案带来的贡献就是 8 − 2 + 1 = 7 8-2+1=7 8−2+1=7 但是如果其中有几季没有第 1 1 1 集,那么就无法产生贡献,那么就不用加上。因此我们可以开一个优先队列将所有数以第一关键字存值,第二关键值存下标存入。一旦当前枚举的 i i i 大于堆顶元素的值,那么就将树状数组中堆顶元素的第二关键字 − 1 -1 −1 ,当用树状数组 a s k ask ask 时也就自然减去了该元素带来的贡献,直接开一个 b b b 数组排序后和优先队列等效。
代码:
#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;
}
边栏推荐
- You have a Doubaqiong thesaurus, please check it
- 【论文+代码】PEBAL/Pixel-wise Energy-biased Abstention Learning for Anomaly Segmentation on Complex Urban Driving Scenes(复杂城市驾驶场景异常分割的像素级能量偏置弃权学习)
- So delicious!Since using this interface artifact, my team efficiency has increased by 60%!
- 协程与任务
- Behind IDC's No. 1 position, what kind of "video cloud" is Alibaba Cloud building?
- LT8911EXB MIPI CSI/DSI转EDP信号转换
- Chapter9 : De Novo Molecular Design with Chemical Language Models
- 基于PLECS的离网(孤岛)并联逆变器的Droop Control下垂控制仿真
- IDC第一的背后,阿里云在打造怎样的一朵“视频云”?
- Database management tool: dynamic read-write separation
猜你喜欢

LT8911EXB MIPI CSI/DSI to EDP signal conversion
MySQL索引的B+树到底有多高?

基于PLECS的离网(孤岛)并联逆变器的Droop Control下垂控制仿真

「网络架构」网络代理第一部分: 代理概述

wirshark 常用操作及 tcp 三次握手过程实例分析

IDC第一的背后,阿里云在打造怎样的一朵“视频云”?

Behind IDC's No. 1 position, what kind of "video cloud" is Alibaba Cloud building?

dedecms supports one-click import of Word content

“68道 Redis+168道 MySQL”精品面试题(带解析)

16、Pytorch Lightning入门
随机推荐
What are the five common data types of Redis?What is the corresponding data storage space?Take you to learn from scratch
LeetCode 237. Delete a node in a linked list
MySQL相关问题整理
讯飞创意组别 全国选拔赛成绩公布说明
IM即时通讯开发WebSocket从入门到精通
How to do foreign media publicity to grasp the key points
16、Pytorch Lightning入门
Threshold-based filtering buffer management scheme in a shared buffer packet switch论文核心部分
Polygon zkEVM工具——PIL和CIRCOM
Custom filters and interceptors implement ThreadLocal thread closure
自定义过滤器和拦截器实现ThreadLocal线程封闭
22年BATJ大厂必问面试题(复盘):JVM+微服务+多线程+锁+高并发
虚拟机桥接模式不能上网
iTextSharp 使用详解
CLIP还能做分割任务?哥廷根大学提出一个使用文本和图像prompt,能同时作三个分割任务的模型CLIPSeg,榨干CLIP能力...
Accumulated and thin hair!Safety Dog has once again obtained the certification of scientific and technological achievements transformation!
一文详解 implementation api embed
CV复习:空洞卷积
LeetCode 362. Design Hit Counter
Guo Jingjing's personal chess teaching, the good guy is a robot