变态重口极致另类在线-波多久久夜色精品国产-波多野结衣在线观看一区-波多野结衣在线观看一区二区-污污的网站免费阅读-污污视频网址

當(dāng)前位置:首頁文章首頁 IT學(xué)院 IT技術(shù)

HDU 4031 樹狀數(shù)組 區(qū)間更新及點(diǎn)詢問

作者:  來源:  發(fā)布時(shí)間:2012-1-19 18:08:44  點(diǎn)擊:

/*******************************************************************************

去年成都賽區(qū)網(wǎng)絡(luò)賽一道題,樹狀數(shù)組在區(qū)間更新中的應(yīng)用。樹狀數(shù)組一般支持的是改點(diǎn),查區(qū)間,但

是這道題要求的是改區(qū)間,查點(diǎn),這就要變通一下,具體可以看代碼,另外要考慮的一個(gè)問題是,如何統(tǒng)計(jì)?

這里的處理方法就是把總共的攻擊次數(shù)-防御的次數(shù),因?yàn)閷?duì)單個(gè)點(diǎn)的詢問可能有多次,所以為每個(gè)點(diǎn)都設(shè)

定一個(gè)游標(biāo)來優(yōu)化時(shí)間~

*******************************************************************************/

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

#include

using namespace std;

 

#define LOWBIT(x) ( (x) & ( (x) ^ ( (x) - 1 ) ) )

#define CLR(x, k) memset((x), (k), sizeof(x))

#define CPY(t, s) memcpy((t), (s), sizeof(s))

#define SC(t, s) static_cast(s)

#define LEN(s) static_cast( strlen((s)) )

#define SZ(s) static_cast( (s).size() )

 

typedef double LF;

typedef __int64 LL; //VC

typedef unsigned __int64 ULL;

 

typedef pair PII;

typedef pair PLL;

typedef pair PDD;

 

typedef vector VI;

typedef vector VC;

typedef vector VF;

typedef vector VS;

 

template

T sqa(const T & x) {return x * x;}

template

T ll(const T & x) {return x << 1;}

template

T rr(const T & x) {return x << 1 | 1;}

template

T gcd(T a, T b)

{

if (!a || !b)

{

return max(a, b);

}

T t;

while (t = a % b)

{

a = b;

b = t;

}

return b;

};

 

const int INF_INT = 0x3f3f3f3f;

const LL INF_LL = 0x7fffffffffffffffLL; //15f

const double oo = 10e9;

const double eps = 10e-7;

const double PI = acos(-1.0);

 

#define ONLINE_JUDGE

 

const int MAXN = 20004;

 

int test, n, q, t;

int tree[MAXN];

int crs[MAXN], def[MAXN];

vector vp;

 

void updateBIT(int x, int inc)

{

for (int i = x; i > 0; i -= LOWBIT(i))

{

tree[i] += inc;

}

return ;

}

void updateSeg(int l, int r, int inc)

{

updateBIT(l - 1, -inc);

updateBIT(r, inc);

return ;

}

int queryBIT(int x)

{

int sum = 0;

for (int i = x; i <= n; i += LOWBIT(i))

{

sum += tree[i];

}

return sum;

}

void ace()

{

int cas = 1;

char op[10];

int l, r, p;

for (scanf("%d", &test); test--; ++cas)

{

scanf("%d %d %d", &n, &q, &t);

CLR(tree, 0);

CLR(crs, 0);

CLR(def, 0);

vp.clear();

int ind = 0;

printf("Case %d:\n", cas);

while (q--)

{

scanf("%s", op);

if ('A' == op[0])

{

scanf("%d %d", &l, &r);

if (l > r)

{

swap(l, r);

}

//l = max(l, 1);

//r = min(r, n);

updateSeg(l, r, 1);

vp.push_back(PII(l, r));

++ind;

}

else

{

scanf("%d", &p);

if (1 == t)

{

puts("0");

continue ;

}

int token = 0;

while (crs[p] < ind)

{

if (vp[ crs[p] ].first <= p && p <= vp[ crs[p] ].second)

{

if (0 == token % t)

{

crs[p] += t - 1;

++def[p];

token = t - 1;

}

++token;

}

++crs[p];

}

printf("%d\n", queryBIT(p) - def[p]);

}

}

}

return ;

}

int main()

{

#ifndef ONLINE_JUDGE

freopen("in.txt", "r", stdin);

freopen("out.txt", "w", stdout);

#endif

ace();

return 0;

}

/*******************************************************************************

Test Data...

2

3 7 2

Attack 1 2

Query 2

Attack 2 3

Query 2

Attack 1 3

Query 1

Query 3

9 7 3

Attack 5 5

Attack 4 6

Attack 3 7

Attack 2 8

Attack 1 9

Query 5

Query 3

*******************************************************************************/

相關(guān)軟件

文章評(píng)論

軟件按字母排列: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
主站蜘蛛池模板: 日韩一区二区三区视频在线观看 | 日本高清网站 | 五月香福利 | 久久综合免费视频 | 亚洲国产一区在线观看 | 一97日本道伊人久久综合影院 | 国产精视频| 韩国精品一区 | 一个人的免费影院 | 好吊色综合网天天高清 | 在线不卡一区二区三区日韩 | jizjizjiz亚洲大全 | 最近的中文字幕大全免费版 | 最近中文字幕mv免费视频 | 菊花综合网 | 欧美国产成人精品一区二区三区 | a级毛片无码免费真人 | 久久99综合国产精品亚洲首页 | 欧美日韩一卡二卡 | 日韩欧美在线第一页 | 东京加勒比中文字幕波多野结衣 | 性xxx69xxx视频在线观看 | 欧美亚洲福利 | 窝窝人体色 | 中文字幕久久亚洲一区 | 一级做a爱片久久蜜桃 | 多人乱p欧美4p | 国产亚洲精品仙踪林在线播放 | 一本一道dvd在线观看免费视频 | 手机看一级片 | 男女午夜爽爽大片免费 | 欧美日韩亚洲视频 | 中文一级黄色片 | 亚州黄色网址 | 麻豆一区二区三区在线观看 | 欧美一区二区三区精品影视 | 午夜私人影院 | 亚洲综合影视 | 麻豆va在线精品免费播放 | 最近最新免费中文字幕高清 | 黄色网址在线播放 |