首页 技术 正文
技术 2022年11月19日
0 收藏 716 点赞 3,302 浏览 1853 个字

http://acm.hdu.edu.cn/showproblem.php?pid=1541

题意:给你一堆点,每个点右一个level,为其右下方所有点的数量之和,求各个level包含的点数。

题解:由于输入是有序的,每读进一对x,y 只需要考虑之前读入的数据就行了(之后的必定在其右上方)。如何计算他的level?只需从其X坐标开始往右所有的X坐标上的点数求和即可。然后再让自己的X坐标点数++。这是单点更新,求前缀和的操作,可以用树状数组。

坑:题目条件有误。

  add函数里x<=maxn而不是n,具体原理应该是会处理到n外面吧

#define _CRT_SECURE_NO_WARNINGS
#include<cstring>
#include<cctype>
#include<cstdlib>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<string>
#include<climits>
#include<stack>
#include<ctime>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<vector>
#include<sstream>
#include<fstream>
#include<iostream>
#include<functional>
#include<algorithm>
#include<memory.h>
//#define INF LONG_MAX
#define eps 1e-6
#define pi acos(-1.0)
#define e exp(1.0)
#define rep(i,t,n) for(int i =(t);i<=(n);++i)
#define per(i,n,t) for(int i =(n);i>=(t);--i)
#define mp make_pair
#define pb push_back
#define mmm(a,b) memset(a,b,sizeof(a))
//std::ios::sync_with_stdio(false);
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
void smain();
#define ONLINE_JUDGE
int main() {
//ios::sync_with_stdio(false);
#ifndef ONLINE_JUDGE
freopen("C:\\Users\\SuuTT\\Desktop\\test\\in.txt", "r", stdin);
freopen("C:\\Users\\SuuTT\\Desktop\\test\\out.txt", "w", stdout);
//ifstream in;
//string filename;
//getline(cin, filename,'\n');
//in.open(filename); long _begin_time = clock();
#endif
smain();
#ifndef ONLINE_JUDGE
long _end_time = clock();
printf("time = %ld ms.", _end_time - _begin_time);
#endif
return ;
}
int dir[][] = { ,,,,-,,,- };
const int maxn = 4e5 + ;
int n, m;
ll a[maxn];
int d[maxn];
int level[maxn];
int lowbit(int x) { return x & (-x); }
void add(int x, int v) {//a[x]+=v;
while (x <= maxn) {
d[x] += v;
x += lowbit(x);
}}
int query(int x) {
int res = ;
while (x) {
res += d[x];
x -= lowbit(x);
}
return res;
}
struct node { int x, y;
node(int x = , int y = ) :x(x), y(y) {}};void Run() {}void smain() {
while (cin >> n)
{
mmm(d, ); mmm(level, ); rep(i, , n) {
int x, y;
cin >> x >> y;
x++;
level[query(x)]++;
//cout << query(x) << endl;
add(x, ); }
rep(i, , n - )cout << level[i] << endl;
}
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,918
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,444
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,255
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,069
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,701
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,741