首页 > 其他分享 >nowcoder contest/911/F

nowcoder contest/911/F

时间:2023-03-28 21:38:04浏览次数:44  
标签:contest int res nowcoder include 911

https://ac.nowcoder.com/acm/contest/911/F

 

 值域上维护右括号的个数,遇到左括号就查询前面有几个右括号

#include <iostream>
#include <algorithm>
#include <queue>
using namespace std ;
 const int N =1e5+10;
 int n,c[N];
 int L[N],R[N] ;
 int lowbit(int x){
 	return x&-x;
 }
 int qry(int x){
 	int res=0;
 	for(;x;x-=lowbit(x)) res+=c[x];
 	return res;
 }
 void add(int x){
 	for(;x<=1e5;x+=lowbit(x)) c[x]++;
 }
 
 signed main(){
 	cin>>n;
 	for(int i=1;i<=n;i++){
 		double x,r; cin>>x>>r;
 		L[i] =x-r; R[i]=x+r;
 	}
 	sort(L+1,L+1+n);sort(R+1,R+1+n) ;
 	
 	int ans=0;
 	for(int i=1;i<=n;i++){
 		int l=L[i],r=R[i];
 		ans+= qry(L[i]-1);
 		add(R[i]);
 	}
 	cout<<ans;
 }
 
 

 

标签:contest,int,res,nowcoder,include,911
From: https://www.cnblogs.com/towboa/p/17266761.html

相关文章

  • AtCoder Beginner Contest 295
    A-ProbablyEnglish#include<bits/stdc++.h>usingnamespacestd;intread(){intx=0,f=1,ch=getchar();while((ch<'0'||ch>'9')&&ch......
  • AtCoder Beginner Contest 145
    AtCoderBeginnerContest145https://atcoder.jp/contests/abc145D-Knight乍一看以为是dp,但是数据范围不允许。仔细一看发现,两种操作的次数是固定的,可以枚举出来每......
  • AtCoder Beginner Contest 148
    AtCoderBeginnerContest148https://atcoder.jp/contests/abc148这场比较简单D-BrickBreak二分orLIS#include<bits/stdc++.h>#definelllonglongusingn......
  • AtCoder Beginner Contest 248 F(连通性状压dp)
    F连通性状压dp思路看了dls的讲解后才明白一点点。状态\(dp[i][j][k]\)表示到表示到i列,删除了j条边,点i和n-1+i是否联通,对于下一列点,若当前i和n-1+i连通,则多出来的三条......
  • AtCoder Educational DP Contest
    1.A没什么难度,直接算就可以了。点击查看代码#include<bits/stdc++.h>#defineintlonglong#defineYesprintf("Yes\n")#defineNoprintf("No\n")#defineYESpr......
  • AtCoder Grand Contest 019 F Yes or No
    洛谷传送门AtCoder传送门首先容易发现最优策略是回答剩余多的选项。设\(n\)为剩余Yes的数量,\(m\)为剩余No的数量,考虑将\((n,m)\)放到平面上,若\(n>m\)则回......
  • AtCoder Grand Contest 008 F Black Radius
    洛谷传送门AtCoder传送门神题!!!!111考虑如何不重不漏地计数。先考虑全为1的情况,令\(f(u,d)\)为与\(u\)的距离\(\led\)的点集。首先单独算全集,那么对于不是全集......
  • AtCoder Beginner Contest 246
    AtCoderBeginnerContest246D题意求一个\(x\geqn\)使得\(x=a^3+a^2b+ab^2+b^3\)且\(n\leq10^{18}\)思路变形\(x=(a+b)(a^2+b^2)\),那么a、b的范围在1e6从大到小......
  • SMU Spring 2023 Trial Contest Round 1(6/8)
    SMUSpring2023TrialContestRound1(6/8)A.PrependandAppendPrependandAppend只需考虑给定字符串两端是否符合10或01即可,双指针从两端模拟即可。#include<iost......
  • AtCoder Beginner Contest 141
    AtCoderBeginnerContest141D-PowerfulDiscountTickets贪心+堆#include<bits/stdc++.h>#definelllonglongusingnamespacestd;constintN=1e5+5;......