当前位置:网站首页>教育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;
}
边栏推荐
猜你喜欢
ArcMAP出现-15的问题无法访问[Provide your license server administrator with the following information:Err-15]
22年BATJ大厂必问面试题(复盘):JVM+微服务+多线程+锁+高并发
多线程下自旋锁设计基本思想
阿里云贾朝辉:云XR平台支持彼真科技呈现国风科幻虚拟演唱会
神经网络学习-正则化
基于PLECS的离网(孤岛)并联逆变器的Droop Control下垂控制仿真
吃透Chisel语言.36.Chisel实战之以FIFO为例(一)——FIFO Buffer和Bubble FIFO的Chisel实现
LT8911EXB MIPI CSI/DSI转EDP信号转换
燃炸!字节跳动成功上岸,只因刷爆LeetCode算法面试题
iTextSharp操作PDF
随机推荐
Golang分布式应用之etcd
Highways「建议收藏」
10 款更先进的开源命令行工具
部署项目半途而废后续
线代 | 秒杀方法与技巧
LeetCode 146. LRU Cache
IM即时通讯开发WebSocket从入门到精通
九宫格抽奖动效
吃透Chisel语言.36.Chisel实战之以FIFO为例(一)——FIFO Buffer和Bubble FIFO的Chisel实现
Dining (网络流)
Mysql—— 内连接、左连接、右连接以及全连接查询
中科院深圳先进技术院合成所赵国屏院士组2022年招聘启事
An enhanced dynamic packet buffer management. The core part of the paper
ASP.NET Core依赖注入系统学习教程:ServiceDescriptor(服务注册描述类型)
Codeforces Round #276 (Div. 1) D. Kindergarten
第5章 虚拟存储器
“68道 Redis+168道 MySQL”精品面试题(带解析)
Digicert EV证书签名后出现“证书对于请求用法无效”的解决方案
Is there a problem with the CURRENT_TIMESTAMP(6) function?
48 the mysql database