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

當前位置: 首頁IT技術 → HDU 4031 樹狀數組 區間更新及點詢問

HDU 4031 樹狀數組 區間更新及點詢問

更多

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

去年成都賽區網絡賽一道題,樹狀數組在區間更新中的應用。樹狀數組一般支持的是改點,查區間,但

是這道題要求的是改區間,查點,這就要變通一下,具體可以看代碼,另外要考慮的一個問題是,如何統計?

這里的處理方法就是把總共的攻擊次數-防御的次數,因為對單個點的詢問可能有多次,所以為每個點都設

定一個游標來優化時間~

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

#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

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

熱門評論
最新評論
昵稱:
表情: 高興 可 汗 我不要 害羞 好 下下下 送花 屎 親親
字數: 0/500 (您的評論需要經過審核才能顯示)
主站蜘蛛池模板: 欧美超高清在线观看 | 成人免费福利视频 | 日韩a毛片免费全部播放完整 | 天天综合网天天综合色不卡 | 乡村乱肉情欲小说 | 毛片一级在线观看 | 在线www 天堂网在线 | 国产成人免费视频 | 网站免费满18成年在线观看 | 国产亚洲一区二区麻豆 | 国产福利影院 | 欧美18—19sex性护士 | 美日韩精品 | 亚洲精品动漫在线观看 | 欧美一级xxxx俄罗斯一级 | 色无五月 | 国产福利午夜 | 久久精品伊人波多野结 | 国产日产欧产精品精品推荐在线 | 国美女福利视频午夜精品 | 欧美性xxxx极品高清3d | 美女图片在线视频精品播放 | 亚洲经典三级 | 91成人免费在线视频 | 免费一级毛片能看的 | 午夜免费| 九九视频在线看精品 | 久久国产一区二区 | 欧美xxxx性猛交bbbb | 成年人网站在线免费观看 | 国产免费拔擦拔擦8x | 精品国产一区二区三区不卡 | 久久综合综合久久狠狠狠97色 | 亚洲午夜成激人情在线影院 | 麻豆久久精品免费看国产 | 亚洲国产精品久久久久久网站 | 欧美日韩影院 | 美女黄网站在线观看 | 深夜福利网站 | 免费人成网址在线观看国内 | 一本三道a无线码一区v |