ural1090 In the Army Now
In the Army Now
Memory limit: 64 MB
Input
Output
Sample
input | output |
---|---|
3 3 |
3 |
分析:一行中前面数比后面数大的数的总个数,很明显的树状数组;
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
const int maxn=1e4+;
const int dis[][]={{,},{-,},{,-},{,}};
using namespace std;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p;p=p*p;q>>=;}return f;}
int n,m,k,t,a[maxn],ma,now,ans;
void add(int x,int y)
{
for(int i=x;i<=n;i+=(i&(-i)))
a[i]+=y;
}
int get(int x)
{
int res=;
for(int i=x;i;i-=(i&(-i)))
res+=a[i];
return res;
}
int main()
{
int i,j;
ans=;
scanf("%d%d",&n,&k);
rep(i,,k)
{
memset(a,,sizeof a);
now=;
rep(j,,n)
{
scanf("%d",&t);
add(t,);
now+=get(n)-get(t);
}
if(ma<now)ma=now,ans=i;
}
printf("%d\n",ans);
//system("Pause");
return ;
}
ural1090 In the Army Now的更多相关文章
- poj 3069 Saruman's Army
Saruman's Army Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8477 Accepted: 4317 De ...
- poj3069 Saruman's Army
http://poj.org/problem?id=3069 Saruman the White must lead his army along a straight path from Iseng ...
- R2D2 and Droid Army(多棵线段树)
R2D2 and Droid Army time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- POJ 3069 Saruman's Army(萨鲁曼军)
POJ 3069 Saruman's Army(萨鲁曼军) Time Limit: 1000MS Memory Limit: 65536K [Description] [题目描述] Saruman ...
- 【LCA】CodeForce #326 Div.2 E:Duff in the Army
C. Duff in the Army Recently Duff has been a soldier in the army. Malek is her commander. Their coun ...
- URAL 1774 A - Barber of the Army of Mages 最大流
A - Barber of the Army of MagesTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/v ...
- POJ 3069 Saruman's Army(贪心)
Saruman's Army Time Limit:1000MS Memory Limit:65536KB 64bit IO Format:%I64d & %I64u Sub ...
- 编程算法 - 萨鲁曼的军队(Saruman's Army) 代码(C)
萨鲁曼的军队(Saruman's Army) 代码(C) 本文地址: http://blog.csdn.net/caroline_wendy 题目: 直线上有N个点, 每个点, 其距离为R以内的区域里 ...
- Codeforces 514 D R2D2 and Droid Army(RMQ+二分法)
An army of n droids is lined up in one row. Each droid is described by m integers a1, a2, ..., am, w ...
随机推荐
- 发现在看完objc基本语法之后,还是看Apple文档比较有用。
现在已经停止找中文资料了,因为很多例子已经过时,运行不出来. 看完objc基本语法以后,Apple的资料也看得懂了. 还是应该跟着Apple的入门指南开始学,今后也应该以Apple的文档为主.
- CentOS7 PostgreSQL 主从配置( 一)
主库配置 pg_hba.conf host replication all 10.2.0.0/0 trust postgresql.conf listen_addresses = '*' max_wa ...
- php过滤提交数据 防止sql注入攻击
规则 1:绝不要信任外部数据或输入 关于 Web 应用程序安全性,必须认识到的第一件事是不应该信任外部数据.外部数据(outside data) 包括不是由程序员在 PHP 代码中直接输入的任何数据. ...
- 哈佛大学构建动态网站--第七讲ajax
Ajax ajax举例: DOM的结构 通过js来修改html页面. Ajax的含义: return false的用途 跨浏览器的ajax 为什么不直接从yahoo获得数据呢? XMLHttpRequ ...
- 后台处理excel下载输出流
前台 <ul class="navtop-right"> <li > <a href="/portal/trip/importExec&qu ...
- QQ登录界面
@property (nonatomic,assign) IBOutlet UITextField *qq; @property (nonatomic,assign) IBOutlet UITextF ...
- think in uml 2.1
业务建模
- libevent在windows下使用步骤详解
一 环境 官方下载地址:http://libevent.org/版本:libevent-2.0.22-stable 二 编译静态库 1 解压把上面下载到libevent-2.0.22-stable.t ...
- windows ORA-12560: TNS: 协议适配器错误
1.first it report ORA-12560: TNS: 协议适配器错误 手工设定环境变量如下: set ORACLE_HOME=d:\app\OAadmin\product\11.2.0\ ...
- php多进程实现
php多进程实现 PHP有一组进程控制函数(编译时需要–enable-pcntl与posix扩展),使得php能在nginx系统中实现跟c一样的创建子进程.使用exec函数执行程序.处理信号等功能. ...