跳过正文
  1. Posts/

nbut 1457 Sona

·2 分钟

https://ac.2333.moe/Problem/view.xhtml?id=1457 题意:求一段区间内数字个数的立方和。 思路:由于一共才1E5,而数字1E9,所以先离散化,再莫队,类似小z的袜子。 注意 :%lld会WA,要用%I64d

  1/* ***********************************************
  2Author :111qqz
  3Created Time :2016年02月17日 星期三 16时11分00秒
  4File Name :code/nbut/1457.cpp
  5************************************************ */
  6
  7#include <cstdio>
  8#include <cstring>
  9#include <iostream>
 10#include <algorithm>
 11#include <vector>
 12#include <queue>
 13#include <set>
 14#include <map>
 15#include <string>
 16#include <cmath>
 17#include <cstdlib>
 18#include <ctime>
 19#define fst first
 20#define sec second
 21#define lson l,m,rt<<1
 22#define rson m+1,r,rt<<1|1
 23#define ms(a,x) memset(a,x,sizeof(a))
 24typedef long long LL;
 25#define pi pair < int ,int >
 26#define MP make_pair
 27
 28using namespace std;
 29const double eps = 1E-8;
 30const int dx4[4]={1,0,0,-1};
 31const int dy4[4]={0,-1,1,0};
 32const int inf = 0x3f3f3f3f;
 33const int N=1E5+7;
 34int a[N],b[N];
 35LL  cnt[N];
 36int pos[N];
 37LL ans[N];
 38LL sum;
 39int n,m;
 40
 41struct node
 42{
 43    int l,r;
 44    int id;
 45
 46    bool operator < (node b)const
 47    {
 48	if (pos[l]==pos[b.l]) return r<b.r;
 49	return pos[l]<pos[b.l];
 50    }
 51}q[N];
 52
 53
 54
 55void update(int x,int d)
 56{
 57
 58	sum-=cnt[a[x]]*cnt[a[x]]*cnt[a[x]];
 59	cnt[a[x]]+=d;
 60	sum +=cnt[a[x]]*cnt[a[x]]*cnt[a[x]];
 61
 62}
 63int main()
 64{
 65	#ifndef  ONLINE_JUDGE
 66	freopen("code/in.txt","r",stdin);
 67  #endif
 68
 69	while (scanf("%d",&n)!=EOF)
 70	{
 71	    ms(cnt,0);
 72	    ms(ans,0);
 73	    sum = 0LL;
 74
 75	    int siz = 330;//sqrt(100000);
 76	    for ( int i = 1 ; i <= n ; i++)
 77	    {
 78		scanf("%d",&b[i]);
 79		pos[i] = (i-1)/siz;
 80		a[i] = b[i];
 81	    }
 82
 83	    sort(b+1,b+n+1);  //离散化
 84	    int t = unique(b+1,b+n+1)-b-1;
 85	    for ( int i = 1 ; i <= n ; i++) a[i]=lower_bound(b+1,b+t+1,a[i])-b;
 86
 87	    scanf("%d",&m);
 88	    for ( int i = 1 ; i <= m ; i++)
 89	    {
 90		scanf("%d %d",&q[i].l,&q[i].r);
 91		q[i].id = i ;
 92	    }
 93	    sort(q+1,q+m+1);
 94
 95	    int pl=1,pr=0;
 96	    int id,l,r;
 97	    for ( int i = 1 ; i <= m ; i++)
 98	    {
 99		id = q[i].id;
100		r = q[i].r;
101		l = q[i].l;
102
103		if (pr<r)
104		{
105		    for ( int j = pr +1 ; j <= r ; j++) update(j,1);
106		}
107		else
108		{
109		    for (int j = r+1 ; j <= pr ; j++) update(j,-1);
110		}
111		pr = r;
112
113		if (l<pl)
114		{
115		    for ( int j = l ; j <= pl-1 ; j++) update(j,1);
116		}
117		else
118		{
119		    for (int j = pl ; j <= l-1 ; j++) update(j,-1);
120		}
121		pl = l;
122
123		ans[id] = sum;
124	    }
125
126	    for ( int i = 1 ; i <= m ; i++) printf("%I64d\n",ans[i]); //用%lld会WA...也不给个警告
127	}
128
129  #ifndef ONLINE_JUDGE
130  fclose(stdin);
131  #endif
132    return 0;
133}

相关文章

hdu 5610 ||BC #69 div2 1001 Baby Ming and Weight lifting

·1 分钟
http://acm.hdu.edu.cn/showproblem.php?pid=5610 题意:有重量为a,b两种铁圈每种无限多个…能能否组成一个重量为c且平衡杠铃(中间的杆的重量忽略不计) a,b,c都是整数。 思路:平衡的话。。就是两边重量一样。。那么c为奇数的时候显然不行。 由于有多组答案的时候输出铁圈数之和小的。。。那么我们枚举的话。应该把里面那层枚举的变量放置成重量较大的。。。。

poj 1350 Cabric Number Problem

·1 分钟
http://poj.org/problem?id=1350 题意:6174问题。。。一个四位数。。四个数字重排。。。最大的减去最小的得到新的数字。最后一定能得到6174或者0.除非这个四位数的四个数字都一样。写出变化的过程。

codeforces 519 C. A and B and Team Training

·1 分钟
http://codeforces.com/problemset/problem/519/C 题意:两种组队方式,3人一组,1个大牛+2个蒟蒻或者1个蒟蒻+2个大牛。给定大牛和蒟蒻的个数。问最多能组多少队。 思路:线性规划。设两种队分别有x,y个即可。 突然发现这题以前做过。。。比当时的代码简单了一些。还不错。

有了这个列表,程序员不愁没练手的小项目了

·14 分钟
我经常看有人发帖问关于项目点子的事,也看到了很多回帖,我自己也回了一些常见的项目。不过我觉得只列出三两个是远远不够的,因此就收集并这个项目列表,大家要找简单的编程项目学习练手的话,可以收藏并扩散本文。这些项目并不是论文级别的,只是想抛砖引玉让大家能从中受些启发。